|
1
|
|
|
<?php |
|
2
|
|
|
use Ubiquity\utils\base\UArray; |
|
3
|
|
|
|
|
4
|
|
|
require_once 'Ubiquity/utils/base/UArray.php'; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* UArray test case. |
|
8
|
|
|
*/ |
|
9
|
|
|
class UArrayTest extends \Codeception\Test\Unit { |
|
10
|
|
|
private $assoArray; |
|
11
|
|
|
private $array; |
|
12
|
|
|
private $mixed; |
|
13
|
|
|
private $keys; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Prepares the environment before running a test. |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function _before() { |
|
19
|
|
|
$this->assoArray = [ "a" => 1,"b" => 2,"c" => 3,"d" => 4 ]; |
|
20
|
|
|
$this->array = [ 1,2,3,4 ]; |
|
21
|
|
|
$this->mixed = [ 1,2,3,4,"a" => 1 ]; |
|
22
|
|
|
$this->keys = [ "a","b","c","d" ]; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Cleans up the environment after running a test. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function _after() { |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Tests UArray::isAssociative() |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testIsAssociative() { |
|
35
|
|
|
$this->assertTrue ( UArray::isAssociative ( $this->assoArray ) ); |
|
36
|
|
|
$this->assertFalse ( UArray::isAssociative ( $this->array ) ); |
|
37
|
|
|
$this->assertTrue ( UArray::isAssociative ( [ ] ) ); |
|
38
|
|
|
$this->assertTrue ( UArray::isAssociative ( $this->mixed ) ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Tests UArray::extractKeys() |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testExtractKeys() { |
|
45
|
|
|
$this->assertEquals ( [ "a" => 1,"c" => 3 ], UArray::extractKeys ( $this->assoArray, [ "a","c" ] ) ); |
|
46
|
|
|
$this->assertEquals ( [ "a" => 1,"c" => 3 ], UArray::extractKeys ( $this->assoArray, [ "a","c","g" ] ) ); |
|
47
|
|
|
$this->assertEquals ( [ ], UArray::extractKeys ( $this->assoArray, [ ] ) ); |
|
48
|
|
|
$this->assertEquals ( [ ], UArray::extractKeys ( [ ], [ ] ) ); |
|
49
|
|
|
$this->assertEquals ( [ ], UArray::extractKeys ( $this->assoArray, [ ] ) ); |
|
50
|
|
|
$this->assertEquals ( [ ], UArray::extractKeys ( $this->assoArray, [ "e","f" ] ) ); |
|
51
|
|
|
$this->assertEquals ( [ ], UArray::extractKeys ( $this->array, [ "e","f" ] ) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Tests UArray::getValue() |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testGetValue() { |
|
58
|
|
|
$this->assertEquals ( 1, UArray::getValue ( $this->assoArray, "a", 0 ) ); |
|
59
|
|
|
$this->assertEquals ( 2, UArray::getValue ( $this->assoArray, "z", 1 ) ); |
|
60
|
|
|
$this->assertNull ( UArray::getValue ( $this->assoArray, "z", 10 ) ); |
|
61
|
|
|
$this->assertEquals ( 1, UArray::getValue ( $this->array, "a", 0 ) ); |
|
62
|
|
|
$this->assertNull ( UArray::getValue ( $this->array, "z", 10 ) ); |
|
63
|
|
|
$this->assertNull ( UArray::getValue ( [ ], "z", 10 ) ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Tests UArray::getRecursive() |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testGetRecursive() { |
|
70
|
|
|
$this->assertEquals ( 2, UArray::getRecursive ( $this->assoArray, "b" ) ); |
|
71
|
|
|
$this->assertEquals ( 56, UArray::getRecursive ( [ "a" => [ "c" => 56 ] ], "c" ) ); |
|
72
|
|
|
$this->assertEquals ( 123, UArray::getRecursive ( [ "a" => [ "c" => [ "d" => 123 ] ] ], "d" ) ); |
|
73
|
|
|
$this->assertNull ( UArray::getRecursive ( $this->assoArray, "g" ) ); |
|
74
|
|
|
$this->assertEquals ( 130, UArray::getRecursive ( $this->assoArray, "z", 130 ) ); |
|
75
|
|
|
$this->assertNull ( UArray::getRecursive ( [ ], "g" ) ); |
|
76
|
|
|
$this->assertNull ( UArray::getRecursive ( $this->array, "g" ) ); |
|
77
|
|
|
$this->assertEquals ( 3, UArray::getRecursive ( $this->array, 2 ) ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Tests UArray::getDefaultValue() |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testGetDefaultValue() { |
|
84
|
|
|
$this->assertEquals ( 2, UArray::getDefaultValue ( $this->assoArray, "b", 50 ) ); |
|
85
|
|
|
$this->assertEquals ( 50, UArray::getDefaultValue ( $this->assoArray, "z", 50 ) ); |
|
86
|
|
|
$this->assertEquals ( 2, UArray::getDefaultValue ( $this->array, 1, 50 ) ); |
|
87
|
|
|
$this->assertEquals ( 50, UArray::getDefaultValue ( $this->array, 300, 50 ) ); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Tests UArray::asPhpArray() |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testAsPhpArray() { |
|
94
|
|
|
$this->assertEquals ( $this->assoArray, eval ( UArray::asPhpArray ( $this->assoArray, 'return array' ) . ";" ) ); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Tests UArray::asJSON() |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testAsJSON() { |
|
101
|
|
|
// TODO Auto-generated UArrayTest::testAsJSON() |
|
102
|
|
|
$this->markTestIncomplete ( "asJSON test not implemented" ); |
|
103
|
|
|
|
|
104
|
|
|
UArray::asJSON(/* parameters */); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Tests UArray::remove() |
|
109
|
|
|
*/ |
|
110
|
|
|
public function testRemove() { |
|
111
|
|
|
// TODO Auto-generated UArrayTest::testRemove() |
|
112
|
|
|
$this->markTestIncomplete ( "remove test not implemented" ); |
|
113
|
|
|
|
|
114
|
|
|
UArray::remove(/* parameters */); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Tests UArray::removeByKey() |
|
119
|
|
|
*/ |
|
120
|
|
|
public function testRemoveByKey() { |
|
121
|
|
|
// TODO Auto-generated UArrayTest::testRemoveByKey() |
|
122
|
|
|
$this->markTestIncomplete ( "removeByKey test not implemented" ); |
|
123
|
|
|
|
|
124
|
|
|
UArray::removeByKey(/* parameters */); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Tests UArray::removeRecursive() |
|
129
|
|
|
*/ |
|
130
|
|
|
public function testRemoveRecursive() { |
|
131
|
|
|
// TODO Auto-generated UArrayTest::testRemoveRecursive() |
|
132
|
|
|
$this->markTestIncomplete ( "removeRecursive test not implemented" ); |
|
133
|
|
|
|
|
134
|
|
|
UArray::removeRecursive(/* parameters */); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Tests UArray::removeByKeys() |
|
139
|
|
|
*/ |
|
140
|
|
|
public function testRemoveByKeys() { |
|
141
|
|
|
// TODO Auto-generated UArrayTest::testRemoveByKeys() |
|
142
|
|
|
$this->markTestIncomplete ( "removeByKeys test not implemented" ); |
|
143
|
|
|
|
|
144
|
|
|
UArray::removeByKeys(/* parameters */); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Tests UArray::removeOne() |
|
149
|
|
|
*/ |
|
150
|
|
|
public function testRemoveOne() { |
|
151
|
|
|
// TODO Auto-generated UArrayTest::testRemoveOne() |
|
152
|
|
|
$this->markTestIncomplete ( "removeOne test not implemented" ); |
|
153
|
|
|
|
|
154
|
|
|
UArray::removeOne(/* parameters */); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Tests UArray::update() |
|
159
|
|
|
*/ |
|
160
|
|
|
public function testUpdate() { |
|
161
|
|
|
// TODO Auto-generated UArrayTest::testUpdate() |
|
162
|
|
|
$this->markTestIncomplete ( "update test not implemented" ); |
|
163
|
|
|
|
|
164
|
|
|
UArray::update(/* parameters */); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Tests UArray::doubleBackSlashes() |
|
169
|
|
|
*/ |
|
170
|
|
|
public function testDoubleBackSlashes() { |
|
171
|
|
|
// TODO Auto-generated UArrayTest::testDoubleBackSlashes() |
|
172
|
|
|
$this->markTestIncomplete ( "doubleBackSlashes test not implemented" ); |
|
173
|
|
|
|
|
174
|
|
|
UArray::doubleBackSlashes(/* parameters */); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Tests UArray::iSearch() |
|
179
|
|
|
*/ |
|
180
|
|
|
public function testISearch() { |
|
181
|
|
|
// TODO Auto-generated UArrayTest::testISearch() |
|
182
|
|
|
$this->markTestIncomplete ( "iSearch test not implemented" ); |
|
183
|
|
|
|
|
184
|
|
|
UArray::iSearch(/* parameters */); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Tests UArray::iRemove() |
|
189
|
|
|
*/ |
|
190
|
|
|
public function testIRemove() { |
|
191
|
|
|
// TODO Auto-generated UArrayTest::testIRemove() |
|
192
|
|
|
$this->markTestIncomplete ( "iRemove test not implemented" ); |
|
193
|
|
|
|
|
194
|
|
|
UArray::iRemove(/* parameters */); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Tests UArray::iRemoveOne() |
|
199
|
|
|
*/ |
|
200
|
|
|
public function testIRemoveOne() { |
|
201
|
|
|
// TODO Auto-generated UArrayTest::testIRemoveOne() |
|
202
|
|
|
$this->markTestIncomplete ( "iRemoveOne test not implemented" ); |
|
203
|
|
|
|
|
204
|
|
|
UArray::iRemoveOne(/* parameters */); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
|