coreTest.php

  1. 8.0.x tests/coreTest.php
  2. 6.x tests/coreTest.php
  3. 7.x tests/coreTest.php
  4. 4.x tests/coreTest.php
  5. 5.x tests/coreTest.php
  6. master tests/coreTest.php

Tests for core commands.

@group commands

Classes

Namesort descending Description
coreCase @file Tests for core commands.

File

tests/coreTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for core commands.
  5. *
  6. * @group commands
  7. */
  8. class coreCase extends Drush_CommandTestCase {
  9. /**
  10. * Test to see if rsync @site:%files calculates the %files path correctly.
  11. * This tests the non-optimized code path in drush_sitealias_resolve_path_references.
  12. */
  13. function testRsyncPercentFiles() {
  14. $this->setUpDrupal(1, TRUE);
  15. $root = $this->webroot();
  16. $site = key($this->sites);
  17. $options = array(
  18. 'root' => $root,
  19. 'uri' => key($this->sites),
  20. 'simulate' => NULL,
  21. 'include-conf' => NULL,
  22. 'include-vcs' => NULL,
  23. 'yes' => NULL,
  24. );
  25. $this->drush('core-rsync', array("@$site:%files", "/tmp"), $options, NULL, NULL, self::EXIT_SUCCESS, '2>&1;');
  26. $output = $this->getOutput();
  27. $level = $this->log_level();
  28. $pattern = in_array($level, array('verbose', 'debug')) ? "Calling system(rsync -e 'ssh ' -akzv --stats --progress --yes %s /tmp);" : "Calling system(rsync -e 'ssh ' -akz --yes %s /tmp);";
  29. $expected = sprintf($pattern, UNISH_SANDBOX . "/web/sites/$site/files");
  30. $this->assertEquals($expected, $output);
  31. }
  32. /**
  33. * Test to see if the optimized code path in drush_sitealias_resolve_path_references
  34. * that avoids a call to backend invoke when evaluating %files works.
  35. */
  36. function testPercentFilesOptimization() {
  37. $this->setUpDrupal(1, TRUE);
  38. $root = $this->webroot();
  39. $site = key($this->sites);
  40. $options = array(
  41. 'root' => $root,
  42. 'uri' => key($this->sites),
  43. 'simulate' => NULL,
  44. 'include-conf' => NULL,
  45. 'include-vcs' => NULL,
  46. 'yes' => NULL,
  47. 'strict' => 0, // invoke from script: do not verify options
  48. );
  49. $php = '$a=drush_sitealias_get_record("@' . $site . '"); drush_sitealias_resolve_path_references($a, "%files"); print_r($a["path-aliases"]["%files"]);';
  50. $this->drush('ev', array($php), $options);
  51. $output = $this->getOutput();
  52. $expected = "sites/dev/files";
  53. $this->assertEquals($expected, $output);
  54. }
  55. /**
  56. * Test standalone php-script scripts. Assure that script args and options work.
  57. */
  58. public function testStandaloneScript() {
  59. if ($this->is_windows()) {
  60. $this->markTestSkipped('Standalone scripts not currently available on Windows.');
  61. }
  62. $this->drush('version', array('drush_version'), array('pipe' => NULL));
  63. $standard = $this->getOutput();
  64. // Write out a hellounish.script into the sandbox. The correct /path/to/drush
  65. // is in the shebang line.
  66. $filename = 'hellounish.script';
  67. $data = '#!/usr/bin/env [PATH-TO-DRUSH]
  68. $arg = drush_shift();
  69. drush_invoke("version", $arg);
  70. ';
  71. $data = str_replace('[PATH-TO-DRUSH]', UNISH_DRUSH, $data);
  72. $script = UNISH_SANDBOX . '/' . $filename;
  73. file_put_contents($script, $data);
  74. chmod($script, 0755);
  75. $this->execute("$script drush_version --pipe");
  76. $standalone = $this->getOutput();
  77. $this->assertEquals($standard, $standalone);
  78. }
  79. function testDrupalDirectory() {
  80. $this->setUpDrupal(1, TRUE);
  81. $root = $this->webroot();
  82. $sitewide = $this->drupalSitewideDirectory();
  83. $options = array(
  84. 'root' => $root,
  85. 'uri' => key($this->sites),
  86. 'yes' => NULL,
  87. 'skip' => NULL,
  88. 'cache' => NULL,
  89. 'strict' => 0, // invoke from script: do not verify options
  90. );
  91. $this->drush('pm-download', array('devel'), $options);
  92. $this->drush('pm-enable', array('devel', 'menu'), $options);
  93. $this->drush('pm-download', array('zen'), $options);
  94. $this->drush('drupal-directory', array('devel'), $options);
  95. $output = $this->getOutput();
  96. $this->assertEquals($root . '/' . $sitewide . '/modules/devel', $output);
  97. $this->drush('drupal-directory', array('zen'), $options);
  98. $output = $this->getOutput();
  99. $this->assertEquals($root . '/' . $sitewide . '/themes/zen', $output);
  100. $this->drush('drupal-directory', array('%files'), $options);
  101. $output = $this->getOutput();
  102. $this->assertEquals($root . '/sites/dev/files', $output);
  103. $this->drush('drupal-directory', array('%modules'), $options);
  104. $output = $this->getOutput();
  105. $this->assertEquals($root . '/' . $sitewide . '/modules', $output);
  106. }
  107. function testCoreRequirements() {
  108. $this->setUpDrupal(1, TRUE);
  109. $root = $this->webroot();
  110. $options = array(
  111. 'root' => $root,
  112. 'uri' => key($this->sites),
  113. 'pipe' => NULL,
  114. 'ignore' => 'cron,http requests,update_core', // no network access when running in tests, so ignore these
  115. 'strict' => 0, // invoke from script: do not verify options
  116. );
  117. // Verify that there are no severity 2 items in the status report
  118. $this->drush('core-requirements', array(), $options + array('severity' => '2'));
  119. $output = $this->getOutput();
  120. $this->assertEquals('', $output);
  121. $this->drush('core-requirements', array(), $options);
  122. $loaded = $this->getOutputFromJSON();
  123. // Pick a subset that are valid for D6/D7/D8.
  124. $expected = array(
  125. // 'install_profile' => -1,
  126. // 'node_access' => -1,
  127. 'php' => -1,
  128. // 'php_extensions' => -1,
  129. 'php_memory_limit' => -1,
  130. 'php_register_globals' => -1,
  131. 'settings.php' => -1,
  132. );
  133. foreach ($expected as $key => $value) {
  134. $this->assertEquals($value, $loaded->$key->sid);
  135. }
  136. }
  137. }