commandUnitTest.php

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

Namespace

Unish

Classes

Namesort descending Description
commandUnitCase

File

tests/commandUnitTest.php
View source
  1. <?php
  2. namespace Unish;
  3. class commandUnitCase extends UnitUnishTestCase {
  4. /**
  5. * Assure that matching version-specific command files are loaded and others are ignored.
  6. */
  7. function testCommandVersionSpecific() {
  8. $path = UNISH_SANDBOX . '/commandUnitCase';
  9. $major = $this->drush_major_version();
  10. $major_plus1 = $major + 1;
  11. // Write matched and unmatched files to the system search path.
  12. $files = array(
  13. $path . "/$major.drush$major.inc",
  14. $path . "/drush$major/drush$major.drush.inc",
  15. $path . "/$major_plus1.drush$major_plus1.inc",
  16. $path . "/drush$major_plus1/drush$major_plus1.drush.inc",
  17. );
  18. mkdir($path);
  19. mkdir($path . '/drush' . $major);
  20. mkdir($path . '/drush' . $major_plus1);
  21. foreach ($files as $file) {
  22. $contents = <<<EOD
  23. <?php
  24. // Written by Unish. This file is safe to delete.
  25. \$GLOBALS['unish_foo'][] = '$file';
  26. EOD;
  27. $return = file_put_contents($file, $contents);
  28. }
  29. drush_set_context('DRUSH_INCLUDE', array($path));
  30. drush_preflight();
  31. $loaded = drush_commandfile_list();
  32. $this->assertTrue(in_array(realpath($files[0]), $loaded), 'Loaded a version-specific command file.');
  33. $this->assertTrue(in_array(realpath($files[1]), $loaded), 'Loaded a version-specific command directory.');
  34. $this->assertFalse(in_array(realpath($files[2]), $loaded), 'Did not load a mismatched version-specific command file.');
  35. $this->assertFalse(in_array(realpath($files[3]), $loaded), 'Did not load a a mismatched version-specific command directory.');
  36. }
  37. /**
  38. * Assert that $command has interesting properties. Reference command by
  39. * it's alias (dl) to assure that those aliases are built as expected.
  40. */
  41. public function testGetCommands() {
  42. drush_preflight();
  43. $commands = drush_get_commands();
  44. $command = $commands['dl'];
  45. $this->assertEquals('dl', current($command['aliases']));
  46. $this->assertArrayHasKey('version_control', $command['engines']);
  47. $this->assertArrayHasKey('package_handler', $command['engines']);
  48. $this->assertArrayHasKey('release_info', $command['engines']);
  49. $this->assertEquals('pm-download', $command['command']);
  50. $this->assertEquals('pm', $command['commandfile']);
  51. $this->assertEquals('drush_command', $command['callback']);
  52. $this->assertArrayHasKey('examples', $command['sections']);
  53. $this->assertTrue($command['is_alias']);
  54. $command = $commands['pm-download'];
  55. $this->assertArrayNotHasKey('is_alias', $command);
  56. }
  57. }