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 script / list',
  51. 'command' => 'core-status',
  52. 'args' => array('drush script'),
  53. 'options' => array(),
  54. 'format' => 'list',
  55. 'output_filter' => array('#/.*drush.php#' => 'drush.php',),
  56. 'expected' => 'drush.php',
  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]+[^']*/" => '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-z0-9\.-]*/" => '0.0-dev',
  97. '#/.*/etc/drush#' => '/etc/drush',
  98. "/(Drush script *: ).*drush.php/" => "Drush script: drush.php",
  99. ),
  100. 'expected' => "Drush script: drush.php
  101. Drush version : 0.0-dev
  102. Drush temp directory : $unish_tmp
  103. Drush configuration :
  104. Drush alias files : /etc/drush/dev.alias.drushrc.php",
  105. ),
  106. /*
  107. core-requirements is a little hard to test, because the
  108. output can be quite variable
  109. array(
  110. 'name' => 'Requirements test - table',
  111. 'command' => 'core-requirements',
  112. 'args' => array(),
  113. 'format' => 'table',
  114. 'output_filter' => array(),
  115. 'expected' => "",
  116. ),
  117. */
  118. // array(
  119. // 'name' => 'pm-updatestatus - table',
  120. // 'command' => 'pm-updatestatus',
  121. // 'args' => array(),
  122. // 'options' => array(),
  123. // 'format' => 'table',
  124. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  125. // 'expected' => "Name Installed Version Proposed version Message
  126. // Drupal 0.0 0.0 Up to date",
  127. // ),
  128. /*
  129. pm-updatestatus --format=csv does not work.
  130. should filter out the items that do not need updating, and print just
  131. the name of the projects that need updates
  132. array(
  133. 'name' => 'pm-updatestatus - csv',
  134. 'command' => 'pm-updatestatus',
  135. 'args' => array(),
  136. 'format' => 'csv',
  137. 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
  138. 'expected' => "",
  139. ),
  140. */
  141. // updatestatus now omits projects that are up tp date. this test now needs work.
  142. // array(
  143. // 'name' => 'pm-updatestatus - csv',
  144. // 'command' => 'pm-updatestatus',
  145. // 'args' => array(),
  146. // 'options' => array(),
  147. // 'format' => 'csv',
  148. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  149. // 'expected' => "drupal,0.0,0.0,Up to date",
  150. // ),
  151. /*
  152. pm-updatestatus --format=ini does not work
  153. array(
  154. 'name' => 'pm-updatestatus - ini',
  155. 'command' => 'pm-updatestatus',
  156. 'args' => array(),
  157. 'format' => 'ini',
  158. 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
  159. 'expected' => "",
  160. ),
  161. */
  162. // array(
  163. // 'name' => 'pm-updatestatus - ini-sections',
  164. // 'command' => 'pm-updatestatus',
  165. // 'args' => array(),
  166. // 'format' => 'ini-sections',
  167. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  168. // 'expected' => "[drupal]
  169. //short_name=drupal
  170. //installed_version=0.0
  171. //proposed_version=0.0
  172. //message=Up to date",
  173. // ),
  174. /*
  175. pm-updatestatus --format=key-value does not work
  176. array(
  177. 'name' => 'pm-updatestatus - key-value',
  178. 'command' => 'pm-updatestatus',
  179. 'args' => array(),
  180. 'options' => array(),
  181. 'format' => 'key-value',
  182. 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
  183. 'expected' => "",
  184. ),
  185. */
  186. // array(
  187. // 'name' => 'pm-updatestatus - key-value-list',
  188. // 'command' => 'pm-updatestatus',
  189. // 'args' => array(),
  190. // 'options' => array(),
  191. // 'format' => 'key-value-list',
  192. // 'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
  193. // 'expected' => "Name : Drupal
  194. // Installed Version : 0.0
  195. // Proposed version : 0.0
  196. // Message : Up to date",
  197. // ),
  198. array(
  199. 'name' => 'pm-info - key-value-list',
  200. 'command' => 'pm-info',
  201. 'args' => array('devel'),
  202. 'options' => array('fields' => 'project,type,devel,description'),
  203. 'format' => 'key-value-list',
  204. 'output_filter' => array(),
  205. 'expected' => "Project : devel
  206. Type : module
  207. Description : Various blocks, pages, and functions for developers.",
  208. ),
  209. array(
  210. 'name' => 'pm-info - csv',
  211. 'command' => 'pm-info',
  212. 'args' => array('devel'),
  213. 'options' => array('fields' => 'project,type,devel,description'),
  214. 'format' => 'csv',
  215. 'expected' => "devel,module,\"Various blocks, pages, and functions for developers.\"",
  216. ),
  217. /*
  218. pm-info --format=ini does not work.
  219. The output data could not be processed by the selected format 'string'.
  220. Multiple rows provided where only one is allowed.
  221. array(
  222. 'name' => 'pm-info - ini',
  223. 'command' => 'pm-info',
  224. 'args' => array('devel'),
  225. 'options' => array('fields' => 'project,type,devel,description'),
  226. 'format' => 'ini',
  227. 'expected' => "",
  228. ),
  229. */
  230. // array(
  231. // 'name' => 'pm-info - ini-sections',
  232. // 'command' => 'pm-info',
  233. // 'args' => array('devel'),
  234. // 'options' => array('fields' => 'project,type,devel,description'),
  235. // 'format' => 'ini-sections',
  236. // 'expected' => "[devel]
  237. //project=devel
  238. //type=module
  239. //description=Various blocks, pages, and functions for developers.",
  240. // ),
  241. /*
  242. pm-info --format=key-value does not respect --fields
  243. array(
  244. 'name' => 'pm-info - key-value',
  245. 'command' => 'pm-info',
  246. 'args' => array('devel'),
  247. 'options' => array('fields' => 'project,type,devel,description'),
  248. 'format' => 'key-value',
  249. 'expected' => "",
  250. ),
  251. */
  252. array(
  253. 'name' => 'pm-info - table',
  254. 'command' => 'pm-info',
  255. 'args' => array('devel'),
  256. 'options' => array('fields' => 'project,type,description'),
  257. 'format' => 'table',
  258. 'output_filter' => array(),
  259. 'expected' => "Project Type Description
  260. devel module Various blocks, pages, and functions for developers.",
  261. ),
  262. // More commands that also support output formats:
  263. // pm-list
  264. // queue-list
  265. // cache-get
  266. // config-get and config-list (D8 only)
  267. // field-info
  268. // php-eval
  269. // role-list
  270. // search-status
  271. // site-alias
  272. // user-information
  273. // variable-get
  274. // version
  275. // watchdog-list
  276. // watchdog-show
  277. );
  278. }
  279. }