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. $json = json_encode(json_decode($json), JSON_PRETTY_PRINT);
  20. return array(
  21. array(
  22. 'name' => 'String test',
  23. 'format' => 'string',
  24. 'data' => array('drush version' => '6.0-dev'),
  25. 'expected' => '6.0-dev',
  26. ),
  27. array(
  28. 'name' => 'List test',
  29. 'format' => 'list',
  30. 'data' => array('drush version' => '6.0-dev'),
  31. 'expected' => '6.0-dev',
  32. ),
  33. array(
  34. 'name' => 'Key-value test',
  35. 'format' => 'key-value',
  36. 'data' => array('drush version' => '6.0-dev'),
  37. 'expected' => 'drush version : 6.0-dev',
  38. ),
  39. // array(
  40. // 'name' => 'Table test',
  41. // 'format' => 'table',
  42. // 'data' => array(
  43. // 'a' => array('b' => 2, 'c' => 3),
  44. // 'd' => array('b' => 5, 'c' => 6),
  45. // ),
  46. // 'expected' => "b c
  47. // 2 3
  48. // 5 6",
  49. // ),
  50. array(
  51. 'name' => 'print-r test',
  52. 'format' => 'print-r',
  53. 'data' => array(
  54. 'a' => array('b' => 2, 'c' => 3),
  55. 'd' => array('b' => 5, 'c' => 6),
  56. ),
  57. 'expected' => "Array
  58. (
  59. [a] => Array
  60. (
  61. [b] => 2
  62. [c] => 3
  63. )
  64. [d] => Array
  65. (
  66. [b] => 5
  67. [c] => 6
  68. )
  69. )",
  70. ),
  71. array(
  72. 'name' => 'json test',
  73. 'format' => 'json',
  74. 'data' => array(
  75. 'a' => array('b' => 2, 'c' => 3),
  76. 'd' => array('e' => 5, 'f' => 6),
  77. ),
  78. 'expected' => $json,
  79. ),
  80. // array(
  81. // 'name' => 'key-value test 1d array',
  82. // 'format' => 'key-value',
  83. // 'data' => array(
  84. // 'b' => 'Two B or ! Two B, that is the comparison',
  85. // 'c' => 'I see that C has gone to Sea',
  86. // ),
  87. // 'expected' => "b : Two B or ! Two B, that is the comparison
  88. // c : I see that C has gone to Sea",
  89. // ),
  90. // array(
  91. // 'name' => 'key-value test 2d array',
  92. // 'format' => 'key-value',
  93. // 'data' => array(
  94. // 'a' => array(
  95. // 'b' => 'Two B or ! Two B, that is the comparison',
  96. // 'c' => 'I see that C has gone to Sea',
  97. // ),
  98. // 'd' => array(
  99. // 'e' => 'Elephants and electron microscopes',
  100. // 'f' => 'My margin is too small',
  101. // )
  102. // ),
  103. // 'expected' => "a : Two B or ! Two B, that is the comparison
  104. // I see that C has gone to Sea
  105. // d : Elephants and electron microscopes
  106. // My margin is too small",
  107. // ),
  108. array(
  109. 'name' => 'export test',
  110. 'format' => 'var_export',
  111. 'data' => array(
  112. 'a' => array('b' => 2, 'c' => 3),
  113. 'd' => array('e' => 5, 'f' => 6),
  114. ),
  115. 'expected' => "array(
  116. 'a' => array(
  117. 'b' => 2,
  118. 'c' => 3,
  119. ),
  120. 'd' => array(
  121. 'e' => 5,
  122. 'f' => 6,
  123. ),
  124. )",
  125. ),
  126. // array(
  127. // 'name' => 'config test',
  128. // 'format' => 'config',
  129. // 'data' => array(
  130. // 'a' => array('b' => 2, 'c' => 3),
  131. // 'd' => array('e' => 5, 'f' => 6),
  132. // ),
  133. // 'expected' => "\$config[\"a\"] = array (
  134. // 'b' => 2,
  135. // 'c' => 3,
  136. //);
  137. //\$config[\"d\"] = array (
  138. // 'e' => 5,
  139. // 'f' => 6,
  140. //);",
  141. // ),
  142. array(
  143. 'name' => 'variables test',
  144. 'format' => 'variables',
  145. 'data' => array(
  146. 'a' => array('b' => 2, 'c' => 3),
  147. 'd' => array('e' => 5, 'f' => 6),
  148. ),
  149. 'expected' => "\$a[\"b\"] = 2;
  150. \$a[\"c\"] = 3;
  151. \$d[\"e\"] = 5;
  152. \$d[\"f\"] = 6;",
  153. ),
  154. );
  155. }
  156. }