Repository navigation
Expand file tree
/
Copy pathtest-general.php
More file actions
144 lines (109 loc) · 4.58 KB
/
Copy pathtest-general.php
File metadata and controls
144 lines (109 loc) · 4.58 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
<?php
/**
* Unit tests for the UniFi Controller Client Alias Sync script.
*
* Copyright (c) 2018 by Scott Reilly (aka coffee2code)
*
* @package UniFi_Client_Alias_Sync
* @author Scott Reilly
*/
use PHPUnit\Framework\TestCase;
final class UniFiClientAliasGeneralTest extends UniFiClientAliasTestBase {
//
//
// DATA PROVIDERS
//
//
public static function values_for_get_controller_url() {
return [
[ 'https://example.com:8443', null, 'https://example.com:8443' ],
[ 'https://example.com:8443/', null, 'https://example.com:8443' ],
[ 'https://example.com:8443', 443, 'https://example.com:8443' ],
[ 'https://example.com:8443/', 443, 'https://example.com:8443' ],
[ 'https://example.com:8443', '443', 'https://example.com:8443' ],
[ 'https://example.com:8443/', '443', 'https://example.com:8443' ],
[ 'https://example.com', null, 'https://example.com:8443' ],
[ 'https://example.com/', null, 'https://example.com:8443' ],
[ 'https://example.com', 443, 'https://example.com:443' ],
[ 'https://example.com/', 443, 'https://example.com:443' ],
[ 'https://example.com', '443', 'https://example.com:443' ],
[ 'https://example.com/', '443', 'https://example.com:443' ],
[ 'example.com:8443', null, 'https://example.com:8443' ],
[ 'example.com:8443/', null, 'https://example.com:8443' ],
[ 'example.com:8443', 443, 'https://example.com:8443' ],
[ 'example.com:8443/', 443, 'https://example.com:8443' ],
[ 'example.com:8443', '443', 'https://example.com:8443' ],
[ 'example.com:8443/', '443', 'https://example.com:8443' ],
[ 'example.com', null, 'https://example.com:8443' ],
[ 'example.com/', null, 'https://example.com:8443' ],
[ 'example.com', 443, 'https://example.com:443' ],
[ 'example.com/', 443, 'https://example.com:443' ],
[ 'example.com', '443', 'https://example.com:443' ],
[ 'example.com/', '443', 'https://example.com:443' ],
];
}
public function test_is_debug_false_by_default() {
$foo = self::get_method( 'is_debug' );
$resp = $foo->invoke( self::$syncer );
$this->assertFalse( $resp );
}
public function test_is_debug_when_setting_is_true() {
$this->set_config( 'UNIFI_ALIAS_SYNC_DEBUG', true );
$foo = self::get_method( 'is_debug' );
$resp = $foo->invoke( self::$syncer );
$this->assertTrue( $resp );
}
public function test_is_testing_when_setting_is_false() {
$this->set_config( 'UNIFI_ALIAS_SYNC_TESTING', false );
$foo = self::get_method( 'is_testing' );
$resp = $foo->invoke( self::$syncer );
$this->assertFalse( $resp );
}
public function test_is_testing_when_setting_is_true() {
$this->set_config( 'UNIFI_ALIAS_SYNC_TESTING', true );
$foo = self::get_method( 'is_testing' );
$resp = $foo->invoke( self::$syncer );
$this->assertTrue( $resp );
}
public function test_status() {
$message = "This is a message.";
$test = self::get_method( 'status' );
$this->expectOutputString( $message . "\n" );
$test->invokeArgs( self::$syncer, [ $message ] );
}
public function test_disabled_status() {
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', true );
$message = "This is a message.";
$test = self::get_method( 'status' );
$this->expectOutputString( '' );
$test->invokeArgs( self::$syncer, [ $message ] );
}
public function test_bail() {
$message = "This is a test message.";
$test = self::get_method( 'bail' );
$this->expectException( Exception::class );
$this->expectExceptionMessage( $message );
$this->expectOutputString( $message . "\n" );
$clients = $test->invokeArgs( self::$syncer, [ $message ] );
}
public function test_bail_when_output_disabled() {
$message = "This is a test message.";
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', true );
$test = self::get_method( 'bail' );
$this->expectException( Exception::class );
$this->expectExceptionMessage( $message );
$this->expectOutputRegex( '/^$/' );
$clients = $test->invokeArgs( self::$syncer, [ $message ] );
$this->set_config( 'UNIFI_ALIAS_SYNC_DISABLE_STATUS', false );
}
/**
* @dataProvider values_for_get_controller_url
*/
public function test_get_controller_url( $url, $port, $expected ) {
$test = self::get_method( 'get_controller_url' );
$this->set_config( 'UNIFI_ALIAS_SYNC_CONTROLLER', $url );
$this->set_config( 'UNIFI_ALIAS_SYNC_PORT', ( $port ?? null ) );
$controller_url = $test->invoke( self::$syncer );
$this->assertEquals( $expected, $controller_url );
}
}