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