annotatedCommandTest.php

Namespace

Unish

Classes

Namesort descending Description
annotatedCommandCase @group base

File

tests/annotatedCommandTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * @group base
  5. */
  6. class annotatedCommandCase extends CommandUnishTestCase {
  7. public function testExecute() {
  8. $sites = $this->setUpDrupal(1, TRUE);
  9. $uri = key($sites);
  10. $root = $this->webroot();
  11. $options = array(
  12. 'root' => $root,
  13. 'uri' => $uri,
  14. 'yes' => NULL,
  15. );
  16. // Copy the 'woot' module over to the Drupal site we just set up.
  17. $this->setupModulesForTests($root);
  18. // These are not good asserts, but for the purposes of isolation....
  19. $targetDir = $root . DIRECTORY_SEPARATOR . $this->drupalSitewideDirectory() . '/modules/woot';
  20. if (UNISH_DRUPAL_MAJOR_VERSION == 8) {
  21. $commandFile = $targetDir . "/src/Command/WootCommands.php";
  22. } else {
  23. $commandFile = $targetDir . "/Command/WootCommands.php";
  24. }
  25. $this->assertFileExists(dirname(dirname(dirname($commandFile))));
  26. $this->assertFileExists(dirname(dirname($commandFile)));
  27. $this->assertFileExists(dirname($commandFile));
  28. $this->assertFileExists($commandFile);
  29. // Enable out module. This will also clear the commandfile cache.
  30. $this->drush('pm-enable', array('woot'), $options);
  31. // In theory this is not necessary, but this test keeps failing.
  32. $this->drush('cc', array('drush'), $options);
  33. // drush woot --help
  34. $this->drush('woot', array(), $options + ['help' => NULL]);
  35. $output = $this->getOutput();
  36. $this->assertContains('Woot mightily.', $output);
  37. $this->assertContains('Aliases: wt', $output);
  38. // drush help woot
  39. $this->drush('help', array('woot'), $options);
  40. $output = $this->getOutput();
  41. $this->assertContains('Woot mightily.', $output);
  42. // drush woot
  43. $this->drush('woot', array(), $options);
  44. $output = $this->getOutput();
  45. $this->assertEquals('Woot!', $output);
  46. // drush my-cat --help
  47. $this->drush('my-cat', array(), $options + ['help' => NULL]);
  48. $output = $this->getOutput();
  49. $this->assertContains('This is the my-cat command', $output);
  50. $this->assertContains('bet alpha --flip', $output);
  51. $this->assertContains('The first parameter', $output);
  52. $this->assertContains('The other parameter', $output);
  53. $this->assertContains('Whether or not the second parameter', $output);
  54. $this->assertContains('Aliases: c', $output);
  55. // drush help my-cat
  56. $this->drush('help', array('my-cat'), $options);
  57. $output = $this->getOutput();
  58. $this->assertContains('This is the my-cat command', $output);
  59. // drush my-cat bet alpha --flip
  60. $this->drush('my-cat', array('bet', 'alpha'), $options + ['flip' => NULL]);
  61. $output = $this->getOutput();
  62. $this->assertEquals('alphabet', $output);
  63. // drush woot --help with the 'woot' module ignored
  64. $this->drush('woot', array(), $options + ['help' => NULL, 'ignored-modules' => 'woot'], NULL, NULL, self::EXIT_ERROR);
  65. // drush my-cat bet alpha --flip
  66. $this->drush('my-cat', array('bet', 'alpha'), $options + ['flip' => NULL, 'ignored-modules' => 'woot'], NULL, NULL, self::EXIT_ERROR);
  67. $this->drush('try-formatters', array(), $options);
  68. $output = $this->getOutput();
  69. $expected = <<<EOT
  70. ------ ------ -------
  71. I II III
  72. ------ ------ -------
  73. One Two Three
  74. Eins Zwei Drei
  75. Ichi Ni San
  76. Uno Dos Tres
  77. ------ ------ -------
  78. EOT;
  79. $this->assertEquals(trim(preg_replace('#[ \n]+#', ' ', $expected)), trim(preg_replace('#[ \n]+#', ' ', $output)));
  80. $this->drush('try-formatters --format=yaml --fields=III,II', array(), $options, NULL, NULL, self::EXIT_SUCCESS);
  81. $output = $this->getOutput();
  82. $expected = <<<EOT
  83. en:
  84. third: Three
  85. second: Two
  86. de:
  87. third: Drei
  88. second: Zwei
  89. jp:
  90. third: San
  91. second: Ni
  92. es:
  93. third: Tres
  94. second: Dos
  95. EOT;
  96. $this->assertEquals($expected, $output);
  97. $this->drush('try-formatters', array(), $options + ['backend' => NULL]);
  98. $parsed = $this->parse_backend_output($this->getOutput());
  99. $data = $parsed['object'];
  100. $expected = <<<EOT
  101. {"en":{"first":"One","second":"Two","third":"Three"},"de":{"first":"Eins","second":"Zwei","third":"Drei"},"jp":{"first":"Ichi","second":"Ni","third":"San"},"es":{"first":"Uno","second":"Dos","third":"Tres"}}
  102. EOT;
  103. $this->assertEquals($expected, json_encode($data));
  104. // drush try-formatters --help
  105. $this->drush('try-formatters', array(), $options + ['help' => NULL], NULL, NULL, self::EXIT_SUCCESS);
  106. $output = $this->getOutput();
  107. $this->assertContains('Demonstrate formatters', $output);
  108. $this->assertContains('try:formatters --fields=first,third', $output);
  109. $this->assertContains('try:formatters --fields=III,II', $output);
  110. $this->assertContains('--fields=<first, second, third>', $output);
  111. $this->assertContains('Fields to output. All available', $output);
  112. $this->assertContains('--format=<table>', $output);
  113. $this->assertContains('Select output format. Available:', $output);
  114. $this->assertContains('Aliases: try-formatters', $output);
  115. // If we are running Drupal version 8 or later, then also check to
  116. // see if the demo:greet and annotated:greet commands are available.
  117. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  118. $this->drush('demo:greet symfony', array(), $options, NULL, NULL, self::EXIT_SUCCESS);
  119. $output = $this->getOutput();
  120. $this->assertEquals('Hello symfony', $output);
  121. $this->drush('annotated:greet symfony', array(), $options, NULL, NULL, self::EXIT_SUCCESS);
  122. $output = $this->getOutput();
  123. $this->assertEquals('Hello symfony', $output);
  124. }
  125. // Clear the Drush cache so that our 'woot' command is not cached.
  126. $this->drush('cache-clear', array('drush'), $options, NULL, NULL, self::EXIT_SUCCESS);
  127. }
  128. public function setupModulesForTests($root) {
  129. $wootModule = __DIR__ . '/resources/modules/d' . UNISH_DRUPAL_MAJOR_VERSION . '/woot';
  130. $targetDir = $root . DIRECTORY_SEPARATOR . $this->drupalSitewideDirectory() . '/modules/woot';
  131. $this->mkdir($targetDir);
  132. $this->recursive_copy($wootModule, $targetDir);
  133. }
  134. }