Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 25... Línea 25...
25
 * @category   phpunit
25
 * @category   phpunit
26
 * @copyright  © 2006 The Open University
26
 * @copyright  © 2006 The Open University
27
 * @author     T.J.Hunt@open.ac.uk
27
 * @author     T.J.Hunt@open.ac.uk
28
 * @author     nicolas@moodle.com
28
 * @author     nicolas@moodle.com
29
 */
29
 */
30
class moodlelib_test extends \advanced_testcase {
30
final class moodlelib_test extends \advanced_testcase {
Línea 31... Línea 31...
31
 
31
 
32
    /**
32
    /**
33
     * Define a local decimal separator.
33
     * Define a local decimal separator.
34
     *
34
     *
Línea 53... Línea 53...
53
        // Ensure the new value is picked up and not taken from the cache.
53
        // Ensure the new value is picked up and not taken from the cache.
54
        $stringmanager = get_string_manager();
54
        $stringmanager = get_string_manager();
55
        $stringmanager->reset_caches(true);
55
        $stringmanager->reset_caches(true);
56
    }
56
    }
Línea 57... Línea 57...
57
 
57
 
58
    public function test_cleanremoteaddr() {
58
    public function test_cleanremoteaddr(): void {
59
        // IPv4.
59
        // IPv4.
60
        $this->assertNull(cleanremoteaddr('1023.121.234.1'));
60
        $this->assertNull(cleanremoteaddr('1023.121.234.1'));
Línea 61... Línea 61...
61
        $this->assertSame('123.121.234.1', cleanremoteaddr('123.121.234.01 '));
61
        $this->assertSame('123.121.234.1', cleanremoteaddr('123.121.234.01 '));
Línea 72... Línea 72...
72
        $this->assertSame('1:1:0:0:0:0:0:0', cleanremoteaddr('01:1::', false));
72
        $this->assertSame('1:1:0:0:0:0:0:0', cleanremoteaddr('01:1::', false));
73
        $this->assertSame('10:0:0:0:0:0:0:10', cleanremoteaddr('10::10', false));
73
        $this->assertSame('10:0:0:0:0:0:0:10', cleanremoteaddr('10::10', false));
74
        $this->assertSame('::ffff:c0a8:11', cleanremoteaddr('::ffff:192.168.1.1', true));
74
        $this->assertSame('::ffff:c0a8:11', cleanremoteaddr('::ffff:192.168.1.1', true));
75
    }
75
    }
Línea 76... Línea 76...
76
 
76
 
77
    public function test_address_in_subnet() {
77
    public function test_address_in_subnet(): void {
78
        // 1: xxx.xxx.xxx.xxx/nn or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/nnn (number of bits in net mask).
78
        // 1: xxx.xxx.xxx.xxx/nn or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/nnn (number of bits in net mask).
79
        $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.234.1/32'));
79
        $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.234.1/32'));
80
        $this->assertFalse(address_in_subnet('123.121.23.1', '123.121.23.0/32'));
80
        $this->assertFalse(address_in_subnet('123.121.23.1', '123.121.23.0/32'));
81
        $this->assertTrue(address_in_subnet('10.10.10.100',  '123.121.23.45/0'));
81
        $this->assertTrue(address_in_subnet('10.10.10.100',  '123.121.23.45/0'));
Línea 157... Línea 157...
157
 
157
 
158
        // Other incorrect input.
158
        // Other incorrect input.
159
        $this->assertFalse(address_in_subnet('123.123.123.123', ''));
159
        $this->assertFalse(address_in_subnet('123.123.123.123', ''));
Línea 160... Línea 160...
160
    }
160
    }
161
 
161
 
162
    public function test_fix_utf8() {
162
    public function test_fix_utf8(): void {
163
        // Make sure valid data including other types is not changed.
163
        // Make sure valid data including other types is not changed.
164
        $this->assertSame(null, fix_utf8(null));
164
        $this->assertSame(null, fix_utf8(null));
165
        $this->assertSame(1, fix_utf8(1));
165
        $this->assertSame(1, fix_utf8(1));
Línea 180... Línea 180...
180
        // Invalid utf8 string.
180
        // Invalid utf8 string.
181
        $this->assertSame('aš', fix_utf8('a'.chr(130).'š'), 'This fails with buggy iconv() when mbstring extenstion is not available as fallback.');
181
        $this->assertSame('aš', fix_utf8('a'.chr(130).'š'), 'This fails with buggy iconv() when mbstring extenstion is not available as fallback.');
182
        $this->assertSame('Hello ', fix_utf8('Hello ï¿¿'));
182
        $this->assertSame('Hello ', fix_utf8('Hello ï¿¿'));
183
    }
183
    }
Línea 184... Línea 184...
184
 
184
 
185
    public function test_optional_param() {
185
    public function test_optional_param(): void {
Línea 186... Línea 186...
186
        global $CFG;
186
        global $CFG;
187
 
187
 
188
        $_POST['username'] = 'post_user';
188
        $_POST['username'] = 'post_user';
Línea 202... Línea 202...
202
            $this->fail('coding_exception expected');
202
            $this->fail('coding_exception expected');
203
        } catch (\coding_exception $e) {
203
        } catch (\coding_exception $e) {
204
        }
204
        }
205
    }
205
    }
Línea 206... Línea 206...
206
 
206
 
207
    public function test_optional_param_array() {
207
    public function test_optional_param_array(): void {
Línea 208... Línea 208...
208
        global $CFG;
208
        global $CFG;
209
 
209
 
210
        $_POST['username'] = array('a'=>'post_user');
210
        $_POST['username'] = array('a'=>'post_user');
Línea 235... Línea 235...
235
        $_POST['username'] = array('abc123_;-/*-+ '=>'arrggh', 'a1_-'=>'post_user');
235
        $_POST['username'] = array('abc123_;-/*-+ '=>'arrggh', 'a1_-'=>'post_user');
236
        $this->assertSame(array('a1_-'=>'post_user'), optional_param_array('username', array(), PARAM_RAW));
236
        $this->assertSame(array('a1_-'=>'post_user'), optional_param_array('username', array(), PARAM_RAW));
237
        $this->assertDebuggingCalled();
237
        $this->assertDebuggingCalled();
238
    }
238
    }
Línea 239... Línea 239...
239
 
239
 
240
    public function test_required_param() {
240
    public function test_required_param(): void {
241
        $_POST['username'] = 'post_user';
241
        $_POST['username'] = 'post_user';
242
        $_GET['username'] = 'get_user';
242
        $_GET['username'] = 'get_user';
Línea 243... Línea 243...
243
        $this->assertSame('post_user', required_param('username', PARAM_RAW));
243
        $this->assertSame('post_user', required_param('username', PARAM_RAW));
Línea 266... Línea 266...
266
            $this->fail('coding_exception expected');
266
            $this->fail('coding_exception expected');
267
        } catch (\coding_exception $e) {
267
        } catch (\coding_exception $e) {
268
        }
268
        }
269
    }
269
    }
Línea 270... Línea 270...
270
 
270
 
271
    public function test_required_param_array() {
271
    public function test_required_param_array(): void {
Línea 272... Línea 272...
272
        global $CFG;
272
        global $CFG;
273
 
273
 
274
        $_POST['username'] = array('a'=>'post_user');
274
        $_POST['username'] = array('a'=>'post_user');
Línea 304... Línea 304...
304
 
304
 
305
    /**
305
    /**
306
     * @covers \core\param
306
     * @covers \core\param
307
     * @covers \clean_param
307
     * @covers \clean_param
308
     */
308
     */
309
    public function test_clean_param() {
309
    public function test_clean_param(): void {
310
        // Forbid objects and arrays.
310
        // Forbid objects and arrays.
311
        try {
311
        try {
312
            clean_param(array('x', 'y'), PARAM_RAW);
312
            clean_param(array('x', 'y'), PARAM_RAW);
313
            $this->fail('coding_exception expected');
313
            $this->fail('coding_exception expected');
Línea 334... Línea 334...
334
 
334
 
335
    /**
335
    /**
336
     * @covers \core\param
336
     * @covers \core\param
337
     * @covers \clean_param
337
     * @covers \clean_param
338
     */
338
     */
339
    public function test_clean_param_array() {
339
    public function test_clean_param_array(): void {
340
        $this->assertSame(array(), clean_param_array(null, PARAM_RAW));
340
        $this->assertSame(array(), clean_param_array(null, PARAM_RAW));
341
        $this->assertSame(array('a', 'b'), clean_param_array(array('a', 'b'), PARAM_RAW));
341
        $this->assertSame(array('a', 'b'), clean_param_array(array('a', 'b'), PARAM_RAW));
Línea 342... Línea 342...
342
        $this->assertSame(array('a', array('b')), clean_param_array(array('a', array('b')), PARAM_RAW, true));
342
        $this->assertSame(array('a', array('b')), clean_param_array(array('a', array('b')), PARAM_RAW, true));
Línea 361... Línea 361...
361
 
361
 
362
    /**
362
    /**
363
     * @covers \core\param
363
     * @covers \core\param
364
     * @covers \clean_param
364
     * @covers \clean_param
365
     */
365
     */
366
    public function test_clean_param_raw() {
366
    public function test_clean_param_raw(): void {
367
        $this->assertSame(
367
        $this->assertSame(
368
            '#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)',
368
            '#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)',
369
            clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_RAW));
369
            clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_RAW));
370
        $this->assertSame(null, clean_param(null, PARAM_RAW));
370
        $this->assertSame(null, clean_param(null, PARAM_RAW));
Línea 371... Línea 371...
371
    }
371
    }
372
 
372
 
373
    /**
373
    /**
374
     * @covers \core\param
374
     * @covers \core\param
375
     * @covers \clean_param
375
     * @covers \clean_param
376
     */
376
     */
377
    public function test_clean_param_trim() {
377
    public function test_clean_param_trim(): void {
378
        $this->assertSame('Frog toad', clean_param("   Frog toad   \r\n  ", PARAM_RAW_TRIMMED));
378
        $this->assertSame('Frog toad', clean_param("   Frog toad   \r\n  ", PARAM_RAW_TRIMMED));
Línea 379... Línea 379...
379
        $this->assertSame('', clean_param(null, PARAM_RAW_TRIMMED));
379
        $this->assertSame('', clean_param(null, PARAM_RAW_TRIMMED));
380
    }
380
    }
381
 
381
 
382
    /**
382
    /**
383
     * @covers \core\param
383
     * @covers \core\param
384
     * @covers \clean_param
384
     * @covers \clean_param
385
     */
385
     */
386
    public function test_clean_param_clean() {
386
    public function test_clean_param_clean(): void {
387
        // PARAM_CLEAN is an ugly hack, do not use in new code (skodak),
387
        // PARAM_CLEAN is an ugly hack, do not use in new code (skodak),
388
        // instead use more specific type, or submit sothing that can be verified properly.
388
        // instead use more specific type, or submit sothing that can be verified properly.
Línea 393... Línea 393...
393
 
393
 
394
    /**
394
    /**
395
     * @covers \core\param
395
     * @covers \core\param
396
     * @covers \clean_param
396
     * @covers \clean_param
397
     */
397
     */
398
    public function test_clean_param_alpha() {
398
    public function test_clean_param_alpha(): void {
399
        $this->assertSame('DSFMOSDJ', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_ALPHA));
399
        $this->assertSame('DSFMOSDJ', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_ALPHA));
400
        $this->assertSame('', clean_param(null, PARAM_ALPHA));
400
        $this->assertSame('', clean_param(null, PARAM_ALPHA));
Línea 401... Línea 401...
401
    }
401
    }
402
 
402
 
403
    /**
403
    /**
404
     * @covers \core\param
404
     * @covers \core\param
405
     * @covers \clean_param
405
     * @covers \clean_param
406
     */
406
     */
407
    public function test_clean_param_alphanum() {
407
    public function test_clean_param_alphanum(): void {
408
        $this->assertSame('978942897DSFMOSDJ', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_ALPHANUM));
408
        $this->assertSame('978942897DSFMOSDJ', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_ALPHANUM));
Línea 409... Línea 409...
409
        $this->assertSame('', clean_param(null, PARAM_ALPHANUM));
409
        $this->assertSame('', clean_param(null, PARAM_ALPHANUM));
410
    }
410
    }
411
 
411
 
412
    /**
412
    /**
413
     * @covers \core\param
413
     * @covers \core\param
414
     * @covers \clean_param
414
     * @covers \clean_param
415
     */
415
     */
416
    public function test_clean_param_alphaext() {
416
    public function test_clean_param_alphaext(): void {
Línea 417... Línea 417...
417
        $this->assertSame('DSFMOSDJ', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_ALPHAEXT));
417
        $this->assertSame('DSFMOSDJ', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_ALPHAEXT));
418
        $this->assertSame('', clean_param(null, PARAM_ALPHAEXT));
418
        $this->assertSame('', clean_param(null, PARAM_ALPHAEXT));
419
    }
419
    }
420
 
420
 
421
    /**
421
    /**
422
     * @covers \core\param
422
     * @covers \core\param
423
     * @covers \clean_param
423
     * @covers \clean_param
424
     */
424
     */
Línea 425... Línea 425...
425
    public function test_clean_param_sequence() {
425
    public function test_clean_param_sequence(): void {
426
        $this->assertSame(',9789,42897', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_SEQUENCE));
426
        $this->assertSame(',9789,42897', clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_SEQUENCE));
427
        $this->assertSame('', clean_param(null, PARAM_SEQUENCE));
427
        $this->assertSame('', clean_param(null, PARAM_SEQUENCE));
428
    }
428
    }
429
 
429
 
430
    /**
430
    /**
431
     * @covers \core\param
431
     * @covers \core\param
432
     * @covers \clean_param
432
     * @covers \clean_param
433
     */
433
     */
434
    public function test_clean_param_component() {
434
    public function test_clean_param_component(): void {
Línea 462... Línea 462...
462
 
462
 
463
    /**
463
    /**
464
     * @covers \core\param
464
     * @covers \core\param
465
     * @covers \clean_param
465
     * @covers \clean_param
466
     */
466
     */
Línea 467... Línea 467...
467
    public function test_clean_param_localisedfloat() {
467
    public function test_clean_param_localisedfloat(): void {
468
 
468
 
469
        $this->assertSame(0.5, clean_param('0.5', PARAM_LOCALISEDFLOAT));
469
        $this->assertSame(0.5, clean_param('0.5', PARAM_LOCALISEDFLOAT));
470
        $this->assertSame(false, clean_param('0X5', PARAM_LOCALISEDFLOAT));
470
        $this->assertSame(false, clean_param('0X5', PARAM_LOCALISEDFLOAT));
Línea 495... Línea 495...
495
        $this->assertSame(false, clean_param('1X000X5', PARAM_LOCALISEDFLOAT));
495
        $this->assertSame(false, clean_param('1X000X5', PARAM_LOCALISEDFLOAT));
496
        $this->assertSame(false, clean_param('nan', PARAM_LOCALISEDFLOAT));
496
        $this->assertSame(false, clean_param('nan', PARAM_LOCALISEDFLOAT));
497
        $this->assertSame(false, clean_param('10X6blah', PARAM_LOCALISEDFLOAT));
497
        $this->assertSame(false, clean_param('10X6blah', PARAM_LOCALISEDFLOAT));
498
    }
498
    }
Línea 499... Línea 499...
499
 
499
 
500
    public function test_is_valid_plugin_name() {
500
    public function test_is_valid_plugin_name(): void {
501
        $this->assertTrue(is_valid_plugin_name('forum'));
501
        $this->assertTrue(is_valid_plugin_name('forum'));
502
        $this->assertTrue(is_valid_plugin_name('forum2'));
502
        $this->assertTrue(is_valid_plugin_name('forum2'));
503
        $this->assertTrue(is_valid_plugin_name('feedback360'));
503
        $this->assertTrue(is_valid_plugin_name('feedback360'));
504
        $this->assertTrue(is_valid_plugin_name('online_users'));
504
        $this->assertTrue(is_valid_plugin_name('online_users'));
Línea 515... Línea 515...
515
 
515
 
516
    /**
516
    /**
517
     * @covers \core\param
517
     * @covers \core\param
518
     * @covers \clean_param
518
     * @covers \clean_param
519
     */
519
     */
520
    public function test_clean_param_plugin() {
520
    public function test_clean_param_plugin(): void {
521
        // Please note the cleaning of plugin names is very strict, no guessing here.
521
        // Please note the cleaning of plugin names is very strict, no guessing here.
522
        $this->assertSame('forum', clean_param('forum', PARAM_PLUGIN));
522
        $this->assertSame('forum', clean_param('forum', PARAM_PLUGIN));
523
        $this->assertSame('forum2', clean_param('forum2', PARAM_PLUGIN));
523
        $this->assertSame('forum2', clean_param('forum2', PARAM_PLUGIN));
524
        $this->assertSame('feedback360', clean_param('feedback360', PARAM_PLUGIN));
524
        $this->assertSame('feedback360', clean_param('feedback360', PARAM_PLUGIN));
Línea 537... Línea 537...
537
 
537
 
538
    /**
538
    /**
539
     * @covers \core\param
539
     * @covers \core\param
540
     * @covers \clean_param
540
     * @covers \clean_param
541
     */
541
     */
542
    public function test_clean_param_area() {
542
    public function test_clean_param_area(): void {
543
        // Please note the cleaning of area names is very strict, no guessing here.
543
        // Please note the cleaning of area names is very strict, no guessing here.
544
        $this->assertSame('something', clean_param('something', PARAM_AREA));
544
        $this->assertSame('something', clean_param('something', PARAM_AREA));
545
        $this->assertSame('something2', clean_param('something2', PARAM_AREA));
545
        $this->assertSame('something2', clean_param('something2', PARAM_AREA));
546
        $this->assertSame('some_thing', clean_param('some_thing', PARAM_AREA));
546
        $this->assertSame('some_thing', clean_param('some_thing', PARAM_AREA));
Línea 558... Línea 558...
558
 
558
 
559
    /**
559
    /**
560
     * @covers \core\param
560
     * @covers \core\param
561
     * @covers \clean_param
561
     * @covers \clean_param
562
     */
562
     */
563
    public function test_clean_param_text() {
563
    public function test_clean_param_text(): void {
564
        // Standard.
564
        // Standard.
565
        $this->assertSame('xx<lang lang="en">aa</lang><lang lang="yy">pp</lang>', clean_param('xx<lang lang="en">aa</lang><lang lang="yy">pp</lang>', PARAM_TEXT));
565
        $this->assertSame('xx<lang lang="en">aa</lang><lang lang="yy">pp</lang>', clean_param('xx<lang lang="en">aa</lang><lang lang="yy">pp</lang>', PARAM_TEXT));
566
        $this->assertSame('<span lang="en" class="multilang">aa</span><span lang="xy" class="multilang">bb</span>', clean_param('<span lang="en" class="multilang">aa</span><span lang="xy" class="multilang">bb</span>', PARAM_TEXT));
566
        $this->assertSame('<span lang="en" class="multilang">aa</span><span lang="xy" class="multilang">bb</span>', clean_param('<span lang="en" class="multilang">aa</span><span lang="xy" class="multilang">bb</span>', PARAM_TEXT));
567
        $this->assertSame('xx<lang lang="en">aa'."\n".'</lang><lang lang="yy">pp</lang>', clean_param('xx<lang lang="en">aa'."\n".'</lang><lang lang="yy">pp</lang>', PARAM_TEXT));
567
        $this->assertSame('xx<lang lang="en">aa'."\n".'</lang><lang lang="yy">pp</lang>', clean_param('xx<lang lang="en">aa'."\n".'</lang><lang lang="yy">pp</lang>', PARAM_TEXT));
Línea 616... Línea 616...
616
 
616
 
617
    /**
617
    /**
618
     * @covers \core\param
618
     * @covers \core\param
619
     * @covers \clean_param
619
     * @covers \clean_param
620
     */
620
     */
621
    public function test_clean_param_url() {
621
    public function test_clean_param_url(): void {
622
        // Test PARAM_URL and PARAM_LOCALURL a bit.
622
        // Test PARAM_URL and PARAM_LOCALURL a bit.
623
        // Valid URLs.
623
        // Valid URLs.
624
        $this->assertSame('http://google.com/', clean_param('http://google.com/', PARAM_URL));
624
        $this->assertSame('http://google.com/', clean_param('http://google.com/', PARAM_URL));
625
        $this->assertSame('http://some.very.long.and.silly.domain/with/a/path/', clean_param('http://some.very.long.and.silly.domain/with/a/path/', PARAM_URL));
625
        $this->assertSame('http://some.very.long.and.silly.domain/with/a/path/', clean_param('http://some.very.long.and.silly.domain/with/a/path/', PARAM_URL));
Línea 646... Línea 646...
646
 
646
 
647
    /**
647
    /**
648
     * @covers \core\param
648
     * @covers \core\param
649
     * @covers \clean_param
649
     * @covers \clean_param
650
     */
650
     */
651
    public function test_clean_param_localurl() {
651
    public function test_clean_param_localurl(): void {
Línea 652... Línea 652...
652
        global $CFG;
652
        global $CFG;
Línea 653... Línea 653...
653
 
653
 
Línea 693... Línea 693...
693
 
693
 
694
    /**
694
    /**
695
     * @covers \core\param
695
     * @covers \core\param
696
     * @covers \clean_param
696
     * @covers \clean_param
697
     */
697
     */
698
    public function test_clean_param_file() {
698
    public function test_clean_param_file(): void {
699
        $this->assertSame('correctfile.txt', clean_param('correctfile.txt', PARAM_FILE));
699
        $this->assertSame('correctfile.txt', clean_param('correctfile.txt', PARAM_FILE));
700
        $this->assertSame('badfile.txt', clean_param('b\'a<d`\\/fi:l>e.t"x|t', PARAM_FILE));
700
        $this->assertSame('badfile.txt', clean_param('b\'a<d`\\/fi:l>e.t"x|t', PARAM_FILE));
701
        $this->assertSame('..parentdirfile.txt', clean_param('../parentdirfile.txt', PARAM_FILE));
701
        $this->assertSame('..parentdirfile.txt', clean_param('../parentdirfile.txt', PARAM_FILE));
702
        $this->assertSame('....grandparentdirfile.txt', clean_param('../../grandparentdirfile.txt', PARAM_FILE));
702
        $this->assertSame('....grandparentdirfile.txt', clean_param('../../grandparentdirfile.txt', PARAM_FILE));
Línea 729... Línea 729...
729
 
729
 
730
    /**
730
    /**
731
     * @covers \core\param
731
     * @covers \core\param
732
     * @covers \clean_param
732
     * @covers \clean_param
733
     */
733
     */
734
    public function test_clean_param_path() {
734
    public function test_clean_param_path(): void {
735
        $this->assertSame('correctfile.txt', clean_param('correctfile.txt', PARAM_PATH));
735
        $this->assertSame('correctfile.txt', clean_param('correctfile.txt', PARAM_PATH));
736
        $this->assertSame('bad/file.txt', clean_param('b\'a<d`\\/fi:l>e.t"x|t', PARAM_PATH));
736
        $this->assertSame('bad/file.txt', clean_param('b\'a<d`\\/fi:l>e.t"x|t', PARAM_PATH));
737
        $this->assertSame('/parentdirfile.txt', clean_param('../parentdirfile.txt', PARAM_PATH));
737
        $this->assertSame('/parentdirfile.txt', clean_param('../parentdirfile.txt', PARAM_PATH));
738
        $this->assertSame('/grandparentdirfile.txt', clean_param('../../grandparentdirfile.txt', PARAM_PATH));
738
        $this->assertSame('/grandparentdirfile.txt', clean_param('../../grandparentdirfile.txt', PARAM_PATH));
Línea 754... Línea 754...
754
 
754
 
755
    /**
755
    /**
756
     * @covers \core\param
756
     * @covers \core\param
757
     * @covers \clean_param
757
     * @covers \clean_param
758
     */
758
     */
759
    public function test_clean_param_safepath() {
759
    public function test_clean_param_safepath(): void {
760
        $this->assertSame('folder/file', clean_param('folder/file', PARAM_SAFEPATH));
760
        $this->assertSame('folder/file', clean_param('folder/file', PARAM_SAFEPATH));
761
        $this->assertSame('folder//file', clean_param('folder/../file', PARAM_SAFEPATH));
761
        $this->assertSame('folder//file', clean_param('folder/../file', PARAM_SAFEPATH));
762
        $this->assertSame('', clean_param(null, PARAM_SAFEPATH));
762
        $this->assertSame('', clean_param(null, PARAM_SAFEPATH));
Línea 763... Línea 763...
763
    }
763
    }
764
 
764
 
765
    /**
765
    /**
766
     * @covers \core\param
766
     * @covers \core\param
767
     * @covers \clean_param
767
     * @covers \clean_param
768
     */
768
     */
769
    public function test_clean_param_username() {
769
    public function test_clean_param_username(): void {
Línea 770... Línea 770...
770
        global $CFG;
770
        global $CFG;
771
        $currentstatus =  $CFG->extendedusernamechars;
771
        $currentstatus =  $CFG->extendedusernamechars;
Línea 803... Línea 803...
803
 
803
 
804
    /**
804
    /**
805
     * @covers \core\param
805
     * @covers \core\param
806
     * @covers \clean_param
806
     * @covers \clean_param
807
     */
807
     */
808
    public function test_clean_param_stringid() {
808
    public function test_clean_param_stringid(): void {
809
        // Test string identifiers validation.
809
        // Test string identifiers validation.
810
        // Valid strings.
810
        // Valid strings.
811
        $this->assertSame('validstring', clean_param('validstring', PARAM_STRINGID));
811
        $this->assertSame('validstring', clean_param('validstring', PARAM_STRINGID));
812
        $this->assertSame('mod/foobar:valid_capability', clean_param('mod/foobar:valid_capability', PARAM_STRINGID));
812
        $this->assertSame('mod/foobar:valid_capability', clean_param('mod/foobar:valid_capability', PARAM_STRINGID));
Línea 824... Línea 824...
824
 
824
 
825
    /**
825
    /**
826
     * @covers \core\param
826
     * @covers \core\param
827
     * @covers \clean_param
827
     * @covers \clean_param
828
     */
828
     */
829
    public function test_clean_param_timezone() {
829
    public function test_clean_param_timezone(): void {
830
        // Test timezone validation.
830
        // Test timezone validation.
831
        $testvalues = array (
831
        $testvalues = array (
832
            'America/Jamaica'                => 'America/Jamaica',
832
            'America/Jamaica'                => 'America/Jamaica',
833
            'America/Argentina/Cordoba'      => 'America/Argentina/Cordoba',
833
            'America/Argentina/Cordoba'      => 'America/Argentina/Cordoba',
Línea 858... Línea 858...
858
            '13.5'                           => '',
858
            '13.5'                           => '',
859
            '+13.5'                          => '',
859
            '+13.5'                          => '',
860
            '-13.5'                          => '',
860
            '-13.5'                          => '',
861
            '0.2'                            => '',
861
            '0.2'                            => '',
862
            ''                               => '',
862
            ''                               => '',
863
            null                             => '',
-
 
864
        );
863
        );
Línea 865... Línea 864...
865
 
864
 
866
        foreach ($testvalues as $testvalue => $expectedvalue) {
865
        foreach ($testvalues as $testvalue => $expectedvalue) {
867
            $actualvalue = clean_param($testvalue, PARAM_TIMEZONE);
866
            $actualvalue = clean_param($testvalue, PARAM_TIMEZONE);
868
            $this->assertEquals($expectedvalue, $actualvalue);
867
            $this->assertEquals($expectedvalue, $actualvalue);
-
 
868
        }
-
 
869
 
-
 
870
        // Test for null.
869
        }
871
        $this->assertEquals('', clean_param(null, PARAM_TIMEZONE));
Línea 870... Línea 872...
870
    }
872
    }
871
 
873
 
872
    /**
874
    /**
873
     * @covers \core\param
875
     * @covers \core\param
874
     * @covers \clean_param
876
     * @covers \clean_param
875
     */
877
     */
876
    public function test_clean_param_null_argument() {
878
    public function test_clean_param_null_argument(): void {
877
        $this->assertEquals(0, clean_param(null, PARAM_INT));
879
        $this->assertEquals(0, clean_param(null, PARAM_INT));
878
        $this->assertEquals(0, clean_param(null, PARAM_FLOAT));
880
        $this->assertEquals(0, clean_param(null, PARAM_FLOAT));
879
        $this->assertEquals(0, clean_param(null, PARAM_LOCALISEDFLOAT));
881
        $this->assertEquals(0, clean_param(null, PARAM_LOCALISEDFLOAT));
Línea 891... Línea 893...
891
        $this->assertEquals('', clean_param(null, PARAM_LANG));
893
        $this->assertEquals('', clean_param(null, PARAM_LANG));
892
        $this->assertEquals('', clean_param(null, PARAM_THEME));
894
        $this->assertEquals('', clean_param(null, PARAM_THEME));
893
        $this->assertEquals('', clean_param(null, PARAM_EMAIL));
895
        $this->assertEquals('', clean_param(null, PARAM_EMAIL));
894
    }
896
    }
Línea 895... Línea 897...
895
 
897
 
896
    public function test_validate_param() {
898
    public function test_validate_param(): void {
897
        try {
899
        try {
898
            $param = validate_param('11a', PARAM_INT);
900
            $param = validate_param('11a', PARAM_INT);
899
            $this->fail('invalid_parameter_exception expected');
901
            $this->fail('invalid_parameter_exception expected');
900
        } catch (\moodle_exception $ex) {
902
        } catch (\moodle_exception $ex) {
Línea 973... Línea 975...
973
        } catch (\moodle_exception $ex) {
975
        } catch (\moodle_exception $ex) {
974
            $this->assertInstanceOf('invalid_parameter_exception', $ex);
976
            $this->assertInstanceOf('invalid_parameter_exception', $ex);
975
        }
977
        }
976
    }
978
    }
Línea 977... Línea 979...
977
 
979
 
978
    public function test_shorten_text_no_tags_already_short_enough() {
980
    public function test_shorten_text_no_tags_already_short_enough(): void {
979
        // ......12345678901234567890123456.
981
        // ......12345678901234567890123456.
980
        $text = "short text already no tags";
982
        $text = "short text already no tags";
981
        $this->assertSame($text, shorten_text($text));
983
        $this->assertSame($text, shorten_text($text));
Línea 982... Línea 984...
982
    }
984
    }
983
 
985
 
984
    public function test_shorten_text_with_tags_already_short_enough() {
986
    public function test_shorten_text_with_tags_already_short_enough(): void {
985
        // .........123456...7890....12345678.......901234567.
987
        // .........123456...7890....12345678.......901234567.
986
        $text = "<p>short <b>text</b> already</p><p>with tags</p>";
988
        $text = "<p>short <b>text</b> already</p><p>with tags</p>";
Línea 987... Línea 989...
987
        $this->assertSame($text, shorten_text($text));
989
        $this->assertSame($text, shorten_text($text));
988
    }
990
    }
989
 
991
 
990
    public function test_shorten_text_no_tags_needs_shortening() {
992
    public function test_shorten_text_no_tags_needs_shortening(): void {
991
        // Default truncation is after 30 chars, but allowing 3 for the final '...'.
993
        // Default truncation is after 30 chars, but allowing 3 for the final '...'.
992
        // ......12345678901234567890123456789023456789012345678901234.
994
        // ......12345678901234567890123456789023456789012345678901234.
Línea 993... Línea 995...
993
        $text = "long text without any tags blah de blah blah blah what";
995
        $text = "long text without any tags blah de blah blah blah what";
994
        $this->assertSame('long text without any tags ...', shorten_text($text));
996
        $this->assertSame('long text without any tags ...', shorten_text($text));
995
    }
997
    }
996
 
998
 
997
    public function test_shorten_text_with_tags_needs_shortening() {
999
    public function test_shorten_text_with_tags_needs_shortening(): void {
998
        // .......................................123456789012345678901234567890...
1000
        // .......................................123456789012345678901234567890...
999
        $text = "<div class='frog'><p><blockquote>Long text with tags that will ".
1001
        $text = "<div class='frog'><p><blockquote>Long text with tags that will ".
Línea 1000... Línea 1002...
1000
            "be chopped off but <b>should be added back again</b></blockquote></p></div>";
1002
            "be chopped off but <b>should be added back again</b></blockquote></p></div>";
1001
        $this->assertEquals("<div class='frog'><p><blockquote>Long text with " .
1003
        $this->assertEquals("<div class='frog'><p><blockquote>Long text with " .
1002
            "tags that ...</blockquote></p></div>", shorten_text($text));
1004
            "tags that ...</blockquote></p></div>", shorten_text($text));
1003
    }
1005
    }
1004
 
1006
 
1005
    public function test_shorten_text_with_tags_and_html_comment() {
1007
    public function test_shorten_text_with_tags_and_html_comment(): void {
1006
        $text = "<div class='frog'><p><blockquote><!--[if !IE]><!-->Long text with ".
1008
        $text = "<div class='frog'><p><blockquote><!--[if !IE]><!-->Long text with ".
Línea 1007... Línea 1009...
1007
            "tags that will<!--<![endif]--> ".
1009
            "tags that will<!--<![endif]--> ".
1008
            "be chopped off but <b>should be added back again</b></blockquote></p></div>";
1010
            "be chopped off but <b>should be added back again</b></blockquote></p></div>";
1009
        $this->assertEquals("<div class='frog'><p><blockquote><!--[if !IE]><!-->Long text with " .
1011
        $this->assertEquals("<div class='frog'><p><blockquote><!--[if !IE]><!-->Long text with " .
1010
            "tags that ...<!--<![endif]--></blockquote></p></div>", shorten_text($text));
1012
            "tags that ...<!--<![endif]--></blockquote></p></div>", shorten_text($text));
1011
    }
1013
    }
1012
 
1014
 
1013
    public function test_shorten_text_with_entities() {
1015
    public function test_shorten_text_with_entities(): void {
1014
        // Remember to allow 3 chars for the final '...'.
1016
        // Remember to allow 3 chars for the final '...'.
Línea 1015... Línea 1017...
1015
        // ......123456789012345678901234567_____890...
1017
        // ......123456789012345678901234567_____890...
1016
        $text = "some text which shouldn't &nbsp; break there";
1018
        $text = "some text which shouldn't &nbsp; break there";
1017
        $this->assertSame("some text which shouldn't &nbsp; ...", shorten_text($text, 31));
1019
        $this->assertSame("some text which shouldn't &nbsp; ...", shorten_text($text, 31));
1018
        $this->assertSame("some text which shouldn't &nbsp;...", shorten_text($text, 30));
1020
        $this->assertSame("some text which shouldn't &nbsp;...", shorten_text($text, 30));
1019
        $this->assertSame("some text which shouldn't ...", shorten_text($text, 29));
1021
        $this->assertSame("some text which shouldn't ...", shorten_text($text, 29));
1020
    }
1022
    }
Línea 1029... Línea 1031...
1029
            shorten_text($text, 42));
1031
            shorten_text($text, 42));
1030
        $this->assertSame("<h3>standard 'break-out' sub groups in TGs?</h3>&nbsp;...",
1032
        $this->assertSame("<h3>standard 'break-out' sub groups in TGs?</h3>&nbsp;...",
1031
            shorten_text($text, 43));
1033
            shorten_text($text, 43));
1032
    }
1034
    }
Línea 1033... Línea 1035...
1033
 
1035
 
1034
    public function test_shorten_text_no_spaces() {
1036
    public function test_shorten_text_no_spaces(): void {
1035
        // ..........123456789.
1037
        // ..........123456789.
1036
        $text = "<h1>123456789</h1>"; // A string with no convenient breaks.
1038
        $text = "<h1>123456789</h1>"; // A string with no convenient breaks.
1037
        $this->assertSame("<h1>12345...</h1>", shorten_text($text, 8));
1039
        $this->assertSame("<h1>12345...</h1>", shorten_text($text, 8));
Línea 1038... Línea 1040...
1038
    }
1040
    }
1039
 
1041
 
1040
    public function test_shorten_text_utf8_european() {
1042
    public function test_shorten_text_utf8_european(): void {
1041
        // Text without tags.
1043
        // Text without tags.
1042
        // ......123456789012345678901234567.
1044
        // ......123456789012345678901234567.
1043
        $text = "Žluťoučký koníček přeskočil";
1045
        $text = "Žluťoučký koníček přeskočil";
Línea 1062... Línea 1064...
1062
        $this->assertSame("<p>Žluťoučký koníček <b>přeskočil</b> pot...</p>", shorten_text($text, 34, true));
1064
        $this->assertSame("<p>Žluťoučký koníček <b>přeskočil</b> pot...</p>", shorten_text($text, 34, true));
1063
        // And in the middle of one tag.
1065
        // And in the middle of one tag.
1064
        $this->assertSame("<p>Žluťoučký koníček <b>přeskočil...</b></p>", shorten_text($text, 30, true));
1066
        $this->assertSame("<p>Žluťoučký koníček <b>přeskočil...</b></p>", shorten_text($text, 30, true));
1065
    }
1067
    }
Línea 1066... Línea 1068...
1066
 
1068
 
1067
    public function test_shorten_text_utf8_oriental() {
1069
    public function test_shorten_text_utf8_oriental(): void {
1068
        // Japanese
1070
        // Japanese
1069
        // text without tags
1071
        // text without tags
1070
        // ......123456789012345678901234.
1072
        // ......123456789012345678901234.
1071
        $text = '言語設定言語設定abcdefghijkl';
1073
        $text = '言語設定言語設定abcdefghijkl';
Línea 1084... Línea 1086...
1084
        $this->assertSame("简体中文简体...", shorten_text($text, 9, false));
1086
        $this->assertSame("简体中文简体...", shorten_text($text, 9, false));
1085
        $this->assertSame("简体中文简体中文ab...", shorten_text($text, 13, true));
1087
        $this->assertSame("简体中文简体中文ab...", shorten_text($text, 13, true));
1086
        $this->assertSame("简体中文简体中文...", shorten_text($text, 13, false));
1088
        $this->assertSame("简体中文简体中文...", shorten_text($text, 13, false));
1087
    }
1089
    }
Línea 1088... Línea 1090...
1088
 
1090
 
1089
    public function test_shorten_text_multilang() {
1091
    public function test_shorten_text_multilang(): void {
1090
        // This is not necessaryily specific to multilang. The issue is really
1092
        // This is not necessaryily specific to multilang. The issue is really
1091
        // tags with attributes, where before we were generating invalid HTML
1093
        // tags with attributes, where before we were generating invalid HTML
1092
        // output like shorten_text('<span id="x" class="y">A</span> B', 1)
1094
        // output like shorten_text('<span id="x" class="y">A</span> B', 1)
1093
        // returning '<span id="x" ...</span>'. It is just that multilang
1095
        // returning '<span id="x" ...</span>'. It is just that multilang
Línea 1192... Línea 1194...
1192
     * @param string $filename
1194
     * @param string $filename
1193
     * @param int $length
1195
     * @param int $length
1194
     * @param string $expected
1196
     * @param string $expected
1195
     * @param boolean $includehash
1197
     * @param boolean $includehash
1196
     */
1198
     */
1197
    public function test_shorten_filename($filename, $length, $expected, $includehash) {
1199
    public function test_shorten_filename($filename, $length, $expected, $includehash): void {
1198
        if (null === $length) {
1200
        if (null === $length) {
1199
            $length = MAX_FILENAME_SIZE;
1201
            $length = MAX_FILENAME_SIZE;
1200
        }
1202
        }
Línea 1201... Línea 1203...
1201
 
1203
 
Línea 1323... Línea 1325...
1323
     * @param array $filenames
1325
     * @param array $filenames
1324
     * @param int $length
1326
     * @param int $length
1325
     * @param string $expected
1327
     * @param string $expected
1326
     * @param boolean $includehash
1328
     * @param boolean $includehash
1327
     */
1329
     */
1328
    public function test_shorten_filenames($filenames, $length, $expected, $includehash) {
1330
    public function test_shorten_filenames($filenames, $length, $expected, $includehash): void {
1329
        if (null === $length) {
1331
        if (null === $length) {
1330
            $length = MAX_FILENAME_SIZE;
1332
            $length = MAX_FILENAME_SIZE;
1331
        }
1333
        }
Línea 1332... Línea 1334...
1332
 
1334
 
1333
        $this->assertSame($expected, shorten_filenames($filenames, $length, $includehash));
1335
        $this->assertSame($expected, shorten_filenames($filenames, $length, $includehash));
Línea 1334... Línea 1336...
1334
    }
1336
    }
1335
 
1337
 
1336
    public function test_usergetdate() {
1338
    public function test_usergetdate(): void {
Línea 1337... Línea 1339...
1337
        global $USER, $CFG, $DB;
1339
        global $USER, $CFG, $DB;
Línea 1377... Línea 1379...
1377
        $this->assertDebuggingNotCalled();
1379
        $this->assertDebuggingNotCalled();
1378
        $this->assertSame(1970, usergetdate(null)['year']);
1380
        $this->assertSame(1970, usergetdate(null)['year']);
1379
        $this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
1381
        $this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
1380
    }
1382
    }
Línea 1381... Línea 1383...
1381
 
1383
 
1382
    public function test_mark_user_preferences_changed() {
1384
    public function test_mark_user_preferences_changed(): void {
1383
        $this->resetAfterTest();
1385
        $this->resetAfterTest();
1384
        $otheruser = $this->getDataGenerator()->create_user();
1386
        $otheruser = $this->getDataGenerator()->create_user();
Línea 1385... Línea 1387...
1385
        $otheruserid = $otheruser->id;
1387
        $otheruserid = $otheruser->id;
Línea 1389... Línea 1391...
1389
 
1391
 
1390
        $this->assertEquals(get_cache_flag('userpreferenceschanged', $otheruserid, time()-10), 1);
1392
        $this->assertEquals(get_cache_flag('userpreferenceschanged', $otheruserid, time()-10), 1);
1391
        set_cache_flag('userpreferenceschanged', $otheruserid, null);
1393
        set_cache_flag('userpreferenceschanged', $otheruserid, null);
Línea 1392... Línea 1394...
1392
    }
1394
    }
1393
 
1395
 
1394
    public function test_check_user_preferences_loaded() {
1396
    public function test_check_user_preferences_loaded(): void {
Línea 1395... Línea 1397...
1395
        global $DB;
1397
        global $DB;
1396
        $this->resetAfterTest();
1398
        $this->resetAfterTest();
Línea 1436... Línea 1438...
1436
        $this->assertCount(3, $user->preference);
1438
        $this->assertCount(3, $user->preference);
1437
        $this->assertSame('bbb', $user->preference['aaa']);
1439
        $this->assertSame('bbb', $user->preference['aaa']);
1438
        set_cache_flag('userpreferenceschanged', $user->id, null);
1440
        set_cache_flag('userpreferenceschanged', $user->id, null);
1439
    }
1441
    }
Línea 1440... Línea 1442...
1440
 
1442
 
1441
    public function test_set_user_preference() {
1443
    public function test_set_user_preference(): void {
1442
        global $DB, $USER;
1444
        global $DB, $USER;
Línea 1443... Línea 1445...
1443
        $this->resetAfterTest();
1445
        $this->resetAfterTest();
Línea 1541... Línea 1543...
1541
        } catch (\moodle_exception $ex) {
1543
        } catch (\moodle_exception $ex) {
1542
            $this->assertInstanceOf('coding_exception', $ex);
1544
            $this->assertInstanceOf('coding_exception', $ex);
1543
        }
1545
        }
1544
    }
1546
    }
Línea 1545... Línea 1547...
1545
 
1547
 
1546
    public function test_set_user_preference_for_current_user() {
1548
    public function test_set_user_preference_for_current_user(): void {
1547
        global $USER;
1549
        global $USER;
1548
        $this->resetAfterTest();
1550
        $this->resetAfterTest();
Línea 1549... Línea 1551...
1549
        $this->setAdminUser();
1551
        $this->setAdminUser();
1550
 
1552
 
1551
        set_user_preference('test_pref', 2);
1553
        set_user_preference('test_pref', 2);
1552
        set_user_preference('test_pref', 1, $USER->id);
1554
        set_user_preference('test_pref', 1, $USER->id);
Línea 1553... Línea 1555...
1553
        $this->assertEquals(1, get_user_preferences('test_pref'));
1555
        $this->assertEquals(1, get_user_preferences('test_pref'));
1554
    }
1556
    }
1555
 
1557
 
1556
    public function test_unset_user_preference_for_current_user() {
1558
    public function test_unset_user_preference_for_current_user(): void {
Línea 1557... Línea 1559...
1557
        global $USER;
1559
        global $USER;
Línea 1572... Línea 1574...
1572
     *
1574
     *
1573
     * Note: If you don't trust PHP TZ/DST support, can verify the
1575
     * Note: If you don't trust PHP TZ/DST support, can verify the
1574
     * harcoded expectations below with:
1576
     * harcoded expectations below with:
1575
     * http://www.tools4noobs.com/online_tools/unix_timestamp_to_datetime/
1577
     * http://www.tools4noobs.com/online_tools/unix_timestamp_to_datetime/
1576
     */
1578
     */
1577
    public function test_some_moodle_special_dst() {
1579
    public function test_some_moodle_special_dst(): void {
1578
        $stamp = 1365386400; // 2013/04/08 02:00:00 GMT/UTC.
1580
        $stamp = 1365386400; // 2013/04/08 02:00:00 GMT/UTC.
Línea 1579... Línea 1581...
1579
 
1581
 
1580
        // In Europe/Tallinn it was 2013/04/08 05:00:00.
1582
        // In Europe/Tallinn it was 2013/04/08 05:00:00.
1581
        $expectation = '2013/04/08 05:00:00';
1583
        $expectation = '2013/04/08 05:00:00';
Línea 1614... Línea 1616...
1614
        $moodleres = userdate($stamp, '%Y/%m/%d %H:%M:%S', 'America/St_Johns', false); // Moodle result.
1616
        $moodleres = userdate($stamp, '%Y/%m/%d %H:%M:%S', 'America/St_Johns', false); // Moodle result.
1615
        $this->assertSame($expectation, $phpres);
1617
        $this->assertSame($expectation, $phpres);
1616
        $this->assertSame($expectation, $moodleres);
1618
        $this->assertSame($expectation, $moodleres);
1617
    }
1619
    }
Línea 1618... Línea 1620...
1618
 
1620
 
1619
    public function test_userdate() {
1621
    public function test_userdate(): void {
1620
        global $USER, $CFG, $DB;
1622
        global $USER, $CFG, $DB;
Línea 1621... Línea 1623...
1621
        $this->resetAfterTest();
1623
        $this->resetAfterTest();
Línea 1732... Línea 1734...
1732
    }
1734
    }
Línea 1733... Línea 1735...
1733
 
1735
 
1734
    /**
1736
    /**
1735
     * Make sure the DST changes happen at the right time in Moodle.
1737
     * Make sure the DST changes happen at the right time in Moodle.
1736
     */
1738
     */
1737
    public function test_dst_changes() {
1739
    public function test_dst_changes(): void {
1738
        // DST switching in Prague.
1740
        // DST switching in Prague.
1739
        // From 2AM to 3AM in 1989.
1741
        // From 2AM to 3AM in 1989.
1740
        $date = new \DateTime('1989-03-26T01:59:00+01:00');
1742
        $date = new \DateTime('1989-03-26T01:59:00+01:00');
1741
        $this->assertSame('Sunday, 26 March 1989, 01:59', userdate($date->getTimestamp(), '%A, %d %B %Y, %H:%M', 'Europe/Prague'));
1743
        $this->assertSame('Sunday, 26 March 1989, 01:59', userdate($date->getTimestamp(), '%A, %d %B %Y, %H:%M', 'Europe/Prague'));
Línea 1802... Línea 1804...
1802
        $this->assertSame('Sunday, 2 November 2014, 01:59', userdate($date->getTimestamp(), '%A, %d %B %Y, %H:%M', 'America/New_York'));
1804
        $this->assertSame('Sunday, 2 November 2014, 01:59', userdate($date->getTimestamp(), '%A, %d %B %Y, %H:%M', 'America/New_York'));
1803
        $date = new \DateTime('2014-11-02T02:01:00-04:00');
1805
        $date = new \DateTime('2014-11-02T02:01:00-04:00');
1804
        $this->assertSame('Sunday, 2 November 2014, 01:01', userdate($date->getTimestamp(), '%A, %d %B %Y, %H:%M', 'America/New_York'));
1806
        $this->assertSame('Sunday, 2 November 2014, 01:01', userdate($date->getTimestamp(), '%A, %d %B %Y, %H:%M', 'America/New_York'));
1805
    }
1807
    }
Línea 1806... Línea 1808...
1806
 
1808
 
1807
    public function test_make_timestamp() {
1809
    public function test_make_timestamp(): void {
1808
        global $USER, $CFG, $DB;
1810
        global $USER, $CFG, $DB;
Línea 1809... Línea 1811...
1809
        $this->resetAfterTest();
1811
        $this->resetAfterTest();
Línea 1963... Línea 1965...
1963
 
1965
 
1964
    /**
1966
    /**
1965
     * Test get_string and most importantly the implementation of the lang_string
1967
     * Test get_string and most importantly the implementation of the lang_string
1966
     * object.
1968
     * object.
1967
     */
1969
     */
1968
    public function test_get_string() {
1970
    public function test_get_string(): void {
Línea 1969... Línea 1971...
1969
        global $COURSE;
1971
        global $COURSE;
1970
 
1972
 
1971
        // Make sure we are using English.
1973
        // Make sure we are using English.
Línea 2103... Línea 2105...
2103
 
2105
 
2104
        // Reset the language.
2106
        // Reset the language.
2105
        $COURSE->lang = $originallang;
2107
        $COURSE->lang = $originallang;
Línea 2106... Línea 2108...
2106
    }
2108
    }
Línea 2107... Línea 2109...
2107
 
2109
 
2108
    public function test_lang_string_var_export() {
2110
    public function test_lang_string_var_export(): void {
Línea 2109... Línea 2111...
2109
 
2111
 
Línea 2140... Línea 2142...
2140
 
2142
 
2141
        $this->assertInstanceOf(lang_string::class, $str);
2143
        $this->assertInstanceOf(lang_string::class, $str);
2142
        $this->assertEquals('No', $str);
2144
        $this->assertEquals('No', $str);
Línea 2143... Línea 2145...
2143
    }
2145
    }
2144
 
2146
 
2145
    public function test_get_string_limitation() {
2147
    public function test_get_string_limitation(): void {
2146
        // This is one of the limitations to the lang_string class. It can't be
2148
        // This is one of the limitations to the lang_string class. It can't be
2147
        // used as a key.
2149
        // used as a key.
2148
        $this->expectException(\TypeError::class);
2150
        $this->expectException(\TypeError::class);
Línea 2149... Línea 2151...
2149
        $array = array(get_string('yes', null, null, true) => 'yes');
2151
        $array = array(get_string('yes', null, null, true) => 'yes');
2150
    }
2152
    }
2151
 
2153
 
2152
    /**
2154
    /**
Línea 2153... Línea 2155...
2153
     * Test localised float formatting.
2155
     * Test localised float formatting.
2154
     */
2156
     */
Línea 2155... Línea 2157...
2155
    public function test_format_float() {
2157
    public function test_format_float(): void {
Línea 2199... Línea 2201...
2199
    }
2201
    }
Línea 2200... Línea 2202...
2200
 
2202
 
2201
    /**
2203
    /**
2202
     * Test localised float unformatting.
2204
     * Test localised float unformatting.
2203
     */
2205
     */
Línea 2204... Línea 2206...
2204
    public function test_unformat_float() {
2206
    public function test_unformat_float(): void {
Línea 2205... Línea 2207...
2205
 
2207
 
2206
        // Tests without the localised decimal separator.
2208
        // Tests without the localised decimal separator.
Línea 2273... Línea 2275...
2273
    }
2275
    }
Línea 2274... Línea 2276...
2274
 
2276
 
2275
    /**
2277
    /**
2276
     * Test deleting of users.
2278
     * Test deleting of users.
2277
     */
2279
     */
2278
    public function test_delete_user() {
2280
    public function test_delete_user(): void {
Línea 2279... Línea 2281...
2279
        global $DB, $CFG;
2281
        global $DB, $CFG;
Línea 2280... Línea 2282...
2280
 
2282
 
Línea 2379... Línea 2381...
2379
    }
2381
    }
Línea 2380... Línea 2382...
2380
 
2382
 
2381
    /**
2383
    /**
2382
     * Test deletion of user with long username
2384
     * Test deletion of user with long username
2383
     */
2385
     */
2384
    public function test_delete_user_long_username() {
2386
    public function test_delete_user_long_username(): void {
Línea 2385... Línea 2387...
2385
        global $DB;
2387
        global $DB;
Línea 2386... Línea 2388...
2386
 
2388
 
Línea 2406... Línea 2408...
2406
    }
2408
    }
Línea 2407... Línea 2409...
2407
 
2409
 
2408
    /**
2410
    /**
2409
     * Test deletion of user with long email address
2411
     * Test deletion of user with long email address
2410
     */
2412
     */
2411
    public function test_delete_user_long_email() {
2413
    public function test_delete_user_long_email(): void {
Línea 2412... Línea 2414...
2412
        global $DB;
2414
        global $DB;
Línea 2413... Línea 2415...
2413
 
2415
 
Línea 2433... Línea 2435...
2433
    }
2435
    }
Línea 2434... Línea 2436...
2434
 
2436
 
2435
    /**
2437
    /**
2436
     * Test function convert_to_array()
2438
     * Test function convert_to_array()
2437
     */
2439
     */
2438
    public function test_convert_to_array() {
2440
    public function test_convert_to_array(): void {
2439
        // Check that normal classes are converted to arrays the same way as (array) would do.
2441
        // Check that normal classes are converted to arrays the same way as (array) would do.
2440
        $obj = new \stdClass();
2442
        $obj = new \stdClass();
2441
        $obj->prop1 = 'hello';
2443
        $obj->prop1 = 'hello';
2442
        $obj->prop2 = array('first', 'second', 13);
2444
        $obj->prop2 = array('first', 'second', 13);
Línea 2457... Línea 2459...
2457
    }
2459
    }
Línea 2458... Línea 2460...
2458
 
2460
 
2459
    /**
2461
    /**
2460
     * Test the function date_format_string().
2462
     * Test the function date_format_string().
2461
     */
2463
     */
2462
    public function test_date_format_string() {
2464
    public function test_date_format_string(): void {
Línea 2463... Línea 2465...
2463
        global $CFG;
2465
        global $CFG;
2464
 
2466
 
Línea 2512... Línea 2514...
2512
            $str = date_format_string(1293876000, $test['str'], $test['tz']);
2514
            $str = date_format_string(1293876000, $test['str'], $test['tz']);
2513
            $this->assertSame(\core_text::strtolower($test['expected']), \core_text::strtolower($str));
2515
            $this->assertSame(\core_text::strtolower($test['expected']), \core_text::strtolower($str));
2514
        }
2516
        }
2515
    }
2517
    }
Línea 2516... Línea 2518...
2516
 
2518
 
2517
    public function test_get_config() {
2519
    public function test_get_config(): void {
Línea 2518... Línea 2520...
2518
        global $CFG;
2520
        global $CFG;
Línea 2519... Línea 2521...
2519
 
2521
 
Línea 2564... Línea 2566...
2564
        $this->assertFalse($cache->get('core'));
2566
        $this->assertFalse($cache->get('core'));
2565
        set_config('phpunit_test_get_config_4', 'test c', 'mod_forum');
2567
        set_config('phpunit_test_get_config_4', 'test c', 'mod_forum');
2566
        $this->assertFalse($cache->get('mod_forum'));
2568
        $this->assertFalse($cache->get('mod_forum'));
2567
    }
2569
    }
Línea 2568... Línea 2570...
2568
 
2570
 
2569
    public function test_get_max_upload_sizes() {
2571
    public function test_get_max_upload_sizes(): void {
2570
        // Test with very low limits so we are not affected by php upload limits.
2572
        // Test with very low limits so we are not affected by php upload limits.
2571
        // Test activity limit smallest.
2573
        // Test activity limit smallest.
2572
        $sitebytes = 102400;
2574
        $sitebytes = 102400;
2573
        $coursebytes = 51200;
2575
        $coursebytes = 51200;
Línea 2666... Línea 2668...
2666
 
2668
 
2667
    /**
2669
    /**
2668
     * Test function password_is_legacy_hash.
2670
     * Test function password_is_legacy_hash.
2669
     * @covers ::password_is_legacy_hash
2671
     * @covers ::password_is_legacy_hash
2670
     */
2672
     */
2671
    public function test_password_is_legacy_hash() {
2673
    public function test_password_is_legacy_hash(): void {
2672
        // Well formed bcrypt hashes should be matched.
2674
        // Well formed bcrypt hashes should be matched.
2673
        foreach (array('some', 'strings', 'to_check!') as $password) {
2675
        foreach (array('some', 'strings', 'to_check!') as $password) {
2674
            $bcrypt = password_hash($password, '2y');
2676
            $bcrypt = password_hash($password, '2y');
2675
            $this->assertTrue(password_is_legacy_hash($bcrypt));
2677
            $this->assertTrue(password_is_legacy_hash($bcrypt));
Línea 2683... Línea 2685...
2683
 
2685
 
2684
    /**
2686
    /**
2685
     * Test function that calculates password pepper entropy.
2687
     * Test function that calculates password pepper entropy.
2686
     * @covers ::calculate_entropy
2688
     * @covers ::calculate_entropy
2687
     */
2689
     */
2688
    public function test_calculate_entropy() {
2690
    public function test_calculate_entropy(): void {
2689
        // Test that the function returns 0 with an empty string.
2691
        // Test that the function returns 0 with an empty string.
Línea 2690... Línea 2692...
2690
        $this->assertEquals(0, calculate_entropy(''));
2692
        $this->assertEquals(0, calculate_entropy(''));
2691
 
2693
 
Línea 2695... Línea 2697...
2695
 
2697
 
2696
    /**
2698
    /**
2697
     * Test function to get password peppers.
2699
     * Test function to get password peppers.
2698
     * @covers ::get_password_peppers
2700
     * @covers ::get_password_peppers
2699
     */
2701
     */
2700
    public function test_get_password_peppers() {
2702
    public function test_get_password_peppers(): void {
2701
        global $CFG;
2703
        global $CFG;
Línea 2702... Línea 2704...
2702
        $this->resetAfterTest();
2704
        $this->resetAfterTest();
2703
 
2705
 
Línea 2743... Línea 2745...
2743
     * Test function to validate password length.
2745
     * Test function to validate password length.
2744
     *
2746
     *
2745
     * @covers ::exceeds_password_length
2747
     * @covers ::exceeds_password_length
2746
     * @return void
2748
     * @return void
2747
     */
2749
     */
2748
    public function test_exceeds_password_length() {
2750
    public function test_exceeds_password_length(): void {
2749
        $this->resetAfterTest(true);
2751
        $this->resetAfterTest(true);
Línea 2750... Línea 2752...
2750
 
2752
 
2751
        // With password less than equals to MAX_PASSWORD_CHARACTERS.
2753
        // With password less than equals to MAX_PASSWORD_CHARACTERS.
Línea 2760... Línea 2762...
2760
 
2762
 
2761
    /**
2763
    /**
2762
     * Test function validate_internal_user_password.
2764
     * Test function validate_internal_user_password.
2763
     * @covers ::validate_internal_user_password
2765
     * @covers ::validate_internal_user_password
2764
     */
2766
     */
2765
    public function test_validate_internal_user_password() {
2767
    public function test_validate_internal_user_password(): void {
2766
        $this->resetAfterTest(true);
2768
        $this->resetAfterTest(true);
2767
        // Test bcrypt hashes (these will be updated but will still count as valid).
2769
        // Test bcrypt hashes (these will be updated but will still count as valid).
2768
        $bcrypthashes = [
2770
        $bcrypthashes = [
2769
            'pw' => '$2y$10$LOSDi5eaQJhutSRun.OVJ.ZSxQZabCMay7TO1KmzMkDMPvU40zGXK',
2771
            'pw' => '$2y$10$LOSDi5eaQJhutSRun.OVJ.ZSxQZabCMay7TO1KmzMkDMPvU40zGXK',
Línea 2796... Línea 2798...
2796
     * Test function validate_internal_user_password() with a peppered password,
2798
     * Test function validate_internal_user_password() with a peppered password,
2797
     * when the pepper no longer exists.
2799
     * when the pepper no longer exists.
2798
     *
2800
     *
2799
     * @covers ::validate_internal_user_password
2801
     * @covers ::validate_internal_user_password
2800
     */
2802
     */
2801
    public function test_validate_internal_user_password_bad_pepper() {
2803
    public function test_validate_internal_user_password_bad_pepper(): void {
2802
        global $CFG;
2804
        global $CFG;
2803
        $this->resetAfterTest();
2805
        $this->resetAfterTest();
Línea 2804... Línea 2806...
2804
 
2806
 
2805
        // Set a pepper.
2807
        // Set a pepper.
Línea 2845... Línea 2847...
2845
 
2847
 
2846
    /**
2848
    /**
2847
     * Test function update_internal_user_password.
2849
     * Test function update_internal_user_password.
2848
     * @covers ::update_internal_user_password
2850
     * @covers ::update_internal_user_password
2849
     */
2851
     */
2850
    public function test_hash_internal_user_password() {
2852
    public function test_hash_internal_user_password(): void {
2851
        global $CFG;
2853
        global $CFG;
2852
        $this->resetAfterTest();
2854
        $this->resetAfterTest();
Línea 2853... Línea 2855...
2853
        $passwords = ['pw', 'abc123', 'C0mP1eX_&}<?@*&%` |\"', 'ĩńťėŕňăţĩōŋāĹ'];
2855
        $passwords = ['pw', 'abc123', 'C0mP1eX_&}<?@*&%` |\"', 'ĩńťėŕňăţĩōŋāĹ'];
Línea 2873... Línea 2875...
2873
    }
2875
    }
Línea 2874... Línea 2876...
2874
 
2876
 
2875
    /**
2877
    /**
2876
     * Test function update_internal_user_password().
2878
     * Test function update_internal_user_password().
2877
     */
2879
     */
2878
    public function test_update_internal_user_password() {
2880
    public function test_update_internal_user_password(): void {
2879
        global $DB;
2881
        global $DB;
2880
        $this->resetAfterTest();
2882
        $this->resetAfterTest();
2881
        $passwords = array('password', '1234', 'changeme', '****');
2883
        $passwords = array('password', '1234', 'changeme', '****');
2882
        foreach ($passwords as $password) {
2884
        foreach ($passwords as $password) {
Línea 2918... Línea 2920...
2918
    }
2920
    }
Línea 2919... Línea 2921...
2919
 
2921
 
2920
    /**
2922
    /**
2921
     * Testing that if the password is not cached, that it does not update
2923
     * Testing that if the password is not cached, that it does not update
-
 
2924
     * the user table and fire event.
-
 
2925
     *
-
 
2926
     * @dataProvider update_internal_user_password_no_cache_provider
-
 
2927
     * @covers ::update_internal_user_password
-
 
2928
     *
-
 
2929
     * @param string $authmethod The authentication method to set for the user.
2922
     * the user table and fire event.
2930
     * @param string|null $password The new password to set for the user.
2923
     */
2931
     */
-
 
2932
    public function test_update_internal_user_password_no_cache(
-
 
2933
        string $authmethod,
-
 
2934
        ?string $password,
2924
    public function test_update_internal_user_password_no_cache() {
2935
    ): void {
2925
        global $DB;
2936
        global $DB;
Línea 2926... Línea 2937...
2926
        $this->resetAfterTest();
2937
        $this->resetAfterTest();
2927
 
2938
 
2928
        $user = $this->getDataGenerator()->create_user(array('auth' => 'cas'));
2939
        $user = $this->getDataGenerator()->create_user(['auth' => $authmethod]);
Línea 2929... Línea 2940...
2929
        $DB->update_record('user', ['id' => $user->id, 'password' => AUTH_PASSWORD_NOT_CACHED]);
2940
        $DB->update_record('user', ['id' => $user->id, 'password' => AUTH_PASSWORD_NOT_CACHED]);
2930
        $user->password = AUTH_PASSWORD_NOT_CACHED;
2941
        $user->password = AUTH_PASSWORD_NOT_CACHED;
2931
 
2942
 
2932
        $sink = $this->redirectEvents();
2943
        $sink = $this->redirectEvents();
Línea 2933... Línea 2944...
2933
        update_internal_user_password($user, 'wonkawonka');
2944
        update_internal_user_password($user, $password);
-
 
2945
        $this->assertEquals(0, $sink->count(), 'User updated event should not fire');
-
 
2946
    }
-
 
2947
 
-
 
2948
    /**
-
 
2949
     * The data provider will test the {@see test_update_internal_user_password_no_cache}
-
 
2950
     * for accounts using the authentication method with prevent_local_passwords set to true (no cache).
-
 
2951
     *
-
 
2952
     * @return array
-
 
2953
     */
-
 
2954
    public static function update_internal_user_password_no_cache_provider(): array {
-
 
2955
        return [
-
 
2956
            'Password is not empty' => ['cas', 'wonkawonka'],
-
 
2957
            'Password is an empty string' => ['oauth2', ''],
-
 
2958
            'Password is null' => ['oauth2', null],
2934
        $this->assertEquals(0, $sink->count(), 'User updated event should not fire');
2959
        ];
2935
    }
2960
    }
2936
 
2961
 
2937
    /**
2962
    /**
2938
     * Test if the user has a password hash, but now their auth method
2963
     * Test if the user has a password hash, but now their auth method
Línea 2939... Línea 2964...
2939
     * says not to cache it.  Then it should update.
2964
     * says not to cache it.  Then it should update.
2940
     */
2965
     */
2941
    public function test_update_internal_user_password_update_no_cache() {
2966
    public function test_update_internal_user_password_update_no_cache(): void {
Línea 2950... Línea 2975...
2950
        $this->assertGreaterThanOrEqual(1, $sink->count(), 'User updated event should fire');
2975
        $this->assertGreaterThanOrEqual(1, $sink->count(), 'User updated event should fire');
Línea 2951... Línea 2976...
2951
 
2976
 
2952
        $this->assertEquals(AUTH_PASSWORD_NOT_CACHED, $user->password);
2977
        $this->assertEquals(AUTH_PASSWORD_NOT_CACHED, $user->password);
Línea 2953... Línea 2978...
2953
    }
2978
    }
2954
 
2979
 
Línea 2955... Línea 2980...
2955
    public function test_fullname() {
2980
    public function test_fullname(): void {
Línea 2956... Línea 2981...
2956
        global $CFG;
2981
        global $CFG;
Línea 3097... Línea 3122...
3097
        // Tidy up after we finish testing.
3122
        // Tidy up after we finish testing.
3098
        $CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
3123
        $CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
3099
        $CFG->alternativefullnameformat = $originalcfg->alternativefullnameformat;
3124
        $CFG->alternativefullnameformat = $originalcfg->alternativefullnameformat;
3100
    }
3125
    }
Línea 3101... Línea 3126...
3101
 
3126
 
3102
    public function test_order_in_string() {
3127
    public function test_order_in_string(): void {
Línea 3103... Línea 3128...
3103
        $this->resetAfterTest();
3128
        $this->resetAfterTest();
3104
 
3129
 
3105
        // Return an array in an order as they are encountered in a string.
3130
        // Return an array in an order as they are encountered in a string.
Línea 3119... Línea 3144...
3119
        $formatstring = 'start seconds away second firstquater first firsthalf';
3144
        $formatstring = 'start seconds away second firstquater first firsthalf';
3120
        $expectedarray = array('19' => 'second', '38' => 'first', '44' => 'firsthalf');
3145
        $expectedarray = array('19' => 'second', '38' => 'first', '44' => 'firsthalf');
3121
        $this->assertEquals($expectedarray, order_in_string($valuearray, $formatstring));
3146
        $this->assertEquals($expectedarray, order_in_string($valuearray, $formatstring));
3122
    }
3147
    }
Línea 3123... Línea 3148...
3123
 
3148
 
3124
    public function test_complete_user_login() {
3149
    public function test_complete_user_login(): void {
Línea 3125... Línea 3150...
3125
        global $USER, $DB;
3150
        global $USER, $DB;
3126
 
3151
 
3127
        $this->resetAfterTest();
3152
        $this->resetAfterTest();
Línea 3160... Línea 3185...
3160
    }
3185
    }
Línea 3161... Línea 3186...
3161
 
3186
 
3162
    /**
3187
    /**
3163
     * Test require_logout.
3188
     * Test require_logout.
3164
     */
3189
     */
3165
    public function test_require_logout() {
3190
    public function test_require_logout(): void {
3166
        $this->resetAfterTest();
3191
        $this->resetAfterTest();
3167
        $user = $this->getDataGenerator()->create_user();
3192
        $user = $this->getDataGenerator()->create_user();
Línea 3168... Línea 3193...
3168
        $this->setUser($user);
3193
        $this->setUser($user);
Línea 3213... Línea 3238...
3213
     * @dataProvider generate_email_messageid_provider
3238
     * @dataProvider generate_email_messageid_provider
3214
     *
3239
     *
3215
     * @param string $wwwroot The wwwroot
3240
     * @param string $wwwroot The wwwroot
3216
     * @param array $msgids An array of msgid local parts and the final result
3241
     * @param array $msgids An array of msgid local parts and the final result
3217
     */
3242
     */
3218
    public function test_generate_email_messageid($wwwroot, $msgids) {
3243
    public function test_generate_email_messageid($wwwroot, $msgids): void {
3219
        global $CFG;
3244
        global $CFG;
Línea 3220... Línea 3245...
3220
 
3245
 
3221
        $this->resetAfterTest();
3246
        $this->resetAfterTest();
Línea 3227... Línea 3252...
3227
    }
3252
    }
Línea 3228... Línea 3253...
3228
 
3253
 
3229
    /**
3254
    /**
3230
     * Test email with custom headers
3255
     * Test email with custom headers
3231
     */
3256
     */
3232
    public function test_send_email_with_custom_header() {
3257
    public function test_send_email_with_custom_header(): void {
3233
        global $DB, $CFG;
3258
        global $DB, $CFG;
3234
        $this->preventResetByRollback();
3259
        $this->preventResetByRollback();
Línea 3235... Línea 3260...
3235
        $this->resetAfterTest();
3260
        $this->resetAfterTest();
Línea 3352... Línea 3377...
3352
     * @param string $divertallemailsto An optional email address
3377
     * @param string $divertallemailsto An optional email address
3353
     * @param string $divertallemailsexcept An optional exclusion list
3378
     * @param string $divertallemailsexcept An optional exclusion list
3354
     * @param array $addresses An array of test addresses
3379
     * @param array $addresses An array of test addresses
3355
     * @param boolean $expected Expected result
3380
     * @param boolean $expected Expected result
3356
     */
3381
     */
3357
    public function test_email_should_be_diverted($divertallemailsto, $divertallemailsexcept, $addresses, $expected) {
3382
    public function test_email_should_be_diverted($divertallemailsto, $divertallemailsexcept, $addresses, $expected): void {
3358
        global $CFG;
3383
        global $CFG;
Línea 3359... Línea 3384...
3359
 
3384
 
3360
        $this->resetAfterTest();
3385
        $this->resetAfterTest();
3361
        $CFG->divertallemailsto = $divertallemailsto;
3386
        $CFG->divertallemailsto = $divertallemailsto;
Línea 3364... Línea 3389...
3364
        foreach ($addresses as $address) {
3389
        foreach ($addresses as $address) {
3365
            $this->assertEquals($expected, email_should_be_diverted($address));
3390
            $this->assertEquals($expected, email_should_be_diverted($address));
3366
        }
3391
        }
3367
    }
3392
    }
Línea 3368... Línea 3393...
3368
 
3393
 
3369
    public function test_email_to_user() {
3394
    public function test_email_to_user(): void {
Línea 3370... Línea 3395...
3370
        global $CFG;
3395
        global $CFG;
Línea 3371... Línea 3396...
3371
 
3396
 
Línea 3545... Línea 3570...
3545
    }
3570
    }
Línea 3546... Línea 3571...
3546
 
3571
 
3547
    /**
3572
    /**
3548
     * Test setnew_password_and_mail.
3573
     * Test setnew_password_and_mail.
3549
     */
3574
     */
3550
    public function test_setnew_password_and_mail() {
3575
    public function test_setnew_password_and_mail(): void {
Línea 3551... Línea 3576...
3551
        global $DB, $CFG;
3576
        global $DB, $CFG;
Línea 3552... Línea 3577...
3552
 
3577
 
Línea 3575... Línea 3600...
3575
        $this->assertEventContextNotUsed($event);
3600
        $this->assertEventContextNotUsed($event);
3576
    }
3601
    }
Línea 3577... Línea 3602...
3577
 
3602
 
3578
    /**
3603
    /**
3579
     * Data provider for test_generate_confirmation_link
3604
     * Data provider for test_generate_confirmation_link
3580
     * @return Array of confirmation urls and expected resultant confirmation links
3605
     * @return array Confirmation urls and expected resultant confirmation links
3581
     */
3606
     */
3582
    public function generate_confirmation_link_provider() {
3607
    public static function generate_confirmation_link_provider(): array {
3583
        global $CFG;
3608
        global $CFG;
3584
        return [
3609
        return [
3585
            "Simple name" => [
3610
            "Simple name" => [
3586
                "username" => "simplename",
3611
                "username" => "simplename",
Línea 3645... Línea 3670...
3645
            "Custom external confirmation url with parameters" => [
3670
            "Custom external confirmation url with parameters" => [
3646
                "username" => "many_-.@characters@_@-..-..",
3671
                "username" => "many_-.@characters@_@-..-..",
3647
                "confirmationurl" => "http://moodle.org/ext.php?with=some&param=eters",
3672
                "confirmationurl" => "http://moodle.org/ext.php?with=some&param=eters",
3648
                "expected" => "http://moodle.org/ext.php?with=some&param=eters&data=/many_-%2E%40characters%40_%40-%2E%2E-%2E%2E"
3673
                "expected" => "http://moodle.org/ext.php?with=some&param=eters&data=/many_-%2E%40characters%40_%40-%2E%2E-%2E%2E"
3649
            ],
3674
            ],
3650
            "Custom external confirmation url with parameters" => [
3675
            "Custom external confirmation url with parameters (again)" => [
3651
                "username" => "many_-.@characters@_@-..-..",
3676
                "username" => "many_-.@characters@_@-..-..",
3652
                "confirmationurl" => "http://moodle.org/ext.php?with=some&data=test",
3677
                "confirmationurl" => "http://moodle.org/ext.php?with=some&data=test",
3653
                "expected" => "http://moodle.org/ext.php?with=some&data=/many_-%2E%40characters%40_%40-%2E%2E-%2E%2E"
3678
                "expected" => "http://moodle.org/ext.php?with=some&data=/many_-%2E%40characters%40_%40-%2E%2E-%2E%2E"
3654
            ],
3679
            ],
3655
        ];
3680
        ];
Línea 3660... Línea 3685...
3660
     * @dataProvider generate_confirmation_link_provider
3685
     * @dataProvider generate_confirmation_link_provider
3661
     * @param string $username The name of the user
3686
     * @param string $username The name of the user
3662
     * @param string $confirmationurl The url the user should go to to confirm
3687
     * @param string $confirmationurl The url the user should go to to confirm
3663
     * @param string $expected The expected url of the confirmation link
3688
     * @param string $expected The expected url of the confirmation link
3664
     */
3689
     */
3665
    public function test_generate_confirmation_link($username, $confirmationurl, $expected) {
3690
    public function test_generate_confirmation_link($username, $confirmationurl, $expected): void {
3666
        $this->resetAfterTest();
3691
        $this->resetAfterTest();
3667
        $sink = $this->redirectEmails();
3692
        $sink = $this->redirectEmails();
Línea 3668... Línea 3693...
3668
 
3693
 
3669
        $user = $this->getDataGenerator()->create_user(
3694
        $user = $this->getDataGenerator()->create_user(
Línea 3684... Línea 3709...
3684
    }
3709
    }
Línea 3685... Línea 3710...
3685
 
3710
 
3686
    /**
3711
    /**
3687
     * Test generate_confirmation_link with custom admin link
3712
     * Test generate_confirmation_link with custom admin link
3688
     */
3713
     */
3689
    public function test_generate_confirmation_link_with_custom_admin() {
3714
    public function test_generate_confirmation_link_with_custom_admin(): void {
Línea 3690... Línea 3715...
3690
        global $CFG;
3715
        global $CFG;
3691
 
3716
 
Línea 3720... Línea 3745...
3720
 
3745
 
3721
    /**
3746
    /**
3722
     * Test remove_course_content deletes course contents
3747
     * Test remove_course_content deletes course contents
3723
     * TODO Add asserts to verify other data related to course is deleted as well.
3748
     * TODO Add asserts to verify other data related to course is deleted as well.
3724
     */
3749
     */
Línea 3725... Línea 3750...
3725
    public function test_remove_course_contents() {
3750
    public function test_remove_course_contents(): void {
Línea 3726... Línea 3751...
3726
 
3751
 
3727
        $this->resetAfterTest();
3752
        $this->resetAfterTest();
Línea 3737... Línea 3762...
3737
    }
3762
    }
Línea 3738... Línea 3763...
3738
 
3763
 
3739
    /**
3764
    /**
3740
     * Test function username_load_fields_from_object().
3765
     * Test function username_load_fields_from_object().
3741
     */
3766
     */
3742
    public function test_username_load_fields_from_object() {
3767
    public function test_username_load_fields_from_object(): void {
Línea 3743... Línea 3768...
3743
        $this->resetAfterTest();
3768
        $this->resetAfterTest();
3744
 
3769
 
3745
        // This object represents the information returned from an sql query.
3770
        // This object represents the information returned from an sql query.
Línea 3926... Línea 3951...
3926
    }
3951
    }
Línea 3927... Línea 3952...
3927
 
3952
 
3928
    /**
3953
    /**
3929
     * Tests the getremoteaddr() function.
3954
     * Tests the getremoteaddr() function.
3930
     */
3955
     */
3931
    public function test_getremoteaddr() {
3956
    public function test_getremoteaddr(): void {
Línea 3932... Línea 3957...
3932
        global $CFG;
3957
        global $CFG;
Línea 3933... Línea 3958...
3933
 
3958
 
Línea 4019... Línea 4044...
4019
    }
4044
    }
Línea 4020... Línea 4045...
4020
 
4045
 
4021
    /**
4046
    /**
4022
     * Test function for creation of random strings.
4047
     * Test function for creation of random strings.
4023
     */
4048
     */
4024
    public function test_random_string() {
4049
    public function test_random_string(): void {
Línea 4025... Línea 4050...
4025
        $pool = 'a-zA-Z0-9';
4050
        $pool = 'a-zA-Z0-9';
4026
 
4051
 
4027
        $result = random_string(10);
4052
        $result = random_string(10);
Línea 4046... Línea 4071...
4046
    }
4071
    }
Línea 4047... Línea 4072...
4047
 
4072
 
4048
    /**
4073
    /**
4049
     * Test function for creation of complex random strings.
4074
     * Test function for creation of complex random strings.
4050
     */
4075
     */
4051
    public function test_complex_random_string() {
4076
    public function test_complex_random_string(): void {
Línea 4052... Línea 4077...
4052
        $pool = preg_quote('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#%^&*()_+-=[];,./<>?:{} ', '/');
4077
        $pool = preg_quote('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#%^&*()_+-=[];,./<>?:{} ', '/');
4053
 
4078
 
4054
        $result = complex_random_string(10);
4079
        $result = complex_random_string(10);
Línea 4091... Línea 4116...
4091
     * Checks ip_is_public returns false for private ips.
4116
     * Checks ip_is_public returns false for private ips.
4092
     *
4117
     *
4093
     * @param string $ip the ipaddress to test
4118
     * @param string $ip the ipaddress to test
4094
     * @dataProvider data_private_ips
4119
     * @dataProvider data_private_ips
4095
     */
4120
     */
4096
    public function test_ip_is_public_private_ips($ip) {
4121
    public function test_ip_is_public_private_ips($ip): void {
4097
        $this->assertFalse(ip_is_public($ip));
4122
        $this->assertFalse(ip_is_public($ip));
4098
    }
4123
    }
Línea 4099... Línea 4124...
4099
 
4124
 
4100
    /**
4125
    /**
Línea 4113... Línea 4138...
4113
     * Checks ip_is_public returns true for public ips.
4138
     * Checks ip_is_public returns true for public ips.
4114
     *
4139
     *
4115
     * @param string $ip the ipaddress to test
4140
     * @param string $ip the ipaddress to test
4116
     * @dataProvider data_public_ips
4141
     * @dataProvider data_public_ips
4117
     */
4142
     */
4118
    public function test_ip_is_public_public_ips($ip) {
4143
    public function test_ip_is_public_public_ips($ip): void {
4119
        $this->assertTrue(ip_is_public($ip));
4144
        $this->assertTrue(ip_is_public($ip));
4120
    }
4145
    }
Línea 4121... Línea 4146...
4121
 
4146
 
4122
    /**
4147
    /**
Línea 4127... Línea 4152...
4127
     * @param bool $samecourse Are the users in the same course?
4152
     * @param bool $samecourse Are the users in the same course?
4128
     * @param string $config The CFG->allowedemaildomains config values
4153
     * @param string $config The CFG->allowedemaildomains config values
4129
     * @param bool $result The expected result.
4154
     * @param bool $result The expected result.
4130
     * @dataProvider data_can_send_from_real_email_address
4155
     * @dataProvider data_can_send_from_real_email_address
4131
     */
4156
     */
4132
    public function test_can_send_from_real_email_address($email, $display, $samecourse, $config, $result) {
4157
    public function test_can_send_from_real_email_address($email, $display, $samecourse, $config, $result): void {
4133
        $this->resetAfterTest();
4158
        $this->resetAfterTest();
Línea 4134... Línea 4159...
4134
 
4159
 
4135
        $fromuser = $this->getDataGenerator()->create_user();
4160
        $fromuser = $this->getDataGenerator()->create_user();
4136
        $touser = $this->getDataGenerator()->create_user();
4161
        $touser = $this->getDataGenerator()->create_user();
Línea 4256... Línea 4281...
4256
    }
4281
    }
Línea 4257... Línea 4282...
4257
 
4282
 
4258
    /**
4283
    /**
4259
     * Test that generate_email_processing_address() returns valid email address.
4284
     * Test that generate_email_processing_address() returns valid email address.
4260
     */
4285
     */
4261
    public function test_generate_email_processing_address() {
4286
    public function test_generate_email_processing_address(): void {
4262
        global $CFG;
4287
        global $CFG;
Línea 4263... Línea 4288...
4263
        $this->resetAfterTest();
4288
        $this->resetAfterTest();
4264
 
4289
 
Línea 4285... Línea 4310...
4285
     * @param string $config The CFG->allowemailaddresses config values
4310
     * @param string $config The CFG->allowemailaddresses config values
4286
     * @param false/string $result The expected result.
4311
     * @param false/string $result The expected result.
4287
     *
4312
     *
4288
     * @dataProvider data_email_is_not_allowed_for_allowemailaddresses
4313
     * @dataProvider data_email_is_not_allowed_for_allowemailaddresses
4289
     */
4314
     */
4290
    public function test_email_is_not_allowed_for_allowemailaddresses($email, $config, $result) {
4315
    public function test_email_is_not_allowed_for_allowemailaddresses($email, $config, $result): void {
4291
        $this->resetAfterTest();
4316
        $this->resetAfterTest();
Línea 4292... Línea 4317...
4292
 
4317
 
4293
        set_config('allowemailaddresses', $config);
4318
        set_config('allowemailaddresses', $config);
4294
        $this->assertEquals($result, email_is_not_allowed($email));
4319
        $this->assertEquals($result, email_is_not_allowed($email));
Línea 4363... Línea 4388...
4363
     * @param string $config The CFG->denyemailaddresses config values
4388
     * @param string $config The CFG->denyemailaddresses config values
4364
     * @param false/string $result The expected result.
4389
     * @param false/string $result The expected result.
4365
     *
4390
     *
4366
     * @dataProvider data_email_is_not_allowed_for_denyemailaddresses
4391
     * @dataProvider data_email_is_not_allowed_for_denyemailaddresses
4367
     */
4392
     */
4368
    public function test_email_is_not_allowed_for_denyemailaddresses($email, $config, $result) {
4393
    public function test_email_is_not_allowed_for_denyemailaddresses($email, $config, $result): void {
4369
        $this->resetAfterTest();
4394
        $this->resetAfterTest();
Línea 4370... Línea 4395...
4370
 
4395
 
4371
        set_config('denyemailaddresses', $config);
4396
        set_config('denyemailaddresses', $config);
4372
        $this->assertEquals($result, email_is_not_allowed($email));
4397
        $this->assertEquals($result, email_is_not_allowed($email));
Línea 4436... Línea 4461...
4436
    }
4461
    }
Línea 4437... Línea 4462...
4437
 
4462
 
4438
    /**
4463
    /**
4439
     * Test safe method unserialize_array().
4464
     * Test safe method unserialize_array().
4440
     */
4465
     */
4441
    public function test_unserialize_array() {
4466
    public function test_unserialize_array(): void {
4442
        $a = [1, 2, 3];
4467
        $a = [1, 2, 3];
4443
        $this->assertEquals($a, unserialize_array(serialize($a)));
4468
        $this->assertEquals($a, unserialize_array(serialize($a)));
4444
        $a = ['a' => 1, 2 => 2, 'b' => 'cde'];
4469
        $a = ['a' => 1, 2 => 2, 'b' => 'cde'];
4445
        $this->assertEquals($a, unserialize_array(serialize($a)));
4470
        $this->assertEquals($a, unserialize_array(serialize($a)));
Línea 4494... Línea 4519...
4494
     * Test that the component_class_callback returns the correct default value when the class was not found.
4519
     * Test that the component_class_callback returns the correct default value when the class was not found.
4495
     *
4520
     *
4496
     * @dataProvider component_class_callback_default_provider
4521
     * @dataProvider component_class_callback_default_provider
4497
     * @param $default
4522
     * @param $default
4498
     */
4523
     */
4499
    public function test_component_class_callback_not_found($default) {
4524
    public function test_component_class_callback_not_found($default): void {
4500
        $this->assertSame($default, component_class_callback('thisIsNotTheClassYouWereLookingFor', 'anymethod', [], $default));
4525
        $this->assertSame($default, component_class_callback('thisIsNotTheClassYouWereLookingFor', 'anymethod', [], $default));
4501
    }
4526
    }
Línea 4502... Línea 4527...
4502
 
4527
 
4503
    /**
4528
    /**
4504
     * Test that the component_class_callback returns the correct default value when the class was not found.
4529
     * Test that the component_class_callback returns the correct default value when the class was not found.
4505
     *
4530
     *
4506
     * @dataProvider component_class_callback_default_provider
4531
     * @dataProvider component_class_callback_default_provider
4507
     * @param $default
4532
     * @param $default
4508
     */
4533
     */
4509
    public function test_component_class_callback_method_not_found($default) {
4534
    public function test_component_class_callback_method_not_found($default): void {
Línea 4510... Línea 4535...
4510
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
4535
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
4511
 
4536
 
Línea 4516... Línea 4541...
4516
     * Test that the component_class_callback returns the default when the method returned null.
4541
     * Test that the component_class_callback returns the default when the method returned null.
4517
     *
4542
     *
4518
     * @dataProvider component_class_callback_default_provider
4543
     * @dataProvider component_class_callback_default_provider
4519
     * @param $default
4544
     * @param $default
4520
     */
4545
     */
4521
    public function test_component_class_callback_found_returns_null($default) {
4546
    public function test_component_class_callback_found_returns_null($default): void {
4522
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
4547
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
Línea 4523... Línea 4548...
4523
 
4548
 
4524
        $this->assertSame($default, component_class_callback(\test_component_class_callback_example::class, 'method_returns_value', [null], $default));
4549
        $this->assertSame($default, component_class_callback(\test_component_class_callback_example::class, 'method_returns_value', [null], $default));
4525
        $this->assertSame($default, component_class_callback(\test_component_class_callback_child_example::class, 'method_returns_value', [null], $default));
4550
        $this->assertSame($default, component_class_callback(\test_component_class_callback_child_example::class, 'method_returns_value', [null], $default));
Línea 4529... Línea 4554...
4529
     * Test that the component_class_callback returns the expected value and not the default when there was a value.
4554
     * Test that the component_class_callback returns the expected value and not the default when there was a value.
4530
     *
4555
     *
4531
     * @dataProvider component_class_callback_data_provider
4556
     * @dataProvider component_class_callback_data_provider
4532
     * @param $default
4557
     * @param $default
4533
     */
4558
     */
4534
    public function test_component_class_callback_found_returns_value($value) {
4559
    public function test_component_class_callback_found_returns_value($value): void {
4535
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
4560
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
Línea 4536... Línea 4561...
4536
 
4561
 
4537
        $this->assertSame($value, component_class_callback(\test_component_class_callback_example::class, 'method_returns_value', [$value], 'This is not the value you were looking for'));
4562
        $this->assertSame($value, component_class_callback(\test_component_class_callback_example::class, 'method_returns_value', [$value], 'This is not the value you were looking for'));
4538
        $this->assertSame($value, component_class_callback(\test_component_class_callback_child_example::class, 'method_returns_value', [$value], 'This is not the value you were looking for'));
4563
        $this->assertSame($value, component_class_callback(\test_component_class_callback_child_example::class, 'method_returns_value', [$value], 'This is not the value you were looking for'));
Línea 4542... Línea 4567...
4542
     * Test that the component_class_callback handles multiple params correctly.
4567
     * Test that the component_class_callback handles multiple params correctly.
4543
     *
4568
     *
4544
     * @dataProvider component_class_callback_multiple_params_provider
4569
     * @dataProvider component_class_callback_multiple_params_provider
4545
     * @param $default
4570
     * @param $default
4546
     */
4571
     */
4547
    public function test_component_class_callback_found_accepts_multiple($params, $count) {
4572
    public function test_component_class_callback_found_accepts_multiple($params, $count): void {
4548
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
4573
        require_once(__DIR__ . '/fixtures/component_class_callback_example.php');
Línea 4549... Línea 4574...
4549
 
4574
 
4550
        $this->assertSame($count, component_class_callback(\test_component_class_callback_example::class, 'method_returns_all_params', $params, 'This is not the value you were looking for'));
4575
        $this->assertSame($count, component_class_callback(\test_component_class_callback_example::class, 'method_returns_all_params', $params, 'This is not the value you were looking for'));
4551
        $this->assertSame($count, component_class_callback(\test_component_class_callback_child_example::class, 'method_returns_all_params', $params, 'This is not the value you were looking for'));
4576
        $this->assertSame($count, component_class_callback(\test_component_class_callback_child_example::class, 'method_returns_all_params', $params, 'This is not the value you were looking for'));
Línea 4621... Línea 4646...
4621
     *
4646
     *
4622
     * @dataProvider callable_names_provider
4647
     * @dataProvider callable_names_provider
4623
     * @param callable $callable
4648
     * @param callable $callable
4624
     * @param string $expectedname
4649
     * @param string $expectedname
4625
     */
4650
     */
4626
    public function test_get_callable_name($callable, $expectedname) {
4651
    public function test_get_callable_name($callable, $expectedname): void {
4627
        $this->assertSame($expectedname, get_callable_name($callable));
4652
        $this->assertSame($expectedname, get_callable_name($callable));
4628
    }
4653
    }
Línea 4629... Línea 4654...
4629
 
4654
 
4630
    /**
4655
    /**
Línea 4720... Línea 4745...
4720
     * @param string|boolean $value The field value. When fetching by ID, set true to fetch valid user ID, false otherwise.
4745
     * @param string|boolean $value The field value. When fetching by ID, set true to fetch valid user ID, false otherwise.
4721
     * @param boolean $success Whether we expect for the fetch to succeed or return false.
4746
     * @param boolean $success Whether we expect for the fetch to succeed or return false.
4722
     * @param int $allowaccountssameemail Value for $CFG->allowaccountssameemail.
4747
     * @param int $allowaccountssameemail Value for $CFG->allowaccountssameemail.
4723
     * @param string $expectedexception The exception to be expected.
4748
     * @param string $expectedexception The exception to be expected.
4724
     */
4749
     */
4725
    public function test_get_complete_user_data($field, $value, $success, $allowaccountssameemail = 0, $expectedexception = '') {
4750
    public function test_get_complete_user_data($field, $value, $success, $allowaccountssameemail = 0, $expectedexception = ''): void {
4726
        $this->resetAfterTest();
4751
        $this->resetAfterTest();
Línea 4727... Línea 4752...
4727
 
4752
 
4728
        // Set config settings we need for our environment.
4753
        // Set config settings we need for our environment.
Línea 4770... Línea 4795...
4770
    }
4795
    }
Línea 4771... Línea 4796...
4771
 
4796
 
4772
    /**
4797
    /**
4773
     * Test for send_password_change_().
4798
     * Test for send_password_change_().
4774
     */
4799
     */
4775
    public function test_send_password_change_info() {
4800
    public function test_send_password_change_info(): void {
Línea 4776... Línea 4801...
4776
        $this->resetAfterTest();
4801
        $this->resetAfterTest();
Línea 4777... Línea 4802...
4777
 
4802
 
Línea 4796... Línea 4821...
4796
     * @param bool $dropzeroes the value passed for the `$dropzeros` param.
4821
     * @param bool $dropzeroes the value passed for the `$dropzeros` param.
4797
     * @param bool $fullformat the value passed for the `$fullformat` param.
4822
     * @param bool $fullformat the value passed for the `$fullformat` param.
4798
     * @covers \get_time_interval_string
4823
     * @covers \get_time_interval_string
4799
     */
4824
     */
4800
    public function test_get_time_interval_string(int $time1, int $time2, ?string $format, string $expected,
4825
    public function test_get_time_interval_string(int $time1, int $time2, ?string $format, string $expected,
4801
            bool $dropzeroes = false, bool $fullformat = false) {
4826
            bool $dropzeroes = false, bool $fullformat = false): void {
4802
        if (is_null($format)) {
4827
        if (is_null($format)) {
4803
            $this->assertEquals($expected, get_time_interval_string($time1, $time2));
4828
            $this->assertEquals($expected, get_time_interval_string($time1, $time2));
4804
        } else {
4829
        } else {
4805
            $this->assertEquals($expected, get_time_interval_string($time1, $time2, $format, $dropzeroes, $fullformat));
4830
            $this->assertEquals($expected, get_time_interval_string($time1, $time2, $format, $dropzeroes, $fullformat));
4806
        }
4831
        }
Línea 4900... Línea 4925...
4900
    }
4925
    }
Línea 4901... Línea 4926...
4901
 
4926
 
4902
    /**
4927
    /**
4903
     * Tests the rename_to_unused_name function with a file.
4928
     * Tests the rename_to_unused_name function with a file.
4904
     */
4929
     */
4905
    public function test_rename_to_unused_name_file() {
4930
    public function test_rename_to_unused_name_file(): void {
Línea 4906... Línea 4931...
4906
        global $CFG;
4931
        global $CFG;
4907
 
4932
 
4908
        // Create a new file in dataroot.
4933
        // Create a new file in dataroot.
Línea 4926... Línea 4951...
4926
    }
4951
    }
Línea 4927... Línea 4952...
4927
 
4952
 
4928
    /**
4953
    /**
4929
     * Tests the rename_to_unused_name function with a directory.
4954
     * Tests the rename_to_unused_name function with a directory.
4930
     */
4955
     */
4931
    public function test_rename_to_unused_name_dir() {
4956
    public function test_rename_to_unused_name_dir(): void {
Línea 4932... Línea 4957...
4932
        global $CFG;
4957
        global $CFG;
4933
 
4958
 
4934
        // Create a new directory in dataroot.
4959
        // Create a new directory in dataroot.
Línea 4952... Línea 4977...
4952
    }
4977
    }
Línea 4953... Línea 4978...
4953
 
4978
 
4954
    /**
4979
    /**
4955
     * Tests the rename_to_unused_name function with error cases.
4980
     * Tests the rename_to_unused_name function with error cases.
4956
     */
4981
     */
4957
    public function test_rename_to_unused_name_failure() {
4982
    public function test_rename_to_unused_name_failure(): void {
Línea 4958... Línea 4983...
4958
        global $CFG;
4983
        global $CFG;
4959
 
4984
 
4960
        // Rename a file that doesn't exist.
4985
        // Rename a file that doesn't exist.
Línea 4996... Línea 5021...
4996
     * Test display_size
5021
     * Test display_size
4997
     * @dataProvider display_size_provider
5022
     * @dataProvider display_size_provider
4998
     * @param int $size the size in bytes
5023
     * @param int $size the size in bytes
4999
     * @param string $expected the expected string.
5024
     * @param string $expected the expected string.
5000
     */
5025
     */
5001
    public function test_display_size($size, $expected) {
5026
    public function test_display_size($size, $expected): void {
5002
        $result = display_size($size);
5027
        $result = display_size($size);
5003
        $expected = str_replace(' ', "\xc2\xa0", $expected); // Should be non-breaking space.
5028
        $expected = str_replace(' ', "\xc2\xa0", $expected); // Should be non-breaking space.
5004
        $this->assertEquals($expected, $result);
5029
        $this->assertEquals($expected, $result);
5005
    }
5030
    }
Línea 5168... Línea 5193...
5168
     * @param int $enabledashboard Whether the dashboard should be enabled or not.
5193
     * @param int $enabledashboard Whether the dashboard should be enabled or not.
5169
     * @param int $userpreference User preference for the home page setting.
5194
     * @param int $userpreference User preference for the home page setting.
5170
     * @covers ::get_home_page
5195
     * @covers ::get_home_page
5171
     */
5196
     */
5172
    public function test_get_home_page(string $user, int $expected, ?int $defaulthomepage = null, ?int $enabledashboard = null,
5197
    public function test_get_home_page(string $user, int $expected, ?int $defaulthomepage = null, ?int $enabledashboard = null,
5173
            ?int $userpreference = null) {
5198
            ?int $userpreference = null): void {
5174
        global $CFG, $USER;
5199
        global $CFG, $USER;
Línea 5175... Línea 5200...
5175
 
5200
 
Línea 5176... Línea 5201...
5176
        $this->resetAfterTest();
5201
        $this->resetAfterTest();
Línea 5281... Línea 5306...
5281
    /**
5306
    /**
5282
     * Test get_default_home_page() method.
5307
     * Test get_default_home_page() method.
5283
     *
5308
     *
5284
     * @covers ::get_default_home_page
5309
     * @covers ::get_default_home_page
5285
     */
5310
     */
5286
    public function test_get_default_home_page() {
5311
    public function test_get_default_home_page(): void {
5287
        global $CFG;
5312
        global $CFG;
Línea 5288... Línea 5313...
5288
 
5313
 
Línea 5289... Línea 5314...
5289
        $this->resetAfterTest();
5314
        $this->resetAfterTest();
Línea 5370... Línea 5395...
5370
    /**
5395
    /**
5371
     * Test the html_is_blank() function.
5396
     * Test the html_is_blank() function.
5372
     *
5397
     *
5373
     * @covers ::html_is_blank
5398
     * @covers ::html_is_blank
5374
     */
5399
     */
5375
    public function test_html_is_blank() {
5400
    public function test_html_is_blank(): void {
5376
        $this->assertEquals(true, html_is_blank(null));
5401
        $this->assertEquals(true, html_is_blank(null));
5377
        $this->assertEquals(true, html_is_blank(''));
5402
        $this->assertEquals(true, html_is_blank(''));
5378
        $this->assertEquals(true, html_is_blank('<p> </p>'));
5403
        $this->assertEquals(true, html_is_blank('<p> </p>'));
5379
        $this->assertEquals(false, html_is_blank('<p>.</p>'));
5404
        $this->assertEquals(false, html_is_blank('<p>.</p>'));
5380
        $this->assertEquals(false, html_is_blank('<img src="#">'));
5405
        $this->assertEquals(false, html_is_blank('<img src="#">'));