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