@@ -8,269 +8,269 @@ |
||
8 | 8 | namespace Test; |
9 | 9 | |
10 | 10 | class TemplateFunctionsTest extends \Test\TestCase { |
11 | - protected function setUp(): void { |
|
12 | - parent::setUp(); |
|
13 | - |
|
14 | - require_once \OC::$SERVERROOT . '/lib/private/Template/functions.php'; |
|
15 | - } |
|
16 | - |
|
17 | - public function testPJavaScript(): void { |
|
18 | - $this->expectOutputString('<img onload="alert(1)" />'); |
|
19 | - p('<img onload="alert(1)" />'); |
|
20 | - } |
|
21 | - |
|
22 | - public function testPJavaScriptWithScriptTags(): void { |
|
23 | - $this->expectOutputString('<script>alert('Hacked!');</script>'); |
|
24 | - p("<script>alert('Hacked!');</script>"); |
|
25 | - } |
|
26 | - |
|
27 | - public function testPNormalString(): void { |
|
28 | - $string = 'This is a good string without HTML.'; |
|
29 | - $this->expectOutputString($string); |
|
30 | - p($string); |
|
31 | - } |
|
32 | - |
|
33 | - public function testPrintUnescaped(): void { |
|
34 | - $htmlString = "<script>alert('xss');</script>"; |
|
35 | - $this->expectOutputString($htmlString); |
|
36 | - print_unescaped($htmlString); |
|
37 | - } |
|
38 | - |
|
39 | - public function testPrintUnescapedNormalString(): void { |
|
40 | - $string = 'This is a good string!'; |
|
41 | - $this->expectOutputString($string); |
|
42 | - print_unescaped($string); |
|
43 | - } |
|
44 | - |
|
45 | - public function testEmitScriptTagWithContent(): void { |
|
46 | - $this->expectOutputRegex('/<script nonce="[^"]+">\nalert\(\)\n<\/script>\n?/'); |
|
47 | - emit_script_tag('', 'alert()'); |
|
48 | - } |
|
49 | - |
|
50 | - public function testEmitScriptTagWithSource(): void { |
|
51 | - $this->expectOutputRegex('/<script nonce=".*" defer src="some.js"><\/script>/'); |
|
52 | - emit_script_tag('some.js'); |
|
53 | - } |
|
54 | - |
|
55 | - public function testEmitScriptTagWithModuleSource(): void { |
|
56 | - $this->expectOutputRegex('/<script nonce=".*" defer src="some.mjs" type="module"><\/script>/'); |
|
57 | - emit_script_tag('some.mjs', '', 'module'); |
|
58 | - } |
|
59 | - |
|
60 | - public function testEmitScriptLoadingTags(): void { |
|
61 | - // Test mjs js and inline content |
|
62 | - $pattern = '/src="some\.mjs"[^>]+type="module"[^>]*>.+\n'; // some.mjs with type = module |
|
63 | - $pattern .= '<script[^>]+src="other\.js"[^>]*>.+\n'; // other.js as plain javascript |
|
64 | - $pattern .= '<script[^>]*>\n?.*inline.*\n?<\/script>'; // inline content |
|
65 | - $pattern .= '/'; // no flags |
|
66 | - |
|
67 | - $this->expectOutputRegex($pattern); |
|
68 | - emit_script_loading_tags([ |
|
69 | - 'jsfiles' => ['some.mjs', 'other.js'], |
|
70 | - 'inline_ocjs' => '// inline' |
|
71 | - ]); |
|
72 | - } |
|
73 | - |
|
74 | - public function testEmitScriptLoadingTagsWithVersion(): void { |
|
75 | - // Test mjs js and inline content |
|
76 | - $pattern = '/src="some\.mjs\?v=ab123cd"[^>]+type="module"[^>]*>.+\n'; // some.mjs with type = module |
|
77 | - $pattern .= '<script[^>]+src="other\.js\?v=12abc34"[^>]*>.+\n'; // other.js as plain javascript |
|
78 | - $pattern .= '/'; // no flags |
|
79 | - |
|
80 | - $this->expectOutputRegex($pattern); |
|
81 | - emit_script_loading_tags([ |
|
82 | - 'jsfiles' => ['some.mjs?v=ab123cd', 'other.js?v=12abc34'], |
|
83 | - ]); |
|
84 | - } |
|
85 | - |
|
86 | - // --------------------------------------------------------------------------- |
|
87 | - // Test relative_modified_date with dates only |
|
88 | - // --------------------------------------------------------------------------- |
|
89 | - public function testRelativeDateToday(): void { |
|
90 | - $currentTime = 1380703592; |
|
91 | - $elementTime = $currentTime; |
|
92 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
93 | - |
|
94 | - $this->assertEquals('today', $result); |
|
95 | - |
|
96 | - // 2 hours ago is still today |
|
97 | - $elementTime = $currentTime - 2 * 3600; |
|
98 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
99 | - |
|
100 | - $this->assertEquals('today', $result); |
|
101 | - } |
|
102 | - |
|
103 | - public function testRelativeDateYesterday(): void { |
|
104 | - $currentTime = 1380703592; |
|
105 | - $elementTime = $currentTime - 24 * 3600; |
|
106 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
107 | - |
|
108 | - $this->assertEquals('yesterday', $result); |
|
109 | - |
|
110 | - // yesterday - 2 hours is still yesterday |
|
111 | - $elementTime = $currentTime - 26 * 3600; |
|
112 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
113 | - |
|
114 | - $this->assertEquals('yesterday', $result); |
|
115 | - } |
|
116 | - |
|
117 | - public function testRelativeDate2DaysAgo(): void { |
|
118 | - $currentTime = 1380703592; |
|
119 | - $elementTime = $currentTime - 48 * 3600; |
|
120 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
11 | + protected function setUp(): void { |
|
12 | + parent::setUp(); |
|
13 | + |
|
14 | + require_once \OC::$SERVERROOT . '/lib/private/Template/functions.php'; |
|
15 | + } |
|
16 | + |
|
17 | + public function testPJavaScript(): void { |
|
18 | + $this->expectOutputString('<img onload="alert(1)" />'); |
|
19 | + p('<img onload="alert(1)" />'); |
|
20 | + } |
|
21 | + |
|
22 | + public function testPJavaScriptWithScriptTags(): void { |
|
23 | + $this->expectOutputString('<script>alert('Hacked!');</script>'); |
|
24 | + p("<script>alert('Hacked!');</script>"); |
|
25 | + } |
|
26 | + |
|
27 | + public function testPNormalString(): void { |
|
28 | + $string = 'This is a good string without HTML.'; |
|
29 | + $this->expectOutputString($string); |
|
30 | + p($string); |
|
31 | + } |
|
32 | + |
|
33 | + public function testPrintUnescaped(): void { |
|
34 | + $htmlString = "<script>alert('xss');</script>"; |
|
35 | + $this->expectOutputString($htmlString); |
|
36 | + print_unescaped($htmlString); |
|
37 | + } |
|
38 | + |
|
39 | + public function testPrintUnescapedNormalString(): void { |
|
40 | + $string = 'This is a good string!'; |
|
41 | + $this->expectOutputString($string); |
|
42 | + print_unescaped($string); |
|
43 | + } |
|
44 | + |
|
45 | + public function testEmitScriptTagWithContent(): void { |
|
46 | + $this->expectOutputRegex('/<script nonce="[^"]+">\nalert\(\)\n<\/script>\n?/'); |
|
47 | + emit_script_tag('', 'alert()'); |
|
48 | + } |
|
49 | + |
|
50 | + public function testEmitScriptTagWithSource(): void { |
|
51 | + $this->expectOutputRegex('/<script nonce=".*" defer src="some.js"><\/script>/'); |
|
52 | + emit_script_tag('some.js'); |
|
53 | + } |
|
54 | + |
|
55 | + public function testEmitScriptTagWithModuleSource(): void { |
|
56 | + $this->expectOutputRegex('/<script nonce=".*" defer src="some.mjs" type="module"><\/script>/'); |
|
57 | + emit_script_tag('some.mjs', '', 'module'); |
|
58 | + } |
|
59 | + |
|
60 | + public function testEmitScriptLoadingTags(): void { |
|
61 | + // Test mjs js and inline content |
|
62 | + $pattern = '/src="some\.mjs"[^>]+type="module"[^>]*>.+\n'; // some.mjs with type = module |
|
63 | + $pattern .= '<script[^>]+src="other\.js"[^>]*>.+\n'; // other.js as plain javascript |
|
64 | + $pattern .= '<script[^>]*>\n?.*inline.*\n?<\/script>'; // inline content |
|
65 | + $pattern .= '/'; // no flags |
|
66 | + |
|
67 | + $this->expectOutputRegex($pattern); |
|
68 | + emit_script_loading_tags([ |
|
69 | + 'jsfiles' => ['some.mjs', 'other.js'], |
|
70 | + 'inline_ocjs' => '// inline' |
|
71 | + ]); |
|
72 | + } |
|
73 | + |
|
74 | + public function testEmitScriptLoadingTagsWithVersion(): void { |
|
75 | + // Test mjs js and inline content |
|
76 | + $pattern = '/src="some\.mjs\?v=ab123cd"[^>]+type="module"[^>]*>.+\n'; // some.mjs with type = module |
|
77 | + $pattern .= '<script[^>]+src="other\.js\?v=12abc34"[^>]*>.+\n'; // other.js as plain javascript |
|
78 | + $pattern .= '/'; // no flags |
|
79 | + |
|
80 | + $this->expectOutputRegex($pattern); |
|
81 | + emit_script_loading_tags([ |
|
82 | + 'jsfiles' => ['some.mjs?v=ab123cd', 'other.js?v=12abc34'], |
|
83 | + ]); |
|
84 | + } |
|
85 | + |
|
86 | + // --------------------------------------------------------------------------- |
|
87 | + // Test relative_modified_date with dates only |
|
88 | + // --------------------------------------------------------------------------- |
|
89 | + public function testRelativeDateToday(): void { |
|
90 | + $currentTime = 1380703592; |
|
91 | + $elementTime = $currentTime; |
|
92 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
93 | + |
|
94 | + $this->assertEquals('today', $result); |
|
95 | + |
|
96 | + // 2 hours ago is still today |
|
97 | + $elementTime = $currentTime - 2 * 3600; |
|
98 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
99 | + |
|
100 | + $this->assertEquals('today', $result); |
|
101 | + } |
|
102 | + |
|
103 | + public function testRelativeDateYesterday(): void { |
|
104 | + $currentTime = 1380703592; |
|
105 | + $elementTime = $currentTime - 24 * 3600; |
|
106 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
107 | + |
|
108 | + $this->assertEquals('yesterday', $result); |
|
109 | + |
|
110 | + // yesterday - 2 hours is still yesterday |
|
111 | + $elementTime = $currentTime - 26 * 3600; |
|
112 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
113 | + |
|
114 | + $this->assertEquals('yesterday', $result); |
|
115 | + } |
|
116 | + |
|
117 | + public function testRelativeDate2DaysAgo(): void { |
|
118 | + $currentTime = 1380703592; |
|
119 | + $elementTime = $currentTime - 48 * 3600; |
|
120 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
121 | 121 | |
122 | - $this->assertEquals('2 days ago', $result); |
|
123 | - |
|
124 | - // 2 days ago minus 4 hours is still 2 days ago |
|
125 | - $elementTime = $currentTime - 52 * 3600; |
|
126 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
127 | - |
|
128 | - $this->assertEquals('2 days ago', $result); |
|
129 | - } |
|
122 | + $this->assertEquals('2 days ago', $result); |
|
123 | + |
|
124 | + // 2 days ago minus 4 hours is still 2 days ago |
|
125 | + $elementTime = $currentTime - 52 * 3600; |
|
126 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
127 | + |
|
128 | + $this->assertEquals('2 days ago', $result); |
|
129 | + } |
|
130 | 130 | |
131 | - public function testRelativeDateLastMonth(): void { |
|
132 | - $currentTime = 1380703592; |
|
133 | - $elementTime = $currentTime - 86400 * 31; |
|
134 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
131 | + public function testRelativeDateLastMonth(): void { |
|
132 | + $currentTime = 1380703592; |
|
133 | + $elementTime = $currentTime - 86400 * 31; |
|
134 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
135 | 135 | |
136 | - $this->assertEquals('last month', $result); |
|
136 | + $this->assertEquals('last month', $result); |
|
137 | 137 | |
138 | - $elementTime = $currentTime - 86400 * 35; |
|
139 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
138 | + $elementTime = $currentTime - 86400 * 35; |
|
139 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
140 | 140 | |
141 | - $this->assertEquals('last month', $result); |
|
142 | - } |
|
141 | + $this->assertEquals('last month', $result); |
|
142 | + } |
|
143 | 143 | |
144 | - public function testRelativeDateMonthsAgo(): void { |
|
145 | - $currentTime = 1380703592; |
|
146 | - $elementTime = $currentTime - 86400 * 65; |
|
147 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
144 | + public function testRelativeDateMonthsAgo(): void { |
|
145 | + $currentTime = 1380703592; |
|
146 | + $elementTime = $currentTime - 86400 * 65; |
|
147 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
148 | 148 | |
149 | - $this->assertEquals('2 months ago', $result); |
|
149 | + $this->assertEquals('2 months ago', $result); |
|
150 | 150 | |
151 | - $elementTime = $currentTime - 86400 * 130; |
|
152 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
151 | + $elementTime = $currentTime - 86400 * 130; |
|
152 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
153 | 153 | |
154 | - $this->assertEquals('4 months ago', $result); |
|
155 | - } |
|
154 | + $this->assertEquals('4 months ago', $result); |
|
155 | + } |
|
156 | 156 | |
157 | - public function testRelativeDateLastYear(): void { |
|
158 | - $currentTime = 1380703592; |
|
159 | - $elementTime = $currentTime - 86400 * 365; |
|
160 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
157 | + public function testRelativeDateLastYear(): void { |
|
158 | + $currentTime = 1380703592; |
|
159 | + $elementTime = $currentTime - 86400 * 365; |
|
160 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
161 | 161 | |
162 | - $this->assertEquals('last year', $result); |
|
162 | + $this->assertEquals('last year', $result); |
|
163 | 163 | |
164 | - $elementTime = $currentTime - 86400 * 450; |
|
165 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
164 | + $elementTime = $currentTime - 86400 * 450; |
|
165 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
166 | 166 | |
167 | - $this->assertEquals('last year', $result); |
|
168 | - } |
|
167 | + $this->assertEquals('last year', $result); |
|
168 | + } |
|
169 | 169 | |
170 | - public function testRelativeDateYearsAgo(): void { |
|
171 | - $currentTime = 1380703592; |
|
172 | - $elementTime = $currentTime - 86400 * 365.25 * 2; |
|
173 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
170 | + public function testRelativeDateYearsAgo(): void { |
|
171 | + $currentTime = 1380703592; |
|
172 | + $elementTime = $currentTime - 86400 * 365.25 * 2; |
|
173 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
174 | 174 | |
175 | - $this->assertEquals('2 years ago', $result); |
|
175 | + $this->assertEquals('2 years ago', $result); |
|
176 | 176 | |
177 | - $elementTime = $currentTime - 86400 * 365.25 * 3; |
|
178 | - $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
177 | + $elementTime = $currentTime - 86400 * 365.25 * 3; |
|
178 | + $result = (string)relative_modified_date($elementTime, $currentTime, true); |
|
179 | 179 | |
180 | - $this->assertEquals('3 years ago', $result); |
|
181 | - } |
|
180 | + $this->assertEquals('3 years ago', $result); |
|
181 | + } |
|
182 | 182 | |
183 | - // --------------------------------------------------------------------------- |
|
184 | - // Test relative_modified_date with timestamps only (date + time value) |
|
185 | - // --------------------------------------------------------------------------- |
|
183 | + // --------------------------------------------------------------------------- |
|
184 | + // Test relative_modified_date with timestamps only (date + time value) |
|
185 | + // --------------------------------------------------------------------------- |
|
186 | 186 | |
187 | - public function testRelativeTimeSecondsAgo(): void { |
|
188 | - $currentTime = 1380703592; |
|
189 | - $elementTime = $currentTime - 5; |
|
190 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
187 | + public function testRelativeTimeSecondsAgo(): void { |
|
188 | + $currentTime = 1380703592; |
|
189 | + $elementTime = $currentTime - 5; |
|
190 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
191 | 191 | |
192 | - $this->assertEquals('seconds ago', $result); |
|
193 | - } |
|
192 | + $this->assertEquals('seconds ago', $result); |
|
193 | + } |
|
194 | 194 | |
195 | - public function testRelativeTimeMinutesAgo(): void { |
|
196 | - $currentTime = 1380703592; |
|
197 | - $elementTime = $currentTime - 190; |
|
198 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
195 | + public function testRelativeTimeMinutesAgo(): void { |
|
196 | + $currentTime = 1380703592; |
|
197 | + $elementTime = $currentTime - 190; |
|
198 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
199 | 199 | |
200 | - $this->assertEquals('3 minutes ago', $result); |
|
201 | - } |
|
200 | + $this->assertEquals('3 minutes ago', $result); |
|
201 | + } |
|
202 | 202 | |
203 | - public function testRelativeTimeHoursAgo(): void { |
|
204 | - $currentTime = 1380703592; |
|
205 | - $elementTime = $currentTime - 7500; |
|
206 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
203 | + public function testRelativeTimeHoursAgo(): void { |
|
204 | + $currentTime = 1380703592; |
|
205 | + $elementTime = $currentTime - 7500; |
|
206 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
207 | 207 | |
208 | - $this->assertEquals('2 hours ago', $result); |
|
209 | - } |
|
208 | + $this->assertEquals('2 hours ago', $result); |
|
209 | + } |
|
210 | 210 | |
211 | - public function testRelativeTime2DaysAgo(): void { |
|
212 | - $currentTime = 1380703592; |
|
213 | - $elementTime = $currentTime - 48 * 3600; |
|
214 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
211 | + public function testRelativeTime2DaysAgo(): void { |
|
212 | + $currentTime = 1380703592; |
|
213 | + $elementTime = $currentTime - 48 * 3600; |
|
214 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
215 | 215 | |
216 | - $this->assertEquals('2 days ago', $result); |
|
216 | + $this->assertEquals('2 days ago', $result); |
|
217 | 217 | |
218 | - // 2 days ago minus 4 hours is still 2 days ago |
|
219 | - $elementTime = $currentTime - 52 * 3600; |
|
220 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
218 | + // 2 days ago minus 4 hours is still 2 days ago |
|
219 | + $elementTime = $currentTime - 52 * 3600; |
|
220 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
221 | 221 | |
222 | - $this->assertEquals('2 days ago', $result); |
|
223 | - } |
|
222 | + $this->assertEquals('2 days ago', $result); |
|
223 | + } |
|
224 | 224 | |
225 | - public function testRelativeTimeLastMonth(): void { |
|
226 | - $currentTime = 1380703592; |
|
227 | - $elementTime = $currentTime - 86400 * 31; |
|
228 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
225 | + public function testRelativeTimeLastMonth(): void { |
|
226 | + $currentTime = 1380703592; |
|
227 | + $elementTime = $currentTime - 86400 * 31; |
|
228 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
229 | 229 | |
230 | - $this->assertEquals('last month', $result); |
|
230 | + $this->assertEquals('last month', $result); |
|
231 | 231 | |
232 | - $elementTime = $currentTime - 86400 * 35; |
|
233 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
232 | + $elementTime = $currentTime - 86400 * 35; |
|
233 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
234 | 234 | |
235 | - $this->assertEquals('last month', $result); |
|
236 | - } |
|
235 | + $this->assertEquals('last month', $result); |
|
236 | + } |
|
237 | 237 | |
238 | - public function testRelativeTimeMonthsAgo(): void { |
|
239 | - $currentTime = 1380703592; |
|
240 | - $elementTime = $currentTime - 86400 * 65; |
|
241 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
238 | + public function testRelativeTimeMonthsAgo(): void { |
|
239 | + $currentTime = 1380703592; |
|
240 | + $elementTime = $currentTime - 86400 * 65; |
|
241 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
242 | 242 | |
243 | - $this->assertEquals('2 months ago', $result); |
|
243 | + $this->assertEquals('2 months ago', $result); |
|
244 | 244 | |
245 | - $elementTime = $currentTime - 86400 * 130; |
|
246 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
245 | + $elementTime = $currentTime - 86400 * 130; |
|
246 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
247 | 247 | |
248 | - $this->assertEquals('4 months ago', $result); |
|
249 | - } |
|
248 | + $this->assertEquals('4 months ago', $result); |
|
249 | + } |
|
250 | 250 | |
251 | - public function testRelativeTimeLastYear(): void { |
|
252 | - $currentTime = 1380703592; |
|
253 | - $elementTime = $currentTime - 86400 * 365; |
|
254 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
251 | + public function testRelativeTimeLastYear(): void { |
|
252 | + $currentTime = 1380703592; |
|
253 | + $elementTime = $currentTime - 86400 * 365; |
|
254 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
255 | 255 | |
256 | - $this->assertEquals('last year', $result); |
|
256 | + $this->assertEquals('last year', $result); |
|
257 | 257 | |
258 | - $elementTime = $currentTime - 86400 * 450; |
|
259 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
258 | + $elementTime = $currentTime - 86400 * 450; |
|
259 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
260 | 260 | |
261 | - $this->assertEquals('last year', $result); |
|
262 | - } |
|
261 | + $this->assertEquals('last year', $result); |
|
262 | + } |
|
263 | 263 | |
264 | - public function testRelativeTimeYearsAgo(): void { |
|
265 | - $currentTime = 1380703592; |
|
266 | - $elementTime = $currentTime - 86400 * 365.25 * 2; |
|
267 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
264 | + public function testRelativeTimeYearsAgo(): void { |
|
265 | + $currentTime = 1380703592; |
|
266 | + $elementTime = $currentTime - 86400 * 365.25 * 2; |
|
267 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
268 | 268 | |
269 | - $this->assertEquals('2 years ago', $result); |
|
269 | + $this->assertEquals('2 years ago', $result); |
|
270 | 270 | |
271 | - $elementTime = $currentTime - 86400 * 365.25 * 3; |
|
272 | - $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
271 | + $elementTime = $currentTime - 86400 * 365.25 * 3; |
|
272 | + $result = (string)relative_modified_date($elementTime, $currentTime, false); |
|
273 | 273 | |
274 | - $this->assertEquals('3 years ago', $result); |
|
275 | - } |
|
274 | + $this->assertEquals('3 years ago', $result); |
|
275 | + } |
|
276 | 276 | } |
@@ -27,128 +27,128 @@ |
||
27 | 27 | use function get_class; |
28 | 28 | |
29 | 29 | class RequestManagerTest extends TestCase { |
30 | - /** @var Coordinator|MockObject */ |
|
31 | - private $coordinator; |
|
32 | - |
|
33 | - /** @var IServerContainer|MockObject */ |
|
34 | - private $container; |
|
35 | - |
|
36 | - /** @var MockObject|LoggerInterface */ |
|
37 | - private $logger; |
|
38 | - |
|
39 | - /** @var RequestManager */ |
|
40 | - private $manager; |
|
41 | - |
|
42 | - protected function setUp(): void { |
|
43 | - parent::setUp(); |
|
44 | - |
|
45 | - $this->coordinator = $this->createMock(Coordinator::class); |
|
46 | - $this->container = $this->createMock(IServerContainer::class); |
|
47 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
48 | - |
|
49 | - $this->manager = new RequestManager( |
|
50 | - $this->coordinator, |
|
51 | - $this->container, |
|
52 | - $this->logger, |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - public function testProcessAppsNotRegistered(): void { |
|
57 | - $request = $this->createMock(IRequest::class); |
|
58 | - $this->expectException(RuntimeException::class); |
|
59 | - |
|
60 | - $this->manager->process('webfinger', $request); |
|
61 | - } |
|
62 | - |
|
63 | - public function testProcessNoHandlersRegistered(): void { |
|
64 | - $request = $this->createMock(IRequest::class); |
|
65 | - $registrationContext = $this->createMock(RegistrationContext::class); |
|
66 | - $this->coordinator->expects(self::once()) |
|
67 | - ->method('getRegistrationContext') |
|
68 | - ->willReturn($registrationContext); |
|
69 | - $registrationContext->expects(self::once()) |
|
70 | - ->method('getWellKnownHandlers') |
|
71 | - ->willReturn([]); |
|
72 | - |
|
73 | - $response = $this->manager->process('webfinger', $request); |
|
74 | - |
|
75 | - self::assertNull($response); |
|
76 | - } |
|
77 | - |
|
78 | - public function testProcessHandlerNotLoadable(): void { |
|
79 | - $request = $this->createMock(IRequest::class); |
|
80 | - $registrationContext = $this->createMock(RegistrationContext::class); |
|
81 | - $this->coordinator->expects(self::once()) |
|
82 | - ->method('getRegistrationContext') |
|
83 | - ->willReturn($registrationContext); |
|
84 | - $handler = new class { |
|
85 | - }; |
|
86 | - $registrationContext->expects(self::once()) |
|
87 | - ->method('getWellKnownHandlers') |
|
88 | - ->willReturn([ |
|
89 | - new ServiceRegistration('test', get_class($handler)), |
|
90 | - ]); |
|
91 | - $this->container->expects(self::once()) |
|
92 | - ->method('get') |
|
93 | - ->with(get_class($handler)) |
|
94 | - ->willThrowException(new QueryException('')); |
|
95 | - $this->logger->expects(self::once()) |
|
96 | - ->method('error'); |
|
97 | - |
|
98 | - $response = $this->manager->process('webfinger', $request); |
|
99 | - |
|
100 | - self::assertNull($response); |
|
101 | - } |
|
102 | - |
|
103 | - public function testProcessHandlerOfWrongType(): void { |
|
104 | - $request = $this->createMock(IRequest::class); |
|
105 | - $registrationContext = $this->createMock(RegistrationContext::class); |
|
106 | - $this->coordinator->expects(self::once()) |
|
107 | - ->method('getRegistrationContext') |
|
108 | - ->willReturn($registrationContext); |
|
109 | - $handler = new class { |
|
110 | - }; |
|
111 | - $registrationContext->expects(self::once()) |
|
112 | - ->method('getWellKnownHandlers') |
|
113 | - ->willReturn([ |
|
114 | - new ServiceRegistration('test', get_class($handler)), |
|
115 | - ]); |
|
116 | - $this->container->expects(self::once()) |
|
117 | - ->method('get') |
|
118 | - ->with(get_class($handler)) |
|
119 | - ->willReturn($handler); |
|
120 | - $this->logger->expects(self::once()) |
|
121 | - ->method('error'); |
|
122 | - |
|
123 | - $response = $this->manager->process('webfinger', $request); |
|
124 | - |
|
125 | - self::assertNull($response); |
|
126 | - } |
|
127 | - |
|
128 | - public function testProcess(): void { |
|
129 | - $request = $this->createMock(IRequest::class); |
|
130 | - $registrationContext = $this->createMock(RegistrationContext::class); |
|
131 | - $this->coordinator->expects(self::once()) |
|
132 | - ->method('getRegistrationContext') |
|
133 | - ->willReturn($registrationContext); |
|
134 | - $handler = new class implements IHandler { |
|
135 | - public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { |
|
136 | - return (new JrdResponse($service))->addAlias('alias'); |
|
137 | - } |
|
138 | - }; |
|
139 | - $registrationContext->expects(self::once()) |
|
140 | - ->method('getWellKnownHandlers') |
|
141 | - ->willReturn([ |
|
142 | - new ServiceRegistration('test', get_class($handler)), |
|
143 | - ]); |
|
144 | - $this->container->expects(self::once()) |
|
145 | - ->method('get') |
|
146 | - ->with(get_class($handler)) |
|
147 | - ->willReturn($handler); |
|
148 | - |
|
149 | - $response = $this->manager->process('webfinger', $request); |
|
150 | - |
|
151 | - self::assertNotNull($response); |
|
152 | - self::assertInstanceOf(JrdResponse::class, $response); |
|
153 | - } |
|
30 | + /** @var Coordinator|MockObject */ |
|
31 | + private $coordinator; |
|
32 | + |
|
33 | + /** @var IServerContainer|MockObject */ |
|
34 | + private $container; |
|
35 | + |
|
36 | + /** @var MockObject|LoggerInterface */ |
|
37 | + private $logger; |
|
38 | + |
|
39 | + /** @var RequestManager */ |
|
40 | + private $manager; |
|
41 | + |
|
42 | + protected function setUp(): void { |
|
43 | + parent::setUp(); |
|
44 | + |
|
45 | + $this->coordinator = $this->createMock(Coordinator::class); |
|
46 | + $this->container = $this->createMock(IServerContainer::class); |
|
47 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
48 | + |
|
49 | + $this->manager = new RequestManager( |
|
50 | + $this->coordinator, |
|
51 | + $this->container, |
|
52 | + $this->logger, |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + public function testProcessAppsNotRegistered(): void { |
|
57 | + $request = $this->createMock(IRequest::class); |
|
58 | + $this->expectException(RuntimeException::class); |
|
59 | + |
|
60 | + $this->manager->process('webfinger', $request); |
|
61 | + } |
|
62 | + |
|
63 | + public function testProcessNoHandlersRegistered(): void { |
|
64 | + $request = $this->createMock(IRequest::class); |
|
65 | + $registrationContext = $this->createMock(RegistrationContext::class); |
|
66 | + $this->coordinator->expects(self::once()) |
|
67 | + ->method('getRegistrationContext') |
|
68 | + ->willReturn($registrationContext); |
|
69 | + $registrationContext->expects(self::once()) |
|
70 | + ->method('getWellKnownHandlers') |
|
71 | + ->willReturn([]); |
|
72 | + |
|
73 | + $response = $this->manager->process('webfinger', $request); |
|
74 | + |
|
75 | + self::assertNull($response); |
|
76 | + } |
|
77 | + |
|
78 | + public function testProcessHandlerNotLoadable(): void { |
|
79 | + $request = $this->createMock(IRequest::class); |
|
80 | + $registrationContext = $this->createMock(RegistrationContext::class); |
|
81 | + $this->coordinator->expects(self::once()) |
|
82 | + ->method('getRegistrationContext') |
|
83 | + ->willReturn($registrationContext); |
|
84 | + $handler = new class { |
|
85 | + }; |
|
86 | + $registrationContext->expects(self::once()) |
|
87 | + ->method('getWellKnownHandlers') |
|
88 | + ->willReturn([ |
|
89 | + new ServiceRegistration('test', get_class($handler)), |
|
90 | + ]); |
|
91 | + $this->container->expects(self::once()) |
|
92 | + ->method('get') |
|
93 | + ->with(get_class($handler)) |
|
94 | + ->willThrowException(new QueryException('')); |
|
95 | + $this->logger->expects(self::once()) |
|
96 | + ->method('error'); |
|
97 | + |
|
98 | + $response = $this->manager->process('webfinger', $request); |
|
99 | + |
|
100 | + self::assertNull($response); |
|
101 | + } |
|
102 | + |
|
103 | + public function testProcessHandlerOfWrongType(): void { |
|
104 | + $request = $this->createMock(IRequest::class); |
|
105 | + $registrationContext = $this->createMock(RegistrationContext::class); |
|
106 | + $this->coordinator->expects(self::once()) |
|
107 | + ->method('getRegistrationContext') |
|
108 | + ->willReturn($registrationContext); |
|
109 | + $handler = new class { |
|
110 | + }; |
|
111 | + $registrationContext->expects(self::once()) |
|
112 | + ->method('getWellKnownHandlers') |
|
113 | + ->willReturn([ |
|
114 | + new ServiceRegistration('test', get_class($handler)), |
|
115 | + ]); |
|
116 | + $this->container->expects(self::once()) |
|
117 | + ->method('get') |
|
118 | + ->with(get_class($handler)) |
|
119 | + ->willReturn($handler); |
|
120 | + $this->logger->expects(self::once()) |
|
121 | + ->method('error'); |
|
122 | + |
|
123 | + $response = $this->manager->process('webfinger', $request); |
|
124 | + |
|
125 | + self::assertNull($response); |
|
126 | + } |
|
127 | + |
|
128 | + public function testProcess(): void { |
|
129 | + $request = $this->createMock(IRequest::class); |
|
130 | + $registrationContext = $this->createMock(RegistrationContext::class); |
|
131 | + $this->coordinator->expects(self::once()) |
|
132 | + ->method('getRegistrationContext') |
|
133 | + ->willReturn($registrationContext); |
|
134 | + $handler = new class implements IHandler { |
|
135 | + public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { |
|
136 | + return (new JrdResponse($service))->addAlias('alias'); |
|
137 | + } |
|
138 | + }; |
|
139 | + $registrationContext->expects(self::once()) |
|
140 | + ->method('getWellKnownHandlers') |
|
141 | + ->willReturn([ |
|
142 | + new ServiceRegistration('test', get_class($handler)), |
|
143 | + ]); |
|
144 | + $this->container->expects(self::once()) |
|
145 | + ->method('get') |
|
146 | + ->with(get_class($handler)) |
|
147 | + ->willReturn($handler); |
|
148 | + |
|
149 | + $response = $this->manager->process('webfinger', $request); |
|
150 | + |
|
151 | + self::assertNotNull($response); |
|
152 | + self::assertInstanceOf(JrdResponse::class, $response); |
|
153 | + } |
|
154 | 154 | } |
@@ -14,79 +14,79 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class JrdResponseTest extends TestCase { |
17 | - public function testEmptyToHttpResponse(): void { |
|
18 | - $response = new JrdResponse('subject'); |
|
19 | - $httpResponse = $response->toHttpResponse(); |
|
17 | + public function testEmptyToHttpResponse(): void { |
|
18 | + $response = new JrdResponse('subject'); |
|
19 | + $httpResponse = $response->toHttpResponse(); |
|
20 | 20 | |
21 | - self::assertTrue($response->isEmpty()); |
|
22 | - self::assertInstanceOf(JSONResponse::class, $httpResponse); |
|
23 | - /** @var JSONResponse $httpResponse */ |
|
24 | - self::assertEquals( |
|
25 | - [ |
|
26 | - 'subject' => 'subject', |
|
27 | - ], |
|
28 | - $httpResponse->getData() |
|
29 | - ); |
|
30 | - } |
|
21 | + self::assertTrue($response->isEmpty()); |
|
22 | + self::assertInstanceOf(JSONResponse::class, $httpResponse); |
|
23 | + /** @var JSONResponse $httpResponse */ |
|
24 | + self::assertEquals( |
|
25 | + [ |
|
26 | + 'subject' => 'subject', |
|
27 | + ], |
|
28 | + $httpResponse->getData() |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | |
32 | - public function testComplexToHttpResponse(): void { |
|
33 | - $response = new JrdResponse('subject'); |
|
34 | - $response->addAlias('alias'); |
|
35 | - $response->addAlias('blias'); |
|
36 | - $response->addProperty('propa', 'a'); |
|
37 | - $response->addProperty('propb', null); |
|
38 | - $response->setExpires('tomorrow'); |
|
39 | - $response->addLink('rel', null, null); |
|
40 | - $response->addLink('rel', 'type', null); |
|
41 | - $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue']); |
|
42 | - $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue'], ['propx' => 'valx']); |
|
43 | - $httpResponse = $response->toHttpResponse(); |
|
32 | + public function testComplexToHttpResponse(): void { |
|
33 | + $response = new JrdResponse('subject'); |
|
34 | + $response->addAlias('alias'); |
|
35 | + $response->addAlias('blias'); |
|
36 | + $response->addProperty('propa', 'a'); |
|
37 | + $response->addProperty('propb', null); |
|
38 | + $response->setExpires('tomorrow'); |
|
39 | + $response->addLink('rel', null, null); |
|
40 | + $response->addLink('rel', 'type', null); |
|
41 | + $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue']); |
|
42 | + $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue'], ['propx' => 'valx']); |
|
43 | + $httpResponse = $response->toHttpResponse(); |
|
44 | 44 | |
45 | - self::assertFalse($response->isEmpty()); |
|
46 | - self::assertInstanceOf(JSONResponse::class, $httpResponse); |
|
47 | - /** @var JSONResponse $httpResponse */ |
|
48 | - self::assertEquals( |
|
49 | - [ |
|
50 | - 'subject' => 'subject', |
|
51 | - 'aliases' => [ |
|
52 | - 'alias', |
|
53 | - 'blias', |
|
54 | - ], |
|
55 | - 'properties' => [ |
|
56 | - 'propa' => 'a', |
|
57 | - 'propb' => null, |
|
58 | - ], |
|
59 | - 'expires' => 'tomorrow', |
|
60 | - 'links' => [ |
|
61 | - [ |
|
62 | - 'rel' => 'rel', |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'rel' => 'rel', |
|
66 | - 'type' => 'type', |
|
67 | - ], |
|
68 | - [ |
|
69 | - 'rel' => 'rel', |
|
70 | - 'type' => 'type', |
|
71 | - 'href' => 'href', |
|
72 | - 'titles' => [ |
|
73 | - 'title' => 'titlevalue', |
|
74 | - ], |
|
75 | - ], |
|
76 | - [ |
|
77 | - 'rel' => 'rel', |
|
78 | - 'type' => 'type', |
|
79 | - 'href' => 'href', |
|
80 | - 'titles' => [ |
|
81 | - 'title' => 'titlevalue', |
|
82 | - ], |
|
83 | - 'properties' => [ |
|
84 | - 'propx' => 'valx', |
|
85 | - ], |
|
86 | - ], |
|
87 | - ] |
|
88 | - ], |
|
89 | - $httpResponse->getData() |
|
90 | - ); |
|
91 | - } |
|
45 | + self::assertFalse($response->isEmpty()); |
|
46 | + self::assertInstanceOf(JSONResponse::class, $httpResponse); |
|
47 | + /** @var JSONResponse $httpResponse */ |
|
48 | + self::assertEquals( |
|
49 | + [ |
|
50 | + 'subject' => 'subject', |
|
51 | + 'aliases' => [ |
|
52 | + 'alias', |
|
53 | + 'blias', |
|
54 | + ], |
|
55 | + 'properties' => [ |
|
56 | + 'propa' => 'a', |
|
57 | + 'propb' => null, |
|
58 | + ], |
|
59 | + 'expires' => 'tomorrow', |
|
60 | + 'links' => [ |
|
61 | + [ |
|
62 | + 'rel' => 'rel', |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'rel' => 'rel', |
|
66 | + 'type' => 'type', |
|
67 | + ], |
|
68 | + [ |
|
69 | + 'rel' => 'rel', |
|
70 | + 'type' => 'type', |
|
71 | + 'href' => 'href', |
|
72 | + 'titles' => [ |
|
73 | + 'title' => 'titlevalue', |
|
74 | + ], |
|
75 | + ], |
|
76 | + [ |
|
77 | + 'rel' => 'rel', |
|
78 | + 'type' => 'type', |
|
79 | + 'href' => 'href', |
|
80 | + 'titles' => [ |
|
81 | + 'title' => 'titlevalue', |
|
82 | + ], |
|
83 | + 'properties' => [ |
|
84 | + 'propx' => 'valx', |
|
85 | + ], |
|
86 | + ], |
|
87 | + ] |
|
88 | + ], |
|
89 | + $httpResponse->getData() |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | } |
@@ -14,11 +14,11 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class GenericResponseTest extends TestCase { |
17 | - public function testToHttpResponse(): void { |
|
18 | - $httpResponse = $this->createMock(JSONResponse::class); |
|
17 | + public function testToHttpResponse(): void { |
|
18 | + $httpResponse = $this->createMock(JSONResponse::class); |
|
19 | 19 | |
20 | - $response = new GenericResponse($httpResponse); |
|
20 | + $response = new GenericResponse($httpResponse); |
|
21 | 21 | |
22 | - self::assertSame($httpResponse, $response->toHttpResponse()); |
|
23 | - } |
|
22 | + self::assertSame($httpResponse, $response->toHttpResponse()); |
|
23 | + } |
|
24 | 24 | } |
@@ -15,44 +15,44 @@ |
||
15 | 15 | * Class ResponseTest |
16 | 16 | */ |
17 | 17 | class ResponseTest extends \Test\TestCase { |
18 | - /** @var GuzzleResponse */ |
|
19 | - private $guzzleResponse; |
|
20 | - |
|
21 | - protected function setUp(): void { |
|
22 | - parent::setUp(); |
|
23 | - $this->guzzleResponse = new GuzzleResponse(418); |
|
24 | - } |
|
25 | - |
|
26 | - public function testGetBody(): void { |
|
27 | - $response = new Response($this->guzzleResponse->withBody(Utils::streamFor('MyResponse'))); |
|
28 | - $this->assertSame('MyResponse', $response->getBody()); |
|
29 | - } |
|
30 | - |
|
31 | - public function testGetStatusCode(): void { |
|
32 | - $response = new Response($this->guzzleResponse); |
|
33 | - $this->assertSame(418, $response->getStatusCode()); |
|
34 | - } |
|
35 | - |
|
36 | - public function testGetHeader(): void { |
|
37 | - $response = new Response($this->guzzleResponse->withHeader('bar', 'foo')); |
|
38 | - $this->assertSame('foo', $response->getHeader('bar')); |
|
39 | - } |
|
40 | - |
|
41 | - public function testGetHeaders(): void { |
|
42 | - $response = new Response($this->guzzleResponse |
|
43 | - ->withHeader('bar', 'foo') |
|
44 | - ->withHeader('x-awesome', 'yes') |
|
45 | - ); |
|
46 | - |
|
47 | - $expected = [ |
|
48 | - 'bar' => [ |
|
49 | - 0 => 'foo', |
|
50 | - ], |
|
51 | - 'x-awesome' => [ |
|
52 | - 0 => 'yes', |
|
53 | - ], |
|
54 | - ]; |
|
55 | - $this->assertSame($expected, $response->getHeaders()); |
|
56 | - $this->assertSame('yes', $response->getHeader('x-awesome')); |
|
57 | - } |
|
18 | + /** @var GuzzleResponse */ |
|
19 | + private $guzzleResponse; |
|
20 | + |
|
21 | + protected function setUp(): void { |
|
22 | + parent::setUp(); |
|
23 | + $this->guzzleResponse = new GuzzleResponse(418); |
|
24 | + } |
|
25 | + |
|
26 | + public function testGetBody(): void { |
|
27 | + $response = new Response($this->guzzleResponse->withBody(Utils::streamFor('MyResponse'))); |
|
28 | + $this->assertSame('MyResponse', $response->getBody()); |
|
29 | + } |
|
30 | + |
|
31 | + public function testGetStatusCode(): void { |
|
32 | + $response = new Response($this->guzzleResponse); |
|
33 | + $this->assertSame(418, $response->getStatusCode()); |
|
34 | + } |
|
35 | + |
|
36 | + public function testGetHeader(): void { |
|
37 | + $response = new Response($this->guzzleResponse->withHeader('bar', 'foo')); |
|
38 | + $this->assertSame('foo', $response->getHeader('bar')); |
|
39 | + } |
|
40 | + |
|
41 | + public function testGetHeaders(): void { |
|
42 | + $response = new Response($this->guzzleResponse |
|
43 | + ->withHeader('bar', 'foo') |
|
44 | + ->withHeader('x-awesome', 'yes') |
|
45 | + ); |
|
46 | + |
|
47 | + $expected = [ |
|
48 | + 'bar' => [ |
|
49 | + 0 => 'foo', |
|
50 | + ], |
|
51 | + 'x-awesome' => [ |
|
52 | + 0 => 'yes', |
|
53 | + ], |
|
54 | + ]; |
|
55 | + $this->assertSame($expected, $response->getHeaders()); |
|
56 | + $this->assertSame('yes', $response->getHeader('x-awesome')); |
|
57 | + } |
|
58 | 58 | } |
@@ -20,101 +20,101 @@ |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class ProviderLoaderTest extends TestCase { |
23 | - /** @var IAppManager|MockObject */ |
|
24 | - private $appManager; |
|
25 | - |
|
26 | - /** @var IUser|MockObject */ |
|
27 | - private $user; |
|
28 | - |
|
29 | - /** @var RegistrationContext|MockObject */ |
|
30 | - private $registrationContext; |
|
31 | - |
|
32 | - /** @var ProviderLoader */ |
|
33 | - private $loader; |
|
34 | - |
|
35 | - protected function setUp(): void { |
|
36 | - parent::setUp(); |
|
37 | - |
|
38 | - $this->appManager = $this->createMock(IAppManager::class); |
|
39 | - $this->user = $this->createMock(IUser::class); |
|
40 | - |
|
41 | - $this->registrationContext = $this->createMock(RegistrationContext::class); |
|
42 | - $coordinator = $this->createMock(Coordinator::class); |
|
43 | - $coordinator->method('getRegistrationContext') |
|
44 | - ->willReturn($this->registrationContext); |
|
45 | - |
|
46 | - $this->loader = new ProviderLoader($this->appManager, $coordinator); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - public function testFailHardIfProviderCanNotBeLoaded(): void { |
|
51 | - $this->expectException(\Exception::class); |
|
52 | - $this->expectExceptionMessage('Could not load two-factor auth provider \\OCA\\MyFaulty2faApp\\DoesNotExist'); |
|
53 | - |
|
54 | - $this->appManager->expects($this->once()) |
|
55 | - ->method('getEnabledAppsForUser') |
|
56 | - ->with($this->user) |
|
57 | - ->willReturn(['mail', 'twofactor_totp']); |
|
58 | - $this->appManager |
|
59 | - ->method('getAppInfo') |
|
60 | - ->willReturnMap([ |
|
61 | - ['mail', false, null, []], |
|
62 | - ['twofactor_totp', false, null, [ |
|
63 | - 'two-factor-providers' => [ |
|
64 | - '\\OCA\\MyFaulty2faApp\\DoesNotExist', |
|
65 | - ], |
|
66 | - ]], |
|
67 | - ]); |
|
68 | - |
|
69 | - $this->loader->getProviders($this->user); |
|
70 | - } |
|
71 | - |
|
72 | - public function testGetProviders(): void { |
|
73 | - $provider = $this->createMock(IProvider::class); |
|
74 | - $provider->method('getId')->willReturn('test'); |
|
75 | - \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) { |
|
76 | - return $provider; |
|
77 | - }); |
|
78 | - $this->appManager->expects($this->once()) |
|
79 | - ->method('getEnabledAppsForUser') |
|
80 | - ->with($this->user) |
|
81 | - ->willReturn(['twofactor_test']); |
|
82 | - $this->appManager |
|
83 | - ->method('getAppInfo') |
|
84 | - ->with('twofactor_test') |
|
85 | - ->willReturn(['two-factor-providers' => [ |
|
86 | - '\\OCA\\TwoFactorTest\\Provider', |
|
87 | - ]]); |
|
88 | - |
|
89 | - $providers = $this->loader->getProviders($this->user); |
|
90 | - |
|
91 | - $this->assertCount(1, $providers); |
|
92 | - $this->assertArrayHasKey('test', $providers); |
|
93 | - $this->assertSame($provider, $providers['test']); |
|
94 | - } |
|
95 | - |
|
96 | - public function testGetProvidersBootstrap(): void { |
|
97 | - $provider = $this->createMock(IProvider::class); |
|
98 | - $provider->method('getId')->willReturn('test'); |
|
99 | - |
|
100 | - \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) { |
|
101 | - return $provider; |
|
102 | - }); |
|
103 | - |
|
104 | - $this->appManager->expects($this->once()) |
|
105 | - ->method('getEnabledAppsForUser') |
|
106 | - ->with($this->user) |
|
107 | - ->willReturn([]); |
|
108 | - |
|
109 | - $this->registrationContext->method('getTwoFactorProviders') |
|
110 | - ->willReturn([ |
|
111 | - new ServiceRegistration('twofactor_test', '\\OCA\\TwoFactorTest\\Provider') |
|
112 | - ]); |
|
113 | - |
|
114 | - $providers = $this->loader->getProviders($this->user); |
|
115 | - |
|
116 | - $this->assertCount(1, $providers); |
|
117 | - $this->assertArrayHasKey('test', $providers); |
|
118 | - $this->assertSame($provider, $providers['test']); |
|
119 | - } |
|
23 | + /** @var IAppManager|MockObject */ |
|
24 | + private $appManager; |
|
25 | + |
|
26 | + /** @var IUser|MockObject */ |
|
27 | + private $user; |
|
28 | + |
|
29 | + /** @var RegistrationContext|MockObject */ |
|
30 | + private $registrationContext; |
|
31 | + |
|
32 | + /** @var ProviderLoader */ |
|
33 | + private $loader; |
|
34 | + |
|
35 | + protected function setUp(): void { |
|
36 | + parent::setUp(); |
|
37 | + |
|
38 | + $this->appManager = $this->createMock(IAppManager::class); |
|
39 | + $this->user = $this->createMock(IUser::class); |
|
40 | + |
|
41 | + $this->registrationContext = $this->createMock(RegistrationContext::class); |
|
42 | + $coordinator = $this->createMock(Coordinator::class); |
|
43 | + $coordinator->method('getRegistrationContext') |
|
44 | + ->willReturn($this->registrationContext); |
|
45 | + |
|
46 | + $this->loader = new ProviderLoader($this->appManager, $coordinator); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + public function testFailHardIfProviderCanNotBeLoaded(): void { |
|
51 | + $this->expectException(\Exception::class); |
|
52 | + $this->expectExceptionMessage('Could not load two-factor auth provider \\OCA\\MyFaulty2faApp\\DoesNotExist'); |
|
53 | + |
|
54 | + $this->appManager->expects($this->once()) |
|
55 | + ->method('getEnabledAppsForUser') |
|
56 | + ->with($this->user) |
|
57 | + ->willReturn(['mail', 'twofactor_totp']); |
|
58 | + $this->appManager |
|
59 | + ->method('getAppInfo') |
|
60 | + ->willReturnMap([ |
|
61 | + ['mail', false, null, []], |
|
62 | + ['twofactor_totp', false, null, [ |
|
63 | + 'two-factor-providers' => [ |
|
64 | + '\\OCA\\MyFaulty2faApp\\DoesNotExist', |
|
65 | + ], |
|
66 | + ]], |
|
67 | + ]); |
|
68 | + |
|
69 | + $this->loader->getProviders($this->user); |
|
70 | + } |
|
71 | + |
|
72 | + public function testGetProviders(): void { |
|
73 | + $provider = $this->createMock(IProvider::class); |
|
74 | + $provider->method('getId')->willReturn('test'); |
|
75 | + \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) { |
|
76 | + return $provider; |
|
77 | + }); |
|
78 | + $this->appManager->expects($this->once()) |
|
79 | + ->method('getEnabledAppsForUser') |
|
80 | + ->with($this->user) |
|
81 | + ->willReturn(['twofactor_test']); |
|
82 | + $this->appManager |
|
83 | + ->method('getAppInfo') |
|
84 | + ->with('twofactor_test') |
|
85 | + ->willReturn(['two-factor-providers' => [ |
|
86 | + '\\OCA\\TwoFactorTest\\Provider', |
|
87 | + ]]); |
|
88 | + |
|
89 | + $providers = $this->loader->getProviders($this->user); |
|
90 | + |
|
91 | + $this->assertCount(1, $providers); |
|
92 | + $this->assertArrayHasKey('test', $providers); |
|
93 | + $this->assertSame($provider, $providers['test']); |
|
94 | + } |
|
95 | + |
|
96 | + public function testGetProvidersBootstrap(): void { |
|
97 | + $provider = $this->createMock(IProvider::class); |
|
98 | + $provider->method('getId')->willReturn('test'); |
|
99 | + |
|
100 | + \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) { |
|
101 | + return $provider; |
|
102 | + }); |
|
103 | + |
|
104 | + $this->appManager->expects($this->once()) |
|
105 | + ->method('getEnabledAppsForUser') |
|
106 | + ->with($this->user) |
|
107 | + ->willReturn([]); |
|
108 | + |
|
109 | + $this->registrationContext->method('getTwoFactorProviders') |
|
110 | + ->willReturn([ |
|
111 | + new ServiceRegistration('twofactor_test', '\\OCA\\TwoFactorTest\\Provider') |
|
112 | + ]); |
|
113 | + |
|
114 | + $providers = $this->loader->getProviders($this->user); |
|
115 | + |
|
116 | + $this->assertCount(1, $providers); |
|
117 | + $this->assertArrayHasKey('test', $providers); |
|
118 | + $this->assertSame($provider, $providers['test']); |
|
119 | + } |
|
120 | 120 | } |
@@ -18,162 +18,162 @@ |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class MandatoryTwoFactorTest extends TestCase { |
21 | - /** @var IConfig|MockObject */ |
|
22 | - private $config; |
|
23 | - |
|
24 | - /** @var IGroupManager|MockObject */ |
|
25 | - private $groupManager; |
|
26 | - |
|
27 | - /** @var MandatoryTwoFactor */ |
|
28 | - private $mandatoryTwoFactor; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->config = $this->createMock(IConfig::class); |
|
34 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
35 | - |
|
36 | - $this->mandatoryTwoFactor = new MandatoryTwoFactor($this->config, $this->groupManager); |
|
37 | - } |
|
38 | - |
|
39 | - public function testIsNotEnforced(): void { |
|
40 | - $this->config |
|
41 | - ->method('getSystemValue') |
|
42 | - ->willReturnMap([ |
|
43 | - ['twofactor_enforced', 'false', 'false'], |
|
44 | - ['twofactor_enforced_groups', [], []], |
|
45 | - ['twofactor_enforced_excluded_groups', [], []], |
|
46 | - ]); |
|
47 | - |
|
48 | - $state = $this->mandatoryTwoFactor->getState(); |
|
49 | - |
|
50 | - $this->assertFalse($state->isEnforced()); |
|
51 | - } |
|
52 | - |
|
53 | - public function testIsEnforced(): void { |
|
54 | - $this->config |
|
55 | - ->method('getSystemValue') |
|
56 | - ->willReturnMap([ |
|
57 | - ['twofactor_enforced', 'false', 'true'], |
|
58 | - ['twofactor_enforced_groups', [], []], |
|
59 | - ['twofactor_enforced_excluded_groups', [], []], |
|
60 | - ]); |
|
61 | - |
|
62 | - $state = $this->mandatoryTwoFactor->getState(); |
|
63 | - |
|
64 | - $this->assertTrue($state->isEnforced()); |
|
65 | - } |
|
66 | - |
|
67 | - public function testIsNotEnforcedForAnybody(): void { |
|
68 | - $user = $this->createMock(IUser::class); |
|
69 | - $user->method('getUID')->willReturn('user123'); |
|
70 | - $this->config |
|
71 | - ->method('getSystemValue') |
|
72 | - ->willReturnMap([ |
|
73 | - ['twofactor_enforced', 'false', 'false'], |
|
74 | - ['twofactor_enforced_groups', [], []], |
|
75 | - ['twofactor_enforced_excluded_groups', [], []], |
|
76 | - ]); |
|
77 | - |
|
78 | - $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
79 | - |
|
80 | - $this->assertFalse($isEnforced); |
|
81 | - } |
|
82 | - |
|
83 | - public function testIsEnforcedForAGroupMember(): void { |
|
84 | - $user = $this->createMock(IUser::class); |
|
85 | - $user->method('getUID')->willReturn('user123'); |
|
86 | - $this->config |
|
87 | - ->method('getSystemValue') |
|
88 | - ->willReturnMap([ |
|
89 | - ['twofactor_enforced', 'false', 'true'], |
|
90 | - ['twofactor_enforced_groups', [], ['twofactorers']], |
|
91 | - ['twofactor_enforced_excluded_groups', [], []], |
|
92 | - ]); |
|
93 | - $this->groupManager->method('isInGroup') |
|
94 | - ->willReturnCallback(function ($user, $group) { |
|
95 | - return $user === 'user123' && $group === 'twofactorers'; |
|
96 | - }); |
|
97 | - |
|
98 | - $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
99 | - |
|
100 | - $this->assertTrue($isEnforced); |
|
101 | - } |
|
102 | - |
|
103 | - public function testIsEnforcedForOtherGroups(): void { |
|
104 | - $user = $this->createMock(IUser::class); |
|
105 | - $user->method('getUID')->willReturn('user123'); |
|
106 | - $this->config |
|
107 | - ->method('getSystemValue') |
|
108 | - ->willReturnMap([ |
|
109 | - ['twofactor_enforced', 'false', 'true'], |
|
110 | - ['twofactor_enforced_groups', [], ['twofactorers']], |
|
111 | - ['twofactor_enforced_excluded_groups', [], []], |
|
112 | - ]); |
|
113 | - $this->groupManager->method('isInGroup') |
|
114 | - ->willReturn(false); |
|
115 | - |
|
116 | - $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
117 | - |
|
118 | - $this->assertFalse($isEnforced); |
|
119 | - } |
|
120 | - |
|
121 | - public function testIsEnforcedButMemberOfExcludedGroup(): void { |
|
122 | - $user = $this->createMock(IUser::class); |
|
123 | - $user->method('getUID')->willReturn('user123'); |
|
124 | - $this->config |
|
125 | - ->method('getSystemValue') |
|
126 | - ->willReturnMap([ |
|
127 | - ['twofactor_enforced', 'false', 'true'], |
|
128 | - ['twofactor_enforced_groups', [], []], |
|
129 | - ['twofactor_enforced_excluded_groups', [], ['yoloers']], |
|
130 | - ]); |
|
131 | - $this->groupManager->method('isInGroup') |
|
132 | - ->willReturnCallback(function ($user, $group) { |
|
133 | - return $user === 'user123' && $group === 'yoloers'; |
|
134 | - }); |
|
135 | - |
|
136 | - $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
137 | - |
|
138 | - $this->assertFalse($isEnforced); |
|
139 | - } |
|
140 | - |
|
141 | - public function testSetEnforced(): void { |
|
142 | - $this->config |
|
143 | - ->expects($this->exactly(3)) |
|
144 | - ->method('setSystemValue') |
|
145 | - ->willReturnMap([ |
|
146 | - ['twofactor_enforced', 'true'], |
|
147 | - ['twofactor_enforced_groups', []], |
|
148 | - ['twofactor_enforced_excluded_groups', []], |
|
149 | - ]); |
|
150 | - |
|
151 | - $this->mandatoryTwoFactor->setState(new EnforcementState(true)); |
|
152 | - } |
|
153 | - |
|
154 | - public function testSetEnforcedForGroups(): void { |
|
155 | - $this->config |
|
156 | - ->expects($this->exactly(3)) |
|
157 | - ->method('setSystemValue') |
|
158 | - ->willReturnMap([ |
|
159 | - ['twofactor_enforced', 'true'], |
|
160 | - ['twofactor_enforced_groups', ['twofactorers']], |
|
161 | - ['twofactor_enforced_excluded_groups', ['yoloers']], |
|
162 | - ]); |
|
163 | - |
|
164 | - $this->mandatoryTwoFactor->setState(new EnforcementState(true, ['twofactorers'], ['yoloers'])); |
|
165 | - } |
|
166 | - |
|
167 | - public function testSetNotEnforced(): void { |
|
168 | - $this->config |
|
169 | - ->expects($this->exactly(3)) |
|
170 | - ->method('setSystemValue') |
|
171 | - ->willReturnMap([ |
|
172 | - ['twofactor_enforced', 'false'], |
|
173 | - ['twofactor_enforced_groups', []], |
|
174 | - ['twofactor_enforced_excluded_groups', []], |
|
175 | - ]); |
|
176 | - |
|
177 | - $this->mandatoryTwoFactor->setState(new EnforcementState(false)); |
|
178 | - } |
|
21 | + /** @var IConfig|MockObject */ |
|
22 | + private $config; |
|
23 | + |
|
24 | + /** @var IGroupManager|MockObject */ |
|
25 | + private $groupManager; |
|
26 | + |
|
27 | + /** @var MandatoryTwoFactor */ |
|
28 | + private $mandatoryTwoFactor; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->config = $this->createMock(IConfig::class); |
|
34 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
35 | + |
|
36 | + $this->mandatoryTwoFactor = new MandatoryTwoFactor($this->config, $this->groupManager); |
|
37 | + } |
|
38 | + |
|
39 | + public function testIsNotEnforced(): void { |
|
40 | + $this->config |
|
41 | + ->method('getSystemValue') |
|
42 | + ->willReturnMap([ |
|
43 | + ['twofactor_enforced', 'false', 'false'], |
|
44 | + ['twofactor_enforced_groups', [], []], |
|
45 | + ['twofactor_enforced_excluded_groups', [], []], |
|
46 | + ]); |
|
47 | + |
|
48 | + $state = $this->mandatoryTwoFactor->getState(); |
|
49 | + |
|
50 | + $this->assertFalse($state->isEnforced()); |
|
51 | + } |
|
52 | + |
|
53 | + public function testIsEnforced(): void { |
|
54 | + $this->config |
|
55 | + ->method('getSystemValue') |
|
56 | + ->willReturnMap([ |
|
57 | + ['twofactor_enforced', 'false', 'true'], |
|
58 | + ['twofactor_enforced_groups', [], []], |
|
59 | + ['twofactor_enforced_excluded_groups', [], []], |
|
60 | + ]); |
|
61 | + |
|
62 | + $state = $this->mandatoryTwoFactor->getState(); |
|
63 | + |
|
64 | + $this->assertTrue($state->isEnforced()); |
|
65 | + } |
|
66 | + |
|
67 | + public function testIsNotEnforcedForAnybody(): void { |
|
68 | + $user = $this->createMock(IUser::class); |
|
69 | + $user->method('getUID')->willReturn('user123'); |
|
70 | + $this->config |
|
71 | + ->method('getSystemValue') |
|
72 | + ->willReturnMap([ |
|
73 | + ['twofactor_enforced', 'false', 'false'], |
|
74 | + ['twofactor_enforced_groups', [], []], |
|
75 | + ['twofactor_enforced_excluded_groups', [], []], |
|
76 | + ]); |
|
77 | + |
|
78 | + $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
79 | + |
|
80 | + $this->assertFalse($isEnforced); |
|
81 | + } |
|
82 | + |
|
83 | + public function testIsEnforcedForAGroupMember(): void { |
|
84 | + $user = $this->createMock(IUser::class); |
|
85 | + $user->method('getUID')->willReturn('user123'); |
|
86 | + $this->config |
|
87 | + ->method('getSystemValue') |
|
88 | + ->willReturnMap([ |
|
89 | + ['twofactor_enforced', 'false', 'true'], |
|
90 | + ['twofactor_enforced_groups', [], ['twofactorers']], |
|
91 | + ['twofactor_enforced_excluded_groups', [], []], |
|
92 | + ]); |
|
93 | + $this->groupManager->method('isInGroup') |
|
94 | + ->willReturnCallback(function ($user, $group) { |
|
95 | + return $user === 'user123' && $group === 'twofactorers'; |
|
96 | + }); |
|
97 | + |
|
98 | + $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
99 | + |
|
100 | + $this->assertTrue($isEnforced); |
|
101 | + } |
|
102 | + |
|
103 | + public function testIsEnforcedForOtherGroups(): void { |
|
104 | + $user = $this->createMock(IUser::class); |
|
105 | + $user->method('getUID')->willReturn('user123'); |
|
106 | + $this->config |
|
107 | + ->method('getSystemValue') |
|
108 | + ->willReturnMap([ |
|
109 | + ['twofactor_enforced', 'false', 'true'], |
|
110 | + ['twofactor_enforced_groups', [], ['twofactorers']], |
|
111 | + ['twofactor_enforced_excluded_groups', [], []], |
|
112 | + ]); |
|
113 | + $this->groupManager->method('isInGroup') |
|
114 | + ->willReturn(false); |
|
115 | + |
|
116 | + $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
117 | + |
|
118 | + $this->assertFalse($isEnforced); |
|
119 | + } |
|
120 | + |
|
121 | + public function testIsEnforcedButMemberOfExcludedGroup(): void { |
|
122 | + $user = $this->createMock(IUser::class); |
|
123 | + $user->method('getUID')->willReturn('user123'); |
|
124 | + $this->config |
|
125 | + ->method('getSystemValue') |
|
126 | + ->willReturnMap([ |
|
127 | + ['twofactor_enforced', 'false', 'true'], |
|
128 | + ['twofactor_enforced_groups', [], []], |
|
129 | + ['twofactor_enforced_excluded_groups', [], ['yoloers']], |
|
130 | + ]); |
|
131 | + $this->groupManager->method('isInGroup') |
|
132 | + ->willReturnCallback(function ($user, $group) { |
|
133 | + return $user === 'user123' && $group === 'yoloers'; |
|
134 | + }); |
|
135 | + |
|
136 | + $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user); |
|
137 | + |
|
138 | + $this->assertFalse($isEnforced); |
|
139 | + } |
|
140 | + |
|
141 | + public function testSetEnforced(): void { |
|
142 | + $this->config |
|
143 | + ->expects($this->exactly(3)) |
|
144 | + ->method('setSystemValue') |
|
145 | + ->willReturnMap([ |
|
146 | + ['twofactor_enforced', 'true'], |
|
147 | + ['twofactor_enforced_groups', []], |
|
148 | + ['twofactor_enforced_excluded_groups', []], |
|
149 | + ]); |
|
150 | + |
|
151 | + $this->mandatoryTwoFactor->setState(new EnforcementState(true)); |
|
152 | + } |
|
153 | + |
|
154 | + public function testSetEnforcedForGroups(): void { |
|
155 | + $this->config |
|
156 | + ->expects($this->exactly(3)) |
|
157 | + ->method('setSystemValue') |
|
158 | + ->willReturnMap([ |
|
159 | + ['twofactor_enforced', 'true'], |
|
160 | + ['twofactor_enforced_groups', ['twofactorers']], |
|
161 | + ['twofactor_enforced_excluded_groups', ['yoloers']], |
|
162 | + ]); |
|
163 | + |
|
164 | + $this->mandatoryTwoFactor->setState(new EnforcementState(true, ['twofactorers'], ['yoloers'])); |
|
165 | + } |
|
166 | + |
|
167 | + public function testSetNotEnforced(): void { |
|
168 | + $this->config |
|
169 | + ->expects($this->exactly(3)) |
|
170 | + ->method('setSystemValue') |
|
171 | + ->willReturnMap([ |
|
172 | + ['twofactor_enforced', 'false'], |
|
173 | + ['twofactor_enforced_groups', []], |
|
174 | + ['twofactor_enforced_excluded_groups', []], |
|
175 | + ]); |
|
176 | + |
|
177 | + $this->mandatoryTwoFactor->setState(new EnforcementState(false)); |
|
178 | + } |
|
179 | 179 | } |
@@ -15,61 +15,61 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class ProviderSetTest extends TestCase { |
18 | - /** @var ProviderSet */ |
|
19 | - private $providerSet; |
|
20 | - |
|
21 | - public function testIndexesProviders(): void { |
|
22 | - $p1 = $this->createMock(IProvider::class); |
|
23 | - $p1->method('getId')->willReturn('p1'); |
|
24 | - $p2 = $this->createMock(IProvider::class); |
|
25 | - $p2->method('getId')->willReturn('p2'); |
|
26 | - $expected = [ |
|
27 | - 'p1' => $p1, |
|
28 | - 'p2' => $p2, |
|
29 | - ]; |
|
30 | - |
|
31 | - $set = new ProviderSet([$p2, $p1], false); |
|
32 | - |
|
33 | - $this->assertEquals($expected, $set->getProviders()); |
|
34 | - } |
|
35 | - |
|
36 | - public function testGet3rdPartyProviders(): void { |
|
37 | - $p1 = $this->createMock(IProvider::class); |
|
38 | - $p1->method('getId')->willReturn('p1'); |
|
39 | - $p2 = $this->createMock(IProvider::class); |
|
40 | - $p2->method('getId')->willReturn('p2'); |
|
41 | - $p3 = $this->createMock(BackupCodesProvider::class); |
|
42 | - $p3->method('getId')->willReturn('p3'); |
|
43 | - $expected = [ |
|
44 | - 'p1' => $p1, |
|
45 | - 'p2' => $p2, |
|
46 | - ]; |
|
47 | - |
|
48 | - $set = new ProviderSet([$p2, $p1], false); |
|
49 | - |
|
50 | - $this->assertEquals($expected, $set->getPrimaryProviders()); |
|
51 | - } |
|
52 | - |
|
53 | - public function testGetProvider(): void { |
|
54 | - $p1 = $this->createMock(IProvider::class); |
|
55 | - $p1->method('getId')->willReturn('p1'); |
|
56 | - |
|
57 | - $set = new ProviderSet([$p1], false); |
|
58 | - $provider = $set->getProvider('p1'); |
|
59 | - |
|
60 | - $this->assertEquals($p1, $provider); |
|
61 | - } |
|
62 | - |
|
63 | - public function testGetProviderNotFound(): void { |
|
64 | - $set = new ProviderSet([], false); |
|
65 | - $provider = $set->getProvider('p1'); |
|
66 | - |
|
67 | - $this->assertNull($provider); |
|
68 | - } |
|
69 | - |
|
70 | - public function testIsProviderMissing(): void { |
|
71 | - $set = new ProviderSet([], true); |
|
72 | - |
|
73 | - $this->assertTrue($set->isProviderMissing()); |
|
74 | - } |
|
18 | + /** @var ProviderSet */ |
|
19 | + private $providerSet; |
|
20 | + |
|
21 | + public function testIndexesProviders(): void { |
|
22 | + $p1 = $this->createMock(IProvider::class); |
|
23 | + $p1->method('getId')->willReturn('p1'); |
|
24 | + $p2 = $this->createMock(IProvider::class); |
|
25 | + $p2->method('getId')->willReturn('p2'); |
|
26 | + $expected = [ |
|
27 | + 'p1' => $p1, |
|
28 | + 'p2' => $p2, |
|
29 | + ]; |
|
30 | + |
|
31 | + $set = new ProviderSet([$p2, $p1], false); |
|
32 | + |
|
33 | + $this->assertEquals($expected, $set->getProviders()); |
|
34 | + } |
|
35 | + |
|
36 | + public function testGet3rdPartyProviders(): void { |
|
37 | + $p1 = $this->createMock(IProvider::class); |
|
38 | + $p1->method('getId')->willReturn('p1'); |
|
39 | + $p2 = $this->createMock(IProvider::class); |
|
40 | + $p2->method('getId')->willReturn('p2'); |
|
41 | + $p3 = $this->createMock(BackupCodesProvider::class); |
|
42 | + $p3->method('getId')->willReturn('p3'); |
|
43 | + $expected = [ |
|
44 | + 'p1' => $p1, |
|
45 | + 'p2' => $p2, |
|
46 | + ]; |
|
47 | + |
|
48 | + $set = new ProviderSet([$p2, $p1], false); |
|
49 | + |
|
50 | + $this->assertEquals($expected, $set->getPrimaryProviders()); |
|
51 | + } |
|
52 | + |
|
53 | + public function testGetProvider(): void { |
|
54 | + $p1 = $this->createMock(IProvider::class); |
|
55 | + $p1->method('getId')->willReturn('p1'); |
|
56 | + |
|
57 | + $set = new ProviderSet([$p1], false); |
|
58 | + $provider = $set->getProvider('p1'); |
|
59 | + |
|
60 | + $this->assertEquals($p1, $provider); |
|
61 | + } |
|
62 | + |
|
63 | + public function testGetProviderNotFound(): void { |
|
64 | + $set = new ProviderSet([], false); |
|
65 | + $provider = $set->getProvider('p1'); |
|
66 | + |
|
67 | + $this->assertNull($provider); |
|
68 | + } |
|
69 | + |
|
70 | + public function testIsProviderMissing(): void { |
|
71 | + $set = new ProviderSet([], true); |
|
72 | + |
|
73 | + $this->assertTrue($set->isProviderMissing()); |
|
74 | + } |
|
75 | 75 | } |
@@ -17,34 +17,34 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class EnforcementStateTest extends TestCase { |
20 | - public function testIsEnforced(): void { |
|
21 | - $state = new EnforcementState(true); |
|
20 | + public function testIsEnforced(): void { |
|
21 | + $state = new EnforcementState(true); |
|
22 | 22 | |
23 | - $this->assertTrue($state->isEnforced()); |
|
24 | - } |
|
23 | + $this->assertTrue($state->isEnforced()); |
|
24 | + } |
|
25 | 25 | |
26 | - public function testGetEnforcedGroups(): void { |
|
27 | - $state = new EnforcementState(true, ['twofactorers']); |
|
26 | + public function testGetEnforcedGroups(): void { |
|
27 | + $state = new EnforcementState(true, ['twofactorers']); |
|
28 | 28 | |
29 | - $this->assertEquals(['twofactorers'], $state->getEnforcedGroups()); |
|
30 | - } |
|
29 | + $this->assertEquals(['twofactorers'], $state->getEnforcedGroups()); |
|
30 | + } |
|
31 | 31 | |
32 | - public function testGetExcludedGroups(): void { |
|
33 | - $state = new EnforcementState(true, [], ['yoloers']); |
|
32 | + public function testGetExcludedGroups(): void { |
|
33 | + $state = new EnforcementState(true, [], ['yoloers']); |
|
34 | 34 | |
35 | - $this->assertEquals(['yoloers'], $state->getExcludedGroups()); |
|
36 | - } |
|
35 | + $this->assertEquals(['yoloers'], $state->getExcludedGroups()); |
|
36 | + } |
|
37 | 37 | |
38 | - public function testJsonSerialize(): void { |
|
39 | - $state = new EnforcementState(true, ['twofactorers'], ['yoloers']); |
|
40 | - $expected = [ |
|
41 | - 'enforced' => true, |
|
42 | - 'enforcedGroups' => ['twofactorers'], |
|
43 | - 'excludedGroups' => ['yoloers'], |
|
44 | - ]; |
|
38 | + public function testJsonSerialize(): void { |
|
39 | + $state = new EnforcementState(true, ['twofactorers'], ['yoloers']); |
|
40 | + $expected = [ |
|
41 | + 'enforced' => true, |
|
42 | + 'enforcedGroups' => ['twofactorers'], |
|
43 | + 'excludedGroups' => ['yoloers'], |
|
44 | + ]; |
|
45 | 45 | |
46 | - $json = $state->jsonSerialize(); |
|
46 | + $json = $state->jsonSerialize(); |
|
47 | 47 | |
48 | - $this->assertEquals($expected, $json); |
|
49 | - } |
|
48 | + $this->assertEquals($expected, $json); |
|
49 | + } |
|
50 | 50 | } |