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

Namespace

Unish

Classes

Namesort descending Description
coreCase Tests for core commands.

File

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