Completed
Push — master ( 258b30...5f33fe )
by
unknown
44:16
created
tests/lib/TemplateFunctionsTest.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -9,290 +9,290 @@
 block discarded – undo
9 9
 namespace Test;
10 10
 
11 11
 class TemplateFunctionsTest extends \Test\TestCase {
12
-	protected function setUp(): void {
13
-		parent::setUp();
14
-
15
-		require_once \OC::$SERVERROOT . '/lib/private/Template/functions.php';
16
-	}
17
-
18
-	public function testPJavaScript(): void {
19
-		$this->expectOutputString('<img onload="alert(1)" />');
20
-		p('<img onload="alert(1)" />');
21
-	}
22
-
23
-	public function testPJavaScriptWithScriptTags(): void {
24
-		$this->expectOutputString('&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;');
25
-		p("<script>alert('Hacked!');</script>");
26
-	}
27
-
28
-	public function testPNormalString(): void {
29
-		$string = 'This is a good string without HTML.';
30
-		$this->expectOutputString($string);
31
-		p($string);
32
-	}
33
-
34
-	public function testPrintUnescaped(): void {
35
-		$htmlString = "<script>alert('xss');</script>";
36
-		$this->expectOutputString($htmlString);
37
-		print_unescaped($htmlString);
38
-	}
39
-
40
-	public function testPrintUnescapedNormalString(): void {
41
-		$string = 'This is a good string!';
42
-		$this->expectOutputString($string);
43
-		print_unescaped($string);
44
-	}
45
-
46
-	public function testEmitScriptTagWithContent(): void {
47
-		$this->expectOutputRegex('/<script nonce="[^"]+">\nalert\(\)\n<\/script>\n?/');
48
-		emit_script_tag('', 'alert()');
49
-	}
50
-
51
-	public function testEmitScriptTagWithSource(): void {
52
-		$this->expectOutputRegex('/<script nonce=".*" defer src="some.js"><\/script>/');
53
-		emit_script_tag('some.js');
54
-	}
55
-
56
-	public function testEmitScriptTagWithModuleSource(): void {
57
-		$this->expectOutputRegex('/<script nonce=".*" type="module" src="some.mjs"><\/script>/');
58
-		emit_script_tag('some.mjs', '', 'module');
59
-	}
60
-
61
-	public function testEmitImportMap(): void {
62
-		$this->expectOutputRegex('/^<script[^>]+type="importmap">\n{"imports":{"\/some\/path\/file\.mjs":"\/some\/path\/file\.mjs\?v=123"}}\n<\/script>$/m');
63
-		emit_import_map(['jsfiles' => ['/some/path/file.mjs?v=123']]);
64
-	}
65
-
66
-	// only create import map for modules with versioning
67
-	public function testEmitImportMapMixedScripts(): void {
68
-		$this->expectOutputRegex('/^<script[^>]+type="importmap">\n{"imports":{"\/some\/path\/module\.mjs":"\/some\/path\/module\.mjs\?v=123"}}\n<\/script>$/m');
69
-		emit_import_map(['jsfiles' => ['/some/path/module.mjs?v=123', '/some/path/classic.js?v=123']]);
70
-	}
71
-
72
-	public function testEmitImportMapNoOutputWithoutVersion(): void {
73
-		$this->expectOutputString('');
74
-		emit_import_map(['jsfiles' => ['some.mjs']]);
75
-	}
76
-
77
-	public function testEmitImportMapNoOutputWithClassicScript(): void {
78
-		$this->expectOutputString('');
79
-		emit_import_map(['jsfiles' => ['some.js?v=123']]);
80
-	}
81
-
82
-	public function testEmitScriptLoadingTags(): void {
83
-		// Test mjs js and inline content
84
-		$pattern = '/type="module"[^>]+src="some\.mjs"[^>]*>.+\n'; // some.mjs with type = module
85
-		$pattern .= '<script[^>]+src="other\.js"[^>]*>.+\n'; // other.js as plain javascript
86
-		$pattern .= '<script[^>]*>\n?.*inline.*\n?<\/script>'; // inline content
87
-		$pattern .= '/'; // no flags
88
-
89
-		$this->expectOutputRegex($pattern);
90
-		emit_script_loading_tags([
91
-			'jsfiles' => ['some.mjs', 'other.js'],
92
-			'inline_ocjs' => '// inline'
93
-		]);
94
-	}
95
-
96
-	public function testEmitScriptLoadingTagsWithVersion(): void {
97
-		// Test mjs js and inline content
98
-		$pattern = '/type="module"[^>]+src="some\.mjs\?v=ab123cd"[^>]*>.+\n'; // some.mjs with type = module
99
-		$pattern .= '<script[^>]+src="other\.js\?v=12abc34"[^>]*>.+\n'; // other.js as plain javascript
100
-		$pattern .= '/'; // no flags
101
-
102
-		$this->expectOutputRegex($pattern);
103
-		emit_script_loading_tags([
104
-			'jsfiles' => ['some.mjs?v=ab123cd', 'other.js?v=12abc34'],
105
-		]);
106
-	}
107
-
108
-	// ---------------------------------------------------------------------------
109
-	// Test relative_modified_date with dates only
110
-	// ---------------------------------------------------------------------------
111
-	public function testRelativeDateToday(): void {
112
-		$currentTime = 1380703592;
113
-		$elementTime = $currentTime;
114
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
115
-
116
-		$this->assertEquals('today', $result);
117
-
118
-		// 2 hours ago is still today
119
-		$elementTime = $currentTime - 2 * 3600;
120
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
121
-
122
-		$this->assertEquals('today', $result);
123
-	}
124
-
125
-	public function testRelativeDateYesterday(): void {
126
-		$currentTime = 1380703592;
127
-		$elementTime = $currentTime - 24 * 3600;
128
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
129
-
130
-		$this->assertEquals('yesterday', $result);
131
-
132
-		// yesterday - 2 hours is still yesterday
133
-		$elementTime = $currentTime - 26 * 3600;
134
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
135
-
136
-		$this->assertEquals('yesterday', $result);
137
-	}
138
-
139
-	public function testRelativeDate2DaysAgo(): void {
140
-		$currentTime = 1380703592;
141
-		$elementTime = $currentTime - 48 * 3600;
142
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
12
+    protected function setUp(): void {
13
+        parent::setUp();
14
+
15
+        require_once \OC::$SERVERROOT . '/lib/private/Template/functions.php';
16
+    }
17
+
18
+    public function testPJavaScript(): void {
19
+        $this->expectOutputString('&lt;img onload=&quot;alert(1)&quot; /&gt;');
20
+        p('<img onload="alert(1)" />');
21
+    }
22
+
23
+    public function testPJavaScriptWithScriptTags(): void {
24
+        $this->expectOutputString('&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;');
25
+        p("<script>alert('Hacked!');</script>");
26
+    }
27
+
28
+    public function testPNormalString(): void {
29
+        $string = 'This is a good string without HTML.';
30
+        $this->expectOutputString($string);
31
+        p($string);
32
+    }
33
+
34
+    public function testPrintUnescaped(): void {
35
+        $htmlString = "<script>alert('xss');</script>";
36
+        $this->expectOutputString($htmlString);
37
+        print_unescaped($htmlString);
38
+    }
39
+
40
+    public function testPrintUnescapedNormalString(): void {
41
+        $string = 'This is a good string!';
42
+        $this->expectOutputString($string);
43
+        print_unescaped($string);
44
+    }
45
+
46
+    public function testEmitScriptTagWithContent(): void {
47
+        $this->expectOutputRegex('/<script nonce="[^"]+">\nalert\(\)\n<\/script>\n?/');
48
+        emit_script_tag('', 'alert()');
49
+    }
50
+
51
+    public function testEmitScriptTagWithSource(): void {
52
+        $this->expectOutputRegex('/<script nonce=".*" defer src="some.js"><\/script>/');
53
+        emit_script_tag('some.js');
54
+    }
55
+
56
+    public function testEmitScriptTagWithModuleSource(): void {
57
+        $this->expectOutputRegex('/<script nonce=".*" type="module" src="some.mjs"><\/script>/');
58
+        emit_script_tag('some.mjs', '', 'module');
59
+    }
60
+
61
+    public function testEmitImportMap(): void {
62
+        $this->expectOutputRegex('/^<script[^>]+type="importmap">\n{"imports":{"\/some\/path\/file\.mjs":"\/some\/path\/file\.mjs\?v=123"}}\n<\/script>$/m');
63
+        emit_import_map(['jsfiles' => ['/some/path/file.mjs?v=123']]);
64
+    }
65
+
66
+    // only create import map for modules with versioning
67
+    public function testEmitImportMapMixedScripts(): void {
68
+        $this->expectOutputRegex('/^<script[^>]+type="importmap">\n{"imports":{"\/some\/path\/module\.mjs":"\/some\/path\/module\.mjs\?v=123"}}\n<\/script>$/m');
69
+        emit_import_map(['jsfiles' => ['/some/path/module.mjs?v=123', '/some/path/classic.js?v=123']]);
70
+    }
71
+
72
+    public function testEmitImportMapNoOutputWithoutVersion(): void {
73
+        $this->expectOutputString('');
74
+        emit_import_map(['jsfiles' => ['some.mjs']]);
75
+    }
76
+
77
+    public function testEmitImportMapNoOutputWithClassicScript(): void {
78
+        $this->expectOutputString('');
79
+        emit_import_map(['jsfiles' => ['some.js?v=123']]);
80
+    }
81
+
82
+    public function testEmitScriptLoadingTags(): void {
83
+        // Test mjs js and inline content
84
+        $pattern = '/type="module"[^>]+src="some\.mjs"[^>]*>.+\n'; // some.mjs with type = module
85
+        $pattern .= '<script[^>]+src="other\.js"[^>]*>.+\n'; // other.js as plain javascript
86
+        $pattern .= '<script[^>]*>\n?.*inline.*\n?<\/script>'; // inline content
87
+        $pattern .= '/'; // no flags
88
+
89
+        $this->expectOutputRegex($pattern);
90
+        emit_script_loading_tags([
91
+            'jsfiles' => ['some.mjs', 'other.js'],
92
+            'inline_ocjs' => '// inline'
93
+        ]);
94
+    }
95
+
96
+    public function testEmitScriptLoadingTagsWithVersion(): void {
97
+        // Test mjs js and inline content
98
+        $pattern = '/type="module"[^>]+src="some\.mjs\?v=ab123cd"[^>]*>.+\n'; // some.mjs with type = module
99
+        $pattern .= '<script[^>]+src="other\.js\?v=12abc34"[^>]*>.+\n'; // other.js as plain javascript
100
+        $pattern .= '/'; // no flags
101
+
102
+        $this->expectOutputRegex($pattern);
103
+        emit_script_loading_tags([
104
+            'jsfiles' => ['some.mjs?v=ab123cd', 'other.js?v=12abc34'],
105
+        ]);
106
+    }
107
+
108
+    // ---------------------------------------------------------------------------
109
+    // Test relative_modified_date with dates only
110
+    // ---------------------------------------------------------------------------
111
+    public function testRelativeDateToday(): void {
112
+        $currentTime = 1380703592;
113
+        $elementTime = $currentTime;
114
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
115
+
116
+        $this->assertEquals('today', $result);
117
+
118
+        // 2 hours ago is still today
119
+        $elementTime = $currentTime - 2 * 3600;
120
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
121
+
122
+        $this->assertEquals('today', $result);
123
+    }
124
+
125
+    public function testRelativeDateYesterday(): void {
126
+        $currentTime = 1380703592;
127
+        $elementTime = $currentTime - 24 * 3600;
128
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
129
+
130
+        $this->assertEquals('yesterday', $result);
131
+
132
+        // yesterday - 2 hours is still yesterday
133
+        $elementTime = $currentTime - 26 * 3600;
134
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
135
+
136
+        $this->assertEquals('yesterday', $result);
137
+    }
138
+
139
+    public function testRelativeDate2DaysAgo(): void {
140
+        $currentTime = 1380703592;
141
+        $elementTime = $currentTime - 48 * 3600;
142
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
143 143
 
144
-		$this->assertEquals('2 days ago', $result);
144
+        $this->assertEquals('2 days ago', $result);
145 145
 
146
-		// 2 days ago minus 4 hours is still 2 days ago
147
-		$elementTime = $currentTime - 52 * 3600;
148
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
146
+        // 2 days ago minus 4 hours is still 2 days ago
147
+        $elementTime = $currentTime - 52 * 3600;
148
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
149 149
 
150
-		$this->assertEquals('2 days ago', $result);
151
-	}
150
+        $this->assertEquals('2 days ago', $result);
151
+    }
152 152
 
153
-	public function testRelativeDateLastMonth(): void {
154
-		$currentTime = 1380703592;
155
-		$elementTime = $currentTime - 86400 * 31;
156
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
153
+    public function testRelativeDateLastMonth(): void {
154
+        $currentTime = 1380703592;
155
+        $elementTime = $currentTime - 86400 * 31;
156
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
157 157
 
158
-		$this->assertEquals('last month', $result);
158
+        $this->assertEquals('last month', $result);
159 159
 
160
-		$elementTime = $currentTime - 86400 * 35;
161
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
160
+        $elementTime = $currentTime - 86400 * 35;
161
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
162 162
 
163
-		$this->assertEquals('last month', $result);
164
-	}
163
+        $this->assertEquals('last month', $result);
164
+    }
165 165
 
166
-	public function testRelativeDateMonthsAgo(): void {
167
-		$currentTime = 1380703592;
168
-		$elementTime = $currentTime - 86400 * 65;
169
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
166
+    public function testRelativeDateMonthsAgo(): void {
167
+        $currentTime = 1380703592;
168
+        $elementTime = $currentTime - 86400 * 65;
169
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
170 170
 
171
-		$this->assertEquals('2 months ago', $result);
171
+        $this->assertEquals('2 months ago', $result);
172 172
 
173
-		$elementTime = $currentTime - 86400 * 130;
174
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
173
+        $elementTime = $currentTime - 86400 * 130;
174
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
175 175
 
176
-		$this->assertEquals('4 months ago', $result);
177
-	}
176
+        $this->assertEquals('4 months ago', $result);
177
+    }
178 178
 
179
-	public function testRelativeDateLastYear(): void {
180
-		$currentTime = 1380703592;
181
-		$elementTime = $currentTime - 86400 * 365;
182
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
179
+    public function testRelativeDateLastYear(): void {
180
+        $currentTime = 1380703592;
181
+        $elementTime = $currentTime - 86400 * 365;
182
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
183 183
 
184
-		$this->assertEquals('last year', $result);
184
+        $this->assertEquals('last year', $result);
185 185
 
186
-		$elementTime = $currentTime - 86400 * 450;
187
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
186
+        $elementTime = $currentTime - 86400 * 450;
187
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
188 188
 
189
-		$this->assertEquals('last year', $result);
190
-	}
189
+        $this->assertEquals('last year', $result);
190
+    }
191 191
 
192
-	public function testRelativeDateYearsAgo(): void {
193
-		$currentTime = 1380703592;
194
-		$elementTime = $currentTime - 86400 * 365.25 * 2;
195
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
192
+    public function testRelativeDateYearsAgo(): void {
193
+        $currentTime = 1380703592;
194
+        $elementTime = $currentTime - 86400 * 365.25 * 2;
195
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
196 196
 
197
-		$this->assertEquals('2 years ago', $result);
197
+        $this->assertEquals('2 years ago', $result);
198 198
 
199
-		$elementTime = $currentTime - 86400 * 365.25 * 3;
200
-		$result = (string)relative_modified_date($elementTime, $currentTime, true);
199
+        $elementTime = $currentTime - 86400 * 365.25 * 3;
200
+        $result = (string)relative_modified_date($elementTime, $currentTime, true);
201 201
 
202
-		$this->assertEquals('3 years ago', $result);
203
-	}
202
+        $this->assertEquals('3 years ago', $result);
203
+    }
204 204
 
205
-	// ---------------------------------------------------------------------------
206
-	// Test relative_modified_date with timestamps only (date + time value)
207
-	// ---------------------------------------------------------------------------
205
+    // ---------------------------------------------------------------------------
206
+    // Test relative_modified_date with timestamps only (date + time value)
207
+    // ---------------------------------------------------------------------------
208 208
 
209
-	public function testRelativeTimeSecondsAgo(): void {
210
-		$currentTime = 1380703592;
211
-		$elementTime = $currentTime - 5;
212
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
209
+    public function testRelativeTimeSecondsAgo(): void {
210
+        $currentTime = 1380703592;
211
+        $elementTime = $currentTime - 5;
212
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
213 213
 
214
-		$this->assertEquals('seconds ago', $result);
215
-	}
214
+        $this->assertEquals('seconds ago', $result);
215
+    }
216 216
 
217
-	public function testRelativeTimeMinutesAgo(): void {
218
-		$currentTime = 1380703592;
219
-		$elementTime = $currentTime - 190;
220
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
217
+    public function testRelativeTimeMinutesAgo(): void {
218
+        $currentTime = 1380703592;
219
+        $elementTime = $currentTime - 190;
220
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
221 221
 
222
-		$this->assertEquals('3 minutes ago', $result);
223
-	}
222
+        $this->assertEquals('3 minutes ago', $result);
223
+    }
224 224
 
225
-	public function testRelativeTimeHoursAgo(): void {
226
-		$currentTime = 1380703592;
227
-		$elementTime = $currentTime - 7500;
228
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
225
+    public function testRelativeTimeHoursAgo(): void {
226
+        $currentTime = 1380703592;
227
+        $elementTime = $currentTime - 7500;
228
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
229 229
 
230
-		$this->assertEquals('2 hours ago', $result);
231
-	}
230
+        $this->assertEquals('2 hours ago', $result);
231
+    }
232 232
 
233
-	public function testRelativeTime2DaysAgo(): void {
234
-		$currentTime = 1380703592;
235
-		$elementTime = $currentTime - 48 * 3600;
236
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
233
+    public function testRelativeTime2DaysAgo(): void {
234
+        $currentTime = 1380703592;
235
+        $elementTime = $currentTime - 48 * 3600;
236
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
237 237
 
238
-		$this->assertEquals('2 days ago', $result);
238
+        $this->assertEquals('2 days ago', $result);
239 239
 
240
-		// 2 days ago minus 4 hours is still 2 days ago
241
-		$elementTime = $currentTime - 52 * 3600;
242
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
240
+        // 2 days ago minus 4 hours is still 2 days ago
241
+        $elementTime = $currentTime - 52 * 3600;
242
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
243 243
 
244
-		$this->assertEquals('2 days ago', $result);
245
-	}
244
+        $this->assertEquals('2 days ago', $result);
245
+    }
246 246
 
247
-	public function testRelativeTimeLastMonth(): void {
248
-		$currentTime = 1380703592;
249
-		$elementTime = $currentTime - 86400 * 31;
250
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
247
+    public function testRelativeTimeLastMonth(): void {
248
+        $currentTime = 1380703592;
249
+        $elementTime = $currentTime - 86400 * 31;
250
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
251 251
 
252
-		$this->assertEquals('last month', $result);
252
+        $this->assertEquals('last month', $result);
253 253
 
254
-		$elementTime = $currentTime - 86400 * 35;
255
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
254
+        $elementTime = $currentTime - 86400 * 35;
255
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
256 256
 
257
-		$this->assertEquals('last month', $result);
258
-	}
257
+        $this->assertEquals('last month', $result);
258
+    }
259 259
 
260
-	public function testRelativeTimeMonthsAgo(): void {
261
-		$currentTime = 1380703592;
262
-		$elementTime = $currentTime - 86400 * 65;
263
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
260
+    public function testRelativeTimeMonthsAgo(): void {
261
+        $currentTime = 1380703592;
262
+        $elementTime = $currentTime - 86400 * 65;
263
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
264 264
 
265
-		$this->assertEquals('2 months ago', $result);
265
+        $this->assertEquals('2 months ago', $result);
266 266
 
267
-		$elementTime = $currentTime - 86400 * 130;
268
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
267
+        $elementTime = $currentTime - 86400 * 130;
268
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
269 269
 
270
-		$this->assertEquals('4 months ago', $result);
271
-	}
270
+        $this->assertEquals('4 months ago', $result);
271
+    }
272 272
 
273
-	public function testRelativeTimeLastYear(): void {
274
-		$currentTime = 1380703592;
275
-		$elementTime = $currentTime - 86400 * 365;
276
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
273
+    public function testRelativeTimeLastYear(): void {
274
+        $currentTime = 1380703592;
275
+        $elementTime = $currentTime - 86400 * 365;
276
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
277 277
 
278
-		$this->assertEquals('last year', $result);
278
+        $this->assertEquals('last year', $result);
279 279
 
280
-		$elementTime = $currentTime - 86400 * 450;
281
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
280
+        $elementTime = $currentTime - 86400 * 450;
281
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
282 282
 
283
-		$this->assertEquals('last year', $result);
284
-	}
283
+        $this->assertEquals('last year', $result);
284
+    }
285 285
 
286
-	public function testRelativeTimeYearsAgo(): void {
287
-		$currentTime = 1380703592;
288
-		$elementTime = $currentTime - 86400 * 365.25 * 2;
289
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
286
+    public function testRelativeTimeYearsAgo(): void {
287
+        $currentTime = 1380703592;
288
+        $elementTime = $currentTime - 86400 * 365.25 * 2;
289
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
290 290
 
291
-		$this->assertEquals('2 years ago', $result);
291
+        $this->assertEquals('2 years ago', $result);
292 292
 
293
-		$elementTime = $currentTime - 86400 * 365.25 * 3;
294
-		$result = (string)relative_modified_date($elementTime, $currentTime, false);
293
+        $elementTime = $currentTime - 86400 * 365.25 * 3;
294
+        $result = (string)relative_modified_date($elementTime, $currentTime, false);
295 295
 
296
-		$this->assertEquals('3 years ago', $result);
297
-	}
296
+        $this->assertEquals('3 years ago', $result);
297
+    }
298 298
 }
Please login to merge, or discard this patch.
lib/private/Template/functions.php 2 patches
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  * @param string $string
18 18
  */
19 19
 function p($string): void {
20
-	print(Util::sanitizeHTML($string));
20
+    print(Util::sanitizeHTML($string));
21 21
 }
22 22
 
23 23
 /**
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
  * @param string $opts, additional optional options
27 27
  */
28 28
 function emit_css_tag($href, $opts = ''): void {
29
-	$s = '<link rel="stylesheet"';
30
-	if (!empty($href)) {
31
-		$s .= ' href="' . $href . '"';
32
-	}
33
-	if (!empty($opts)) {
34
-		$s .= ' ' . $opts;
35
-	}
36
-	print_unescaped($s . ">\n");
29
+    $s = '<link rel="stylesheet"';
30
+    if (!empty($href)) {
31
+        $s .= ' href="' . $href . '"';
32
+    }
33
+    if (!empty($opts)) {
34
+        $s .= ' ' . $opts;
35
+    }
36
+    print_unescaped($s . ">\n");
37 37
 }
38 38
 
39 39
 /**
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
  * @param array $obj all the script information from template
42 42
  */
43 43
 function emit_css_loading_tags($obj): void {
44
-	foreach ($obj['cssfiles'] as $css) {
45
-		emit_css_tag($css);
46
-	}
47
-	foreach ($obj['printcssfiles'] as $css) {
48
-		emit_css_tag($css, 'media="print"');
49
-	}
44
+    foreach ($obj['cssfiles'] as $css) {
45
+        emit_css_tag($css);
46
+    }
47
+    foreach ($obj['printcssfiles'] as $css) {
48
+        emit_css_tag($css, 'media="print"');
49
+    }
50 50
 }
51 51
 
52 52
 /**
@@ -58,21 +58,21 @@  discard block
 block discarded – undo
58 58
  * @since 27.0.0 added the $content_type parameter
59 59
  */
60 60
 function emit_script_tag(string $src, string $script_content = '', string $content_type = ''): void {
61
-	$nonceManager = Server::get(ContentSecurityPolicyNonceManager::class);
61
+    $nonceManager = Server::get(ContentSecurityPolicyNonceManager::class);
62 62
 
63
-	$defer_str = $content_type === '' ? ' defer' : ''; // "defer" only works with classic scripts
64
-	$type = $content_type !== '' ? ' type="' . $content_type . '"' : '';
63
+    $defer_str = $content_type === '' ? ' defer' : ''; // "defer" only works with classic scripts
64
+    $type = $content_type !== '' ? ' type="' . $content_type . '"' : '';
65 65
 
66
-	$s = '<script nonce="' . $nonceManager->getNonce() . '"' . $type;
67
-	if (!empty($src)) {
68
-		// emit script tag for deferred loading from $src
69
-		$s .= $defer_str . ' src="' . $src . '">';
70
-	} else {
71
-		// emit script tag for inline script from $script_content without defer (see MDN)
72
-		$s .= ">\n" . $script_content . "\n";
73
-	}
74
-	$s .= '</script>';
75
-	print_unescaped($s . "\n");
66
+    $s = '<script nonce="' . $nonceManager->getNonce() . '"' . $type;
67
+    if (!empty($src)) {
68
+        // emit script tag for deferred loading from $src
69
+        $s .= $defer_str . ' src="' . $src . '">';
70
+    } else {
71
+        // emit script tag for inline script from $script_content without defer (see MDN)
72
+        $s .= ">\n" . $script_content . "\n";
73
+    }
74
+    $s .= '</script>';
75
+    print_unescaped($s . "\n");
76 76
 }
77 77
 
78 78
 /**
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
  * @param array $obj all the script information from template
81 81
  */
82 82
 function emit_script_loading_tags($obj): void {
83
-	emit_import_map($obj);
83
+    emit_import_map($obj);
84 84
 
85
-	foreach ($obj['jsfiles'] as $jsfile) {
86
-		$fileName = explode('?', $jsfile, 2)[0];
87
-		$type = str_ends_with($fileName, '.mjs') ? 'module' : '';
88
-		emit_script_tag($jsfile, '', $type);
89
-	}
90
-	if (!empty($obj['inline_ocjs'])) {
91
-		emit_script_tag('', $obj['inline_ocjs']);
92
-	}
85
+    foreach ($obj['jsfiles'] as $jsfile) {
86
+        $fileName = explode('?', $jsfile, 2)[0];
87
+        $type = str_ends_with($fileName, '.mjs') ? 'module' : '';
88
+        emit_script_tag($jsfile, '', $type);
89
+    }
90
+    if (!empty($obj['inline_ocjs'])) {
91
+        emit_script_tag('', $obj['inline_ocjs']);
92
+    }
93 93
 }
94 94
 
95 95
 /**
@@ -101,18 +101,18 @@  discard block
 block discarded – undo
101 101
  * @param $obj all the script information from template
102 102
  */
103 103
 function emit_import_map(array $obj): void {
104
-	$modules = [];
105
-	foreach ($obj['jsfiles'] as $jsfile) {
106
-		$fileName = explode('?', $jsfile, 2)[0];
107
-		if (str_ends_with($fileName, '.mjs') && $jsfile !== $fileName) {
108
-			// its a module and we have a cache buster available
109
-			$modules[$fileName] = $jsfile;
110
-		}
111
-	}
112
-	if (!empty($modules)) {
113
-		$json = json_encode(['imports' => $modules], JSON_UNESCAPED_SLASHES | JSON_FORCE_OBJECT);
114
-		emit_script_tag('', $json, 'importmap');
115
-	}
104
+    $modules = [];
105
+    foreach ($obj['jsfiles'] as $jsfile) {
106
+        $fileName = explode('?', $jsfile, 2)[0];
107
+        if (str_ends_with($fileName, '.mjs') && $jsfile !== $fileName) {
108
+            // its a module and we have a cache buster available
109
+            $modules[$fileName] = $jsfile;
110
+        }
111
+    }
112
+    if (!empty($modules)) {
113
+        $json = json_encode(['imports' => $modules], JSON_UNESCAPED_SLASHES | JSON_FORCE_OBJECT);
114
+        emit_script_tag('', $json, 'importmap');
115
+    }
116 116
 }
117 117
 
118 118
 /**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
  * @param string $string the string which will be printed as it is
122 122
  */
123 123
 function print_unescaped($string): void {
124
-	print($string);
124
+    print($string);
125 125
 }
126 126
 
127 127
 /**
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
  *                              if an array is given it will add all scripts
138 138
  */
139 139
 function script($app, $file = null): void {
140
-	if (is_array($file)) {
141
-		foreach ($file as $script) {
142
-			Util::addScript($app, $script, 'core');
143
-		}
144
-	} else {
145
-		Util::addScript($app, $file, 'core');
146
-	}
140
+    if (is_array($file)) {
141
+        foreach ($file as $script) {
142
+            Util::addScript($app, $script, 'core');
143
+        }
144
+    } else {
145
+        Util::addScript($app, $file, 'core');
146
+    }
147 147
 }
148 148
 
149 149
 /**
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
  *                              if an array is given it will add all styles
154 154
  */
155 155
 function style($app, $file = null): void {
156
-	if (is_array($file)) {
157
-		foreach ($file as $f) {
158
-			Util::addStyle($app, $f);
159
-		}
160
-	} else {
161
-		Util::addStyle($app, $file);
162
-	}
156
+    if (is_array($file)) {
157
+        foreach ($file as $f) {
158
+            Util::addStyle($app, $f);
159
+        }
160
+    } else {
161
+        Util::addStyle($app, $file);
162
+    }
163 163
 }
164 164
 
165 165
 /**
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
  * @deprecated 32.0.0
171 171
  */
172 172
 function vendor_style($app, $file = null): void {
173
-	if (is_array($file)) {
174
-		foreach ($file as $f) {
175
-			OC_Util::addVendorStyle($app, $f);
176
-		}
177
-	} else {
178
-		OC_Util::addVendorStyle($app, $file);
179
-	}
173
+    if (is_array($file)) {
174
+        foreach ($file as $f) {
175
+            OC_Util::addVendorStyle($app, $f);
176
+        }
177
+    } else {
178
+        OC_Util::addVendorStyle($app, $file);
179
+    }
180 180
 }
181 181
 
182 182
 /**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
  *                    if an array is given it will add all styles
186 186
  */
187 187
 function translation($app): void {
188
-	Util::addTranslations($app);
188
+    Util::addTranslations($app);
189 189
 }
190 190
 
191 191
 /**
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
  * For further information have a look at \OCP\IURLGenerator::linkTo
199 199
  */
200 200
 function link_to($app, $file, $args = []) {
201
-	return Server::get(IURLGenerator::class)->linkTo($app, $file, $args);
201
+    return Server::get(IURLGenerator::class)->linkTo($app, $file, $args);
202 202
 }
203 203
 
204 204
 /**
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
  * @return string url to the online documentation
207 207
  */
208 208
 function link_to_docs($key) {
209
-	return Server::get(IURLGenerator::class)->linkToDocs($key);
209
+    return Server::get(IURLGenerator::class)->linkToDocs($key);
210 210
 }
211 211
 
212 212
 /**
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
  * For further information have a look at \OCP\IURLGenerator::imagePath
219 219
  */
220 220
 function image_path($app, $image) {
221
-	return Server::get(IURLGenerator::class)->imagePath($app, $image);
221
+    return Server::get(IURLGenerator::class)->imagePath($app, $image);
222 222
 }
223 223
 
224 224
 /**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
  * @return string link to the image
228 228
  */
229 229
 function mimetype_icon($mimetype) {
230
-	return Server::get(IMimeTypeDetector::class)->mimeTypeIcon($mimetype);
230
+    return Server::get(IMimeTypeDetector::class)->mimeTypeIcon($mimetype);
231 231
 }
232 232
 
233 233
 /**
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
  * @return string link to the preview
238 238
  */
239 239
 function preview_icon($path) {
240
-	return Server::get(IURLGenerator::class)->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
240
+    return Server::get(IURLGenerator::class)->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
241 241
 }
242 242
 
243 243
 /**
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * @return string
247 247
  */
248 248
 function publicPreview_icon($path, $token) {
249
-	return Server::get(IURLGenerator::class)->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]);
249
+    return Server::get(IURLGenerator::class)->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]);
250 250
 }
251 251
 
252 252
 /**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
  * For further information have a look at Util::humanFileSize
259 259
  */
260 260
 function human_file_size($bytes) {
261
-	return Util::humanFileSize($bytes);
261
+    return Util::humanFileSize($bytes);
262 262
 }
263 263
 
264 264
 /**
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
  * @return int timestamp without time value
268 268
  */
269 269
 function strip_time($timestamp) {
270
-	$date = new \DateTime("@{$timestamp}");
271
-	$date->setTime(0, 0, 0);
272
-	return (int)$date->format('U');
270
+    $date = new \DateTime("@{$timestamp}");
271
+    $date->setTime(0, 0, 0);
272
+    return (int)$date->format('U');
273 273
 }
274 274
 
275 275
 /**
@@ -281,12 +281,12 @@  discard block
 block discarded – undo
281 281
  * @return string timestamp
282 282
  */
283 283
 function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false): string {
284
-	$formatter = Server::get(IDateTimeFormatter::class);
284
+    $formatter = Server::get(IDateTimeFormatter::class);
285 285
 
286
-	if ($dateOnly) {
287
-		return $formatter->formatDateSpan($timestamp, $fromTime);
288
-	}
289
-	return $formatter->formatTimeSpan($timestamp, $fromTime);
286
+    if ($dateOnly) {
287
+        return $formatter->formatDateSpan($timestamp, $fromTime);
288
+    }
289
+    return $formatter->formatTimeSpan($timestamp, $fromTime);
290 290
 }
291 291
 
292 292
 /**
@@ -295,29 +295,29 @@  discard block
 block discarded – undo
295 295
  * @param array $params
296 296
  */
297 297
 function html_select_options($options, $selected, $params = []): string {
298
-	if (!is_array($selected)) {
299
-		$selected = [$selected];
300
-	}
301
-	if (isset($params['combine']) && $params['combine']) {
302
-		$options = array_combine($options, $options);
303
-	}
304
-	$value_name = $label_name = false;
305
-	if (isset($params['value'])) {
306
-		$value_name = $params['value'];
307
-	}
308
-	if (isset($params['label'])) {
309
-		$label_name = $params['label'];
310
-	}
311
-	$html = '';
312
-	foreach ($options as $value => $label) {
313
-		if ($value_name && is_array($label)) {
314
-			$value = $label[$value_name];
315
-		}
316
-		if ($label_name && is_array($label)) {
317
-			$label = $label[$label_name];
318
-		}
319
-		$select = in_array($value, $selected) ? ' selected="selected"' : '';
320
-		$html .= '<option value="' . Util::sanitizeHTML($value) . '"' . $select . '>' . Util::sanitizeHTML($label) . '</option>' . "\n";
321
-	}
322
-	return $html;
298
+    if (!is_array($selected)) {
299
+        $selected = [$selected];
300
+    }
301
+    if (isset($params['combine']) && $params['combine']) {
302
+        $options = array_combine($options, $options);
303
+    }
304
+    $value_name = $label_name = false;
305
+    if (isset($params['value'])) {
306
+        $value_name = $params['value'];
307
+    }
308
+    if (isset($params['label'])) {
309
+        $label_name = $params['label'];
310
+    }
311
+    $html = '';
312
+    foreach ($options as $value => $label) {
313
+        if ($value_name && is_array($label)) {
314
+            $value = $label[$value_name];
315
+        }
316
+        if ($label_name && is_array($label)) {
317
+            $label = $label[$label_name];
318
+        }
319
+        $select = in_array($value, $selected) ? ' selected="selected"' : '';
320
+        $html .= '<option value="' . Util::sanitizeHTML($value) . '"' . $select . '>' . Util::sanitizeHTML($label) . '</option>' . "\n";
321
+    }
322
+    return $html;
323 323
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 function emit_css_tag($href, $opts = ''): void {
29 29
 	$s = '<link rel="stylesheet"';
30 30
 	if (!empty($href)) {
31
-		$s .= ' href="' . $href . '"';
31
+		$s .= ' href="'.$href.'"';
32 32
 	}
33 33
 	if (!empty($opts)) {
34
-		$s .= ' ' . $opts;
34
+		$s .= ' '.$opts;
35 35
 	}
36
-	print_unescaped($s . ">\n");
36
+	print_unescaped($s.">\n");
37 37
 }
38 38
 
39 39
 /**
@@ -61,18 +61,18 @@  discard block
 block discarded – undo
61 61
 	$nonceManager = Server::get(ContentSecurityPolicyNonceManager::class);
62 62
 
63 63
 	$defer_str = $content_type === '' ? ' defer' : ''; // "defer" only works with classic scripts
64
-	$type = $content_type !== '' ? ' type="' . $content_type . '"' : '';
64
+	$type = $content_type !== '' ? ' type="'.$content_type.'"' : '';
65 65
 
66
-	$s = '<script nonce="' . $nonceManager->getNonce() . '"' . $type;
66
+	$s = '<script nonce="'.$nonceManager->getNonce().'"'.$type;
67 67
 	if (!empty($src)) {
68 68
 		// emit script tag for deferred loading from $src
69
-		$s .= $defer_str . ' src="' . $src . '">';
69
+		$s .= $defer_str.' src="'.$src.'">';
70 70
 	} else {
71 71
 		// emit script tag for inline script from $script_content without defer (see MDN)
72
-		$s .= ">\n" . $script_content . "\n";
72
+		$s .= ">\n".$script_content."\n";
73 73
 	}
74 74
 	$s .= '</script>';
75
-	print_unescaped($s . "\n");
75
+	print_unescaped($s."\n");
76 76
 }
77 77
 
78 78
 /**
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 function strip_time($timestamp) {
270 270
 	$date = new \DateTime("@{$timestamp}");
271 271
 	$date->setTime(0, 0, 0);
272
-	return (int)$date->format('U');
272
+	return (int) $date->format('U');
273 273
 }
274 274
 
275 275
 /**
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 			$label = $label[$label_name];
318 318
 		}
319 319
 		$select = in_array($value, $selected) ? ' selected="selected"' : '';
320
-		$html .= '<option value="' . Util::sanitizeHTML($value) . '"' . $select . '>' . Util::sanitizeHTML($label) . '</option>' . "\n";
320
+		$html .= '<option value="'.Util::sanitizeHTML($value).'"'.$select.'>'.Util::sanitizeHTML($label).'</option>'."\n";
321 321
 	}
322 322
 	return $html;
323 323
 }
Please login to merge, or discard this patch.