outputFormatTest.php

  1. 8.0.x tests/outputFormatTest.php
  2. 6.x tests/outputFormatTest.php
  3. 7.x tests/outputFormatTest.php

Namespace

Unish

Classes

Namesort descending Description
outputFormatCase @todo, Consider removing these tests now that we have outputFormatUnitCase.

File

tests/outputFormatTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Tests for outputformat.drush.inc
  5. */
  6. /**
  7. * @todo, Consider removing these tests now that we have outputFormatUnitCase.
  8. *
  9. * @group slow
  10. * @group base
  11. */
  12. class outputFormatCase extends CommandUnishTestCase {
  13. /**
  14. * Test output formats using various Drush commands on a Drupal site.
  15. *
  16. * Cannot use dataProvider since we want to share one setUpDrupal(),
  17. **/
  18. public function testOutputFormatWithDrupal() {
  19. $data = $this->getDataForDrupal();
  20. $sites = $this->setUpDrupal(1, TRUE);
  21. $site_options = array(
  22. 'root' => $this->webroot(),
  23. 'uri' => key($sites),
  24. );
  25. $this->drush('pm-download', array('devel'), $site_options + array('cache' => NULL, 'skip' => TRUE));
  26. foreach ($data as $row) {
  27. extract($row);
  28. $name = $name . ": ";
  29. // We need to specify a fixed column width so that word wrapping does
  30. // not change our output contrary to our expectations when run in
  31. // a narrow terminal window.
  32. $env = array(
  33. 'COLUMNS' => '800',
  34. );
  35. $this->drush($command, $args, $site_options + $options + array('format' => $format), NULL, NULL, self::EXIT_SUCCESS, NULL, $env);
  36. $output = implode("\n", $this->getOutputAsList()); // note: we consider trailing eols insignificant
  37. // If the Drupal command we are running might produce variable output,
  38. // we can use one or more output filters to simplify the output down
  39. // to an invariant form.
  40. foreach ($output_filter as $regex => $replacement) {
  41. $output = preg_replace($regex, $replacement, $output);
  42. }
  43. $this->assertEquals($name . $expected, $name. $output);
  44. }
  45. }
  46. public function getDataForDrupal() {
  47. $unish_tmp = UNISH_TMP; // Need local variable.
  48. return array(
  49. array(
  50. 'name' => 'Status test - drush version / list',
  51. 'command' => 'core-status',
  52. 'args' => array('drush version'),
  53. 'options' => array(),
  54. 'format' => 'list',
  55. 'output_filter' => array('/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev',),
  56. 'expected' => '0.0-dev',
  57. ),
  58. // array(
  59. // 'name' => 'Status test - drush / ini',
  60. // 'command' => 'core-status',
  61. // 'args' => array('drush'),
  62. // 'format' => 'ini',
  63. // 'output_filter' => array('/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev', '#/.*/etc/drush#' => '/etc/drush'),
  64. // 'expected' => 'drush-version=0.0-dev
  65. //drush-conf=
  66. //drush-alias-files=/etc/drush/dev.alias.drushrc.php',
  67. // ),
  68. array(
  69. 'name' => 'Status test - drush / export',
  70. 'command' => 'core-status',
  71. 'args' => array('drush'),
  72. 'options' => array(),
  73. 'format' => 'var_export',
  74. 'output_filter' => array(
  75. '/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev',
  76. '#/.*/etc/drush#' => '/etc/drush',
  77. "/'drush-script' => '.*drush.php'/" => "'drush-script' => 'drush.php'",
  78. ),
  79. 'expected' => "array(
  80. 'drush-script' => 'drush.php',
  81. 'drush-version' => '0.0-dev',
  82. 'drush-temp' => '$unish_tmp',
  83. 'drush-conf' => array(),
  84. 'drush-alias-files' => array(
  85. '/etc/drush/dev.alias.drushrc.php',
  86. ),
  87. )",
  88. ),
  89. array(
  90. 'name' => 'Status test - drush / key-value',
  91. 'command' => 'core-status',
  92. 'args' => array('drush'),
  93. 'options' => array(),
  94. 'format' => 'key-value',
  95. 'output_filter' => array(
  96. '/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev', '#/.*/etc/drush#' => '/etc/drush',
  97. "/(Drush script *: ).*drush.php/" => "Drush script: drush.php",
  98. ),
  99. 'expected' => "Drush script: drush.php
  100. Drush version : 0.0-dev
  101. Drush temp directory : $unish_tmp
  102. Drush configuration :
  103. Drush alias files : /etc/drush/dev.alias.drushrc.php",
  104. ),
  105. /*
  106. core-requirements is a little hard to test, because the
  107. output can be quite variable
  108. array(
  109. 'name' => 'Requirements test - table',
  110. 'command' => 'core-requirements',
  111. 'args' => array(),
  112. 'format' => 'table',
  113. 'output_filter' => array(),
  114. 'expected' => "",
  115. ),
  116. */
  117. // array(
  118. // 'name' => 'pm-updatestatus - table',
  119. // 'command' => 'pm-updatestatus',
  120. // 'args' => array(),
  121. // 'options' => array(),
  122. // 'format' => 'table',
  123. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  124. // 'expected' => "Name Installed Version Proposed version Message
  125. // Drupal 0.0 0.0 Up to date",
  126. // ),
  127. /*
  128. pm-updatestatus --format=csv does not work.
  129. should filter out the items that do not need updating, and print just
  130. the name of the projects that need updates
  131. array(
  132. 'name' => 'pm-updatestatus - csv',
  133. 'command' => 'pm-updatestatus',
  134. 'args' => array(),
  135. 'format' => 'csv',
  136. 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
  137. 'expected' => "",
  138. ),
  139. */
  140. // updatestatus now omits projects that are up tp date. this test now needs work.
  141. // array(
  142. // 'name' => 'pm-updatestatus - csv',
  143. // 'command' => 'pm-updatestatus',
  144. // 'args' => array(),
  145. // 'options' => array(),
  146. // 'format' => 'csv',
  147. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  148. // 'expected' => "drupal,0.0,0.0,Up to date",
  149. // ),
  150. /*
  151. pm-updatestatus --format=ini does not work
  152. array(
  153. 'name' => 'pm-updatestatus - ini',
  154. 'command' => 'pm-updatestatus',
  155. 'args' => array(),
  156. 'format' => 'ini',
  157. 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
  158. 'expected' => "",
  159. ),
  160. */
  161. // array(
  162. // 'name' => 'pm-updatestatus - ini-sections',
  163. // 'command' => 'pm-updatestatus',
  164. // 'args' => array(),
  165. // 'format' => 'ini-sections',
  166. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  167. // 'expected' => "[drupal]
  168. //short_name=drupal
  169. //installed_version=0.0
  170. //proposed_version=0.0
  171. //message=Up to date",
  172. // ),
  173. /*
  174. pm-updatestatus --format=key-value does not work
  175. array(
  176. 'name' => 'pm-updatestatus - key-value',
  177. 'command' => 'pm-updatestatus',
  178. 'args' => array(),
  179. 'options' => array(),
  180. 'format' => 'key-value',
  181. 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
  182. 'expected' => "",
  183. ),
  184. */
  185. // array(
  186. // 'name' => 'pm-updatestatus - key-value-list',
  187. // 'command' => 'pm-updatestatus',
  188. // 'args' => array(),
  189. // 'options' => array(),
  190. // 'format' => 'key-value-list',
  191. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  192. // 'expected' => "Name : Drupal
  193. // Installed Version : 0.0
  194. // Proposed version : 0.0
  195. // Message : Up to date",
  196. // ),
  197. array(
  198. 'name' => 'pm-info - key-value-list',
  199. 'command' => 'pm-info',
  200. 'args' => array('devel'),
  201. 'options' => array('fields' => 'project,type,devel,description'),
  202. 'format' => 'key-value-list',
  203. 'output_filter' => array(),
  204. 'expected' => "Project : devel
  205. Type : module
  206. Description : Various blocks, pages, and functions for developers.",
  207. ),
  208. array(
  209. 'name' => 'pm-info - csv',
  210. 'command' => 'pm-info',
  211. 'args' => array('devel'),
  212. 'options' => array('fields' => 'project,type,devel,description'),
  213. 'format' => 'csv',
  214. 'expected' => "devel,module,\"Various blocks, pages, and functions for developers.\"",
  215. ),
  216. /*
  217. pm-info --format=ini does not work.
  218. The output data could not be processed by the selected format 'string'.
  219. Multiple rows provided where only one is allowed.
  220. array(
  221. 'name' => 'pm-info - ini',
  222. 'command' => 'pm-info',
  223. 'args' => array('devel'),
  224. 'options' => array('fields' => 'project,type,devel,description'),
  225. 'format' => 'ini',
  226. 'expected' => "",
  227. ),
  228. */
  229. // array(
  230. // 'name' => 'pm-info - ini-sections',
  231. // 'command' => 'pm-info',
  232. // 'args' => array('devel'),
  233. // 'options' => array('fields' => 'project,type,devel,description'),
  234. // 'format' => 'ini-sections',
  235. // 'expected' => "[devel]
  236. //project=devel
  237. //type=module
  238. //description=Various blocks, pages, and functions for developers.",
  239. // ),
  240. /*
  241. pm-info --format=key-value does not respect --fields
  242. array(
  243. 'name' => 'pm-info - key-value',
  244. 'command' => 'pm-info',
  245. 'args' => array('devel'),
  246. 'options' => array('fields' => 'project,type,devel,description'),
  247. 'format' => 'key-value',
  248. 'expected' => "",
  249. ),
  250. */
  251. array(
  252. 'name' => 'pm-info - table',
  253. 'command' => 'pm-info',
  254. 'args' => array('devel'),
  255. 'options' => array('fields' => 'project,type,description'),
  256. 'format' => 'table',
  257. 'output_filter' => array(),
  258. 'expected' => "Project Type Description
  259. devel module Various blocks, pages, and functions for developers.",
  260. ),
  261. // More commands that also support output formats:
  262. // pm-list
  263. // queue-list
  264. // cache-get
  265. // config-get and config-list (D8 only)
  266. // field-info
  267. // php-eval
  268. // role-list
  269. // search-status
  270. // site-alias
  271. // user-information
  272. // variable-get
  273. // version
  274. // watchdog-list
  275. // watchdog-show
  276. );
  277. }
  278. }