outputFormatUnitTest.php

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

Tests for outputformat.drush.inc

Namespace

Unish

Classes

File

tests/outputFormatUnitTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for outputformat.drush.inc
  5. */
  6. namespace Unish;
  7. class outputFormatUnitCase extends UnitUnishTestCase {
  8. /**
  9. * Test various output formats using php-eval with no Drupal site.
  10. *
  11. * @dataProvider provider
  12. **/
  13. public function testOutputFormat($name, $format, $data, $expected) {
  14. drush_preflight();
  15. $this->assertEquals($expected, trim(drush_format($data, array(), $format)), $name . ': '. $format);
  16. }
  17. public function provider() {
  18. $json = '{"a":{"b":2,"c":3},"d":{"e":5,"f":6}}';
  19. if (version_compare(phpversion(), '5.4.0', '>=')) {
  20. $json = json_encode(json_decode($json), JSON_PRETTY_PRINT);
  21. }
  22. return array(
  23. array(
  24. 'name' => 'String test',
  25. 'format' => 'string',
  26. 'data' => array('drush version' => '6.0-dev'),
  27. 'expected' => '6.0-dev',
  28. ),
  29. array(
  30. 'name' => 'List test',
  31. 'format' => 'list',
  32. 'data' => array('drush version' => '6.0-dev'),
  33. 'expected' => '6.0-dev',
  34. ),
  35. array(
  36. 'name' => 'Key-value test',
  37. 'format' => 'key-value',
  38. 'data' => array('drush version' => '6.0-dev'),
  39. 'expected' => 'drush version : 6.0-dev',
  40. ),
  41. // array(
  42. // 'name' => 'Table test',
  43. // 'format' => 'table',
  44. // 'data' => array(
  45. // 'a' => array('b' => 2, 'c' => 3),
  46. // 'd' => array('b' => 5, 'c' => 6),
  47. // ),
  48. // 'expected' => "b c
  49. // 2 3
  50. // 5 6",
  51. // ),
  52. array(
  53. 'name' => 'print-r test',
  54. 'format' => 'print-r',
  55. 'data' => array(
  56. 'a' => array('b' => 2, 'c' => 3),
  57. 'd' => array('b' => 5, 'c' => 6),
  58. ),
  59. 'expected' => "Array
  60. (
  61. [a] => Array
  62. (
  63. [b] => 2
  64. [c] => 3
  65. )
  66. [d] => Array
  67. (
  68. [b] => 5
  69. [c] => 6
  70. )
  71. )",
  72. ),
  73. array(
  74. 'name' => 'json test',
  75. 'format' => 'json',
  76. 'data' => array(
  77. 'a' => array('b' => 2, 'c' => 3),
  78. 'd' => array('e' => 5, 'f' => 6),
  79. ),
  80. 'expected' => $json,
  81. ),
  82. // array(
  83. // 'name' => 'key-value test 1d array',
  84. // 'format' => 'key-value',
  85. // 'data' => array(
  86. // 'b' => 'Two B or ! Two B, that is the comparison',
  87. // 'c' => 'I see that C has gone to Sea',
  88. // ),
  89. // 'expected' => "b : Two B or ! Two B, that is the comparison
  90. // c : I see that C has gone to Sea",
  91. // ),
  92. // array(
  93. // 'name' => 'key-value test 2d array',
  94. // 'format' => 'key-value',
  95. // 'data' => array(
  96. // 'a' => array(
  97. // 'b' => 'Two B or ! Two B, that is the comparison',
  98. // 'c' => 'I see that C has gone to Sea',
  99. // ),
  100. // 'd' => array(
  101. // 'e' => 'Elephants and electron microscopes',
  102. // 'f' => 'My margin is too small',
  103. // )
  104. // ),
  105. // 'expected' => "a : Two B or ! Two B, that is the comparison
  106. // I see that C has gone to Sea
  107. // d : Elephants and electron microscopes
  108. // My margin is too small",
  109. // ),
  110. array(
  111. 'name' => 'export test',
  112. 'format' => 'var_export',
  113. 'data' => array(
  114. 'a' => array('b' => 2, 'c' => 3),
  115. 'd' => array('e' => 5, 'f' => 6),
  116. ),
  117. 'expected' => "array(
  118. 'a' => array(
  119. 'b' => 2,
  120. 'c' => 3,
  121. ),
  122. 'd' => array(
  123. 'e' => 5,
  124. 'f' => 6,
  125. ),
  126. )",
  127. ),
  128. // array(
  129. // 'name' => 'config test',
  130. // 'format' => 'config',
  131. // 'data' => array(
  132. // 'a' => array('b' => 2, 'c' => 3),
  133. // 'd' => array('e' => 5, 'f' => 6),
  134. // ),
  135. // 'expected' => "\$config[\"a\"] = array (
  136. // 'b' => 2,
  137. // 'c' => 3,
  138. //);
  139. //\$config[\"d\"] = array (
  140. // 'e' => 5,
  141. // 'f' => 6,
  142. //);",
  143. // ),
  144. array(
  145. 'name' => 'variables test',
  146. 'format' => 'variables',
  147. 'data' => array(
  148. 'a' => array('b' => 2, 'c' => 3),
  149. 'd' => array('e' => 5, 'f' => 6),
  150. ),
  151. 'expected' => "\$a[\"b\"] = 2;
  152. \$a[\"c\"] = 3;
  153. \$d[\"e\"] = 5;
  154. \$d[\"f\"] = 6;",
  155. ),
  156. );
  157. }
  158. }