Repository navigation
Expand file tree
/
Copy pathtest-aliases.php
More file actions
296 lines (221 loc) · 9.91 KB
/
Copy pathtest-aliases.php
File metadata and controls
296 lines (221 loc) · 9.91 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
/**
* UniFi Controller Client Alias Sync script unit tests related to client aliases.
*
* Copyright (c) 2018 by Scott Reilly (aka coffee2code)
*
* @package UniFi_Client_Alias_Sync
* @author Scott Reilly
*/
use PHPUnit\Framework\TestCase;
final class UniFiClientAliasAliasesTest extends UniFiClientAliasTestBase {
public function setUp() {
parent::setUp();
$this->mock_clients();
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', true );
}
public function tearDown() {
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', false );
}
public function test_get_client_aliases_for_site_for_invalid_site() {
$test = self::get_method( 'get_client_aliases_for_site' );
$aliases = $test->invokeArgs( self::$syncer, [ 'invalid' ] );
$this->assertEmpty( $aliases );
}
public function test_get_client_aliases_for_last_site() {
$expected = [
'90:04:e3:51:9d:a1' => "Adam's iPhone 8",
'35:19:29:f5:4b:1e' => "Brenda's Note 8",
'e4:d9:c7:cc:46:3b' => "HP Inkjet Printer",
'9e:cc:a1:2f:0b:aa' => "iPad X - Walter",
];
$test = self::get_method( 'get_client_aliases_for_site' );
$aliases = $test->invokeArgs( self::$syncer, [ 'cd90qe2s' ] );
$this->assertEquals( $expected, $aliases );
}
public function test_get_client_aliases_for_first_site() {
$expected = [
'9e:cc:a1:2f:0b:aa' => "iPad X - Walter",
'bc:3e:ea:26:8d:50' => "Only on lowest priority site",
];
$test = self::get_method( 'get_client_aliases_for_site' );
$aliases = $test->invokeArgs( self::$syncer, [ 'default' ] );
$this->assertEquals( $expected, $aliases );
}
public function test_get_client_aliases_for_last_site_with_overwrites() {
$this->set_config( 'UNIFI_ALIAS_SYNC_ALLOW_OVERWRITES', true );
$expected = [
'90:04:e3:51:9d:a1' => "Adam's iPhone 8",
'35:19:29:f5:4b:1e' => "Brenda's Note 8",
'e4:d9:c7:cc:46:3b' => "HP Inkjet Printer",
'9e:cc:a1:2f:0b:aa' => "iPad X - Walter",
];
$test = self::get_method( 'get_client_aliases_for_site' );
$aliases = $test->invokeArgs( self::$syncer, [ 'cd90qe2s' ] );
$this->assertEquals( $expected, $aliases );
}
public function test_get_client_aliases_for_first_site_with_overwrites() {
$this->set_config( 'UNIFI_ALIAS_SYNC_ALLOW_OVERWRITES', true );
$expected = [
'9e:cc:a1:2f:0b:aa' => "iPad X - Walter",
'bc:3e:ea:26:8d:50' => "Only on lowest priority site",
];
$test = self::get_method( 'get_client_aliases_for_site' );
$aliases = $test->invokeArgs( self::$syncer, [ 'default' ] );
$this->assertEquals( $expected, $aliases );
}
public function test_get_client_aliases_for_first_site_with_configured_aliases() {
$this->set_config( 'UNIFI_ALIAS_SYNC_ALIASES', [ '35:19:29:f5:4b:1e' => "Brenda's Phone" ] );
$expected = [
'9e:cc:a1:2f:0b:aa' => "iPad X - Walter",
'bc:3e:ea:26:8d:50' => "Only on lowest priority site",
'35:19:29:f5:4b:1e' => "Brenda's Phone",
];
$test = self::get_method( 'get_client_aliases_for_site' );
$aliases = $test->invokeArgs( self::$syncer, [ 'default' ] );
$this->assertEquals( $expected, $aliases );
}
public function test_sync_aliases() {
// Get client aliases early just so it'll already be memoized and thus not
// appear in output.
$test = self::get_method( 'get_aliased_clients' );
$test->invoke( self::$syncer );
$expected = <<<TEXT
About to assign client aliases to site default...
Would have set alias for 9e:cc:a1:2f:0b:aa to "iPad X - Walter".
Clients assigned an alias: 1.
About to assign client aliases to site 1qwe314gn...
No clients assigned an alias.
About to assign client aliases to site 9lirxq5p...
Would have set alias for e4:d9:c7:cc:46:3b to "HP Inkjet Printer".
Would have set alias for 35:19:29:f5:4b:1e to "Brenda's Note 8".
Client 90:04:e3:51:9d:a1 already aliased as "iPhone 8 - Adam" (thus not getting aliased as "Adam's iPhone 8").
Clients assigned an alias: 2.
About to assign client aliases to site a98ey4l5...
No clients assigned an alias.
About to assign client aliases to site cd90qe2s...
Client 35:19:29:f5:4b:1e already has the alias "Brenda's Note 8".
No clients assigned an alias.
TEXT;
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', false );
$test = self::get_method( 'sync_aliases' );
$this->expectOutputString( $expected );
$aliases = $test->invoke( self::$syncer );
}
public function test_sync_aliases_with_overwrites_allowed() {
$this->set_config( 'UNIFI_ALIAS_SYNC_ALLOW_OVERWRITES', true );
// Get client aliases early just so it'll already be memoized and thus not
// appear in output.
$test = self::get_method( 'get_aliased_clients' );
$test->invoke( self::$syncer );
$expected = <<<TEXT
About to assign client aliases to site default...
Would have set alias for 9e:cc:a1:2f:0b:aa to "iPad X - Walter".
Clients assigned an alias: 1.
About to assign client aliases to site 1qwe314gn...
No clients assigned an alias.
About to assign client aliases to site 9lirxq5p...
Would have set alias for e4:d9:c7:cc:46:3b to "HP Inkjet Printer".
Would have set alias for 35:19:29:f5:4b:1e to "Brenda's Note 8".
Would have set alias for 90:04:e3:51:9d:a1 to "Adam's iPhone 8" (overwriting existing alias of "iPhone 8 - Adam").
Clients assigned an alias: 3.
About to assign client aliases to site a98ey4l5...
No clients assigned an alias.
About to assign client aliases to site cd90qe2s...
Client 35:19:29:f5:4b:1e already has the alias "Brenda's Note 8".
No clients assigned an alias.
TEXT;
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', false );
$test = self::get_method( 'sync_aliases' );
$this->expectOutputString( $expected );
$aliases = $test->invoke( self::$syncer );
}
public function test_excluded_sites_do_not_contribute_client_aliases() {
$this->set_config( 'UNIFI_ALIAS_SYNC_EXCLUDE_SITES', [ '9lirxq5p' ] );
// Get client aliases early just so it'll already be memoized and thus not
// appear in output.
$test = self::get_method( 'get_aliased_clients' );
$test->invoke( self::$syncer );
$expected = <<<TEXT
Excluding site 9lirxq5p
About to assign client aliases to site default...
No clients assigned an alias.
About to assign client aliases to site 1qwe314gn...
No clients assigned an alias.
About to assign client aliases to site a98ey4l5...
No clients assigned an alias.
About to assign client aliases to site cd90qe2s...
Client 35:19:29:f5:4b:1e already has the alias "Brenda's Note 8".
No clients assigned an alias.
TEXT;
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', false );
$test = self::get_method( 'sync_aliases' );
$this->expectOutputString( $expected );
$aliases = $test->invoke( self::$syncer );
}
public function test_excluded_site_does_not_have_aliases() {
$this->set_config( 'UNIFI_ALIAS_SYNC_EXCLUDE_SITES', [ 'default' ] );
$test = self::get_method( 'get_client_aliases_for_site' );
$aliases = $test->invokeArgs( self::$syncer, [ 'default' ] );
$this->assertEmpty( $aliases );
}
public function test_sync_aliases_with_configured_aliases() {
$this->set_config( 'UNIFI_ALIAS_SYNC_ALIASES', [ '35:19:29:f5:4b:1e' => "Brenda's Phone" ] );
// Get client aliases early just so it'll already be memoized and thus not
// appear in output.
$test = self::get_method( 'get_aliased_clients' );
$test->invoke( self::$syncer );
$expected = <<<TEXT
About to assign client aliases to site default...
Would have set alias for 9e:cc:a1:2f:0b:aa to "iPad X - Walter".
Client 35:19:29:f5:4b:1e already aliased as "Brenda's Note 8" (thus not getting aliased as "Brenda's Phone").
Clients assigned an alias: 1.
About to assign client aliases to site 1qwe314gn...
No clients assigned an alias.
About to assign client aliases to site 9lirxq5p...
Would have set alias for e4:d9:c7:cc:46:3b to "HP Inkjet Printer".
Would have set alias for 35:19:29:f5:4b:1e to "Brenda's Phone".
Client 90:04:e3:51:9d:a1 already aliased as "iPhone 8 - Adam" (thus not getting aliased as "Adam's iPhone 8").
Clients assigned an alias: 2.
About to assign client aliases to site a98ey4l5...
No clients assigned an alias.
About to assign client aliases to site cd90qe2s...
Client 35:19:29:f5:4b:1e already aliased as "Brenda's Note 8" (thus not getting aliased as "Brenda's Phone").
No clients assigned an alias.
TEXT;
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', false );
$test = self::get_method( 'sync_aliases' );
$this->expectOutputString( $expected );
$aliases = $test->invoke( self::$syncer );
}
public function test_sync_aliases_with_overwrites_allowed_and_configured_aliases() {
$this->set_config( 'UNIFI_ALIAS_SYNC_ALLOW_OVERWRITES', true );
$this->set_config( 'UNIFI_ALIAS_SYNC_ALIASES', [ '35:19:29:f5:4b:1e' => "Brenda's Phone" ] );
// Get client aliases early just so it'll already be memoized and thus not
// appear in output.
$test = self::get_method( 'get_aliased_clients' );
$test->invoke( self::$syncer );
$expected = <<<TEXT
About to assign client aliases to site default...
Would have set alias for 9e:cc:a1:2f:0b:aa to "iPad X - Walter".
Would have set alias for 35:19:29:f5:4b:1e to "Brenda's Phone" (overwriting existing alias of "Brenda's Note 8").
Clients assigned an alias: 2.
About to assign client aliases to site 1qwe314gn...
No clients assigned an alias.
About to assign client aliases to site 9lirxq5p...
Would have set alias for e4:d9:c7:cc:46:3b to "HP Inkjet Printer".
Would have set alias for 35:19:29:f5:4b:1e to "Brenda's Phone".
Would have set alias for 90:04:e3:51:9d:a1 to "Adam's iPhone 8" (overwriting existing alias of "iPhone 8 - Adam").
Clients assigned an alias: 3.
About to assign client aliases to site a98ey4l5...
No clients assigned an alias.
About to assign client aliases to site cd90qe2s...
Would have set alias for 35:19:29:f5:4b:1e to "Brenda's Phone" (overwriting existing alias of "Brenda's Note 8").
Clients assigned an alias: 1.
TEXT;
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', false );
$test = self::get_method( 'sync_aliases' );
$this->expectOutputString( $expected );
$aliases = $test->invoke( self::$syncer );
}
}