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
 */
25
 */
26
class weblib_test extends advanced_testcase {
26
class weblib_test extends advanced_testcase {
27
    /**
27
    /**
28
     * @covers ::s
28
     * @covers ::s
29
     */
29
     */
30
    public function test_s() {
30
    public function test_s(): void {
31
        // Special cases.
31
        // Special cases.
32
        $this->assertSame('0', s(0));
32
        $this->assertSame('0', s(0));
33
        $this->assertSame('0', s('0'));
33
        $this->assertSame('0', s('0'));
34
        $this->assertSame('0', s(false));
34
        $this->assertSame('0', s(false));
35
        $this->assertSame('', s(null));
35
        $this->assertSame('', s(null));
Línea 185... Línea 185...
185
    }
185
    }
Línea 186... Línea 186...
186
 
186
 
187
    /**
187
    /**
188
     * @covers ::format_text_email
188
     * @covers ::format_text_email
189
     */
189
     */
190
    public function test_format_text_email() {
190
    public function test_format_text_email(): void {
191
        $this->assertSame("This is a TEST\n",
191
        $this->assertSame("This is a TEST\n",
192
            format_text_email('<p>This is a <strong>test</strong></p>', FORMAT_HTML));
192
            format_text_email('<p>This is a <strong>test</strong></p>', FORMAT_HTML));
193
        $this->assertSame("This is a TEST\n",
193
        $this->assertSame("This is a TEST\n",
194
            format_text_email('<p class="frogs">This is a <strong class=\'fishes\'>test</strong></p>', FORMAT_HTML));
194
            format_text_email('<p class="frogs">This is a <strong class=\'fishes\'>test</strong></p>', FORMAT_HTML));
Línea 201... Línea 201...
201
    }
201
    }
Línea 202... Línea 202...
202
 
202
 
203
    /**
203
    /**
204
     * @covers ::obfuscate_email
204
     * @covers ::obfuscate_email
205
     */
205
     */
206
    public function test_obfuscate_email() {
206
    public function test_obfuscate_email(): void {
207
        $email = 'some.user@example.com';
207
        $email = 'some.user@example.com';
208
        $obfuscated = obfuscate_email($email);
208
        $obfuscated = obfuscate_email($email);
209
        $this->assertNotSame($email, $obfuscated);
209
        $this->assertNotSame($email, $obfuscated);
210
        $back = core_text::entities_to_utf8(urldecode($email), true);
210
        $back = core_text::entities_to_utf8(urldecode($email), true);
211
        $this->assertSame($email, $back);
211
        $this->assertSame($email, $back);
Línea 212... Línea 212...
212
    }
212
    }
213
 
213
 
214
    /**
214
    /**
215
     * @covers ::obfuscate_text
215
     * @covers ::obfuscate_text
216
     */
216
     */
217
    public function test_obfuscate_text() {
217
    public function test_obfuscate_text(): void {
218
        $text = 'Žluťoučký koníček 32131';
218
        $text = 'Žluťoučký koníček 32131';
219
        $obfuscated = obfuscate_text($text);
219
        $obfuscated = obfuscate_text($text);
220
        $this->assertNotSame($text, $obfuscated);
220
        $this->assertNotSame($text, $obfuscated);
221
        $back = core_text::entities_to_utf8($obfuscated, true);
221
        $back = core_text::entities_to_utf8($obfuscated, true);
Línea 222... Línea 222...
222
        $this->assertSame($text, $back);
222
        $this->assertSame($text, $back);
223
    }
223
    }
224
 
224
 
225
    /**
225
    /**
226
     * @covers ::highlight
226
     * @covers ::highlight
227
     */
227
     */
Línea 228... Línea 228...
228
    public function test_highlight() {
228
    public function test_highlight(): void {
229
        $this->assertSame('This is <span class="highlight">good</span>',
229
        $this->assertSame('This is <span class="highlight">good</span>',
Línea 264... Línea 264...
264
    }
264
    }
Línea 265... Línea 265...
265
 
265
 
266
    /**
266
    /**
267
     * @covers ::replace_ampersands_not_followed_by_entity
267
     * @covers ::replace_ampersands_not_followed_by_entity
268
     */
268
     */
269
    public function test_replace_ampersands() {
269
    public function test_replace_ampersands(): void {
270
        $this->assertSame("This &amp; that &nbsp;", replace_ampersands_not_followed_by_entity("This & that &nbsp;"));
270
        $this->assertSame("This &amp; that &nbsp;", replace_ampersands_not_followed_by_entity("This & that &nbsp;"));
271
        $this->assertSame("This &amp;nbsp that &nbsp;", replace_ampersands_not_followed_by_entity("This &nbsp that &nbsp;"));
271
        $this->assertSame("This &amp;nbsp that &nbsp;", replace_ampersands_not_followed_by_entity("This &nbsp that &nbsp;"));
Línea 272... Línea 272...
272
    }
272
    }
273
 
273
 
274
    /**
274
    /**
275
     * @covers ::strip_links
275
     * @covers ::strip_links
276
     */
276
     */
277
    public function test_strip_links() {
277
    public function test_strip_links(): void {
Línea 278... Línea 278...
278
        $this->assertSame('this is a link', strip_links('this is a <a href="http://someaddress.com/query">link</a>'));
278
        $this->assertSame('this is a link', strip_links('this is a <a href="http://someaddress.com/query">link</a>'));
279
    }
279
    }
280
 
280
 
281
    /**
281
    /**
282
     * @covers ::wikify_links
282
     * @covers ::wikify_links
283
     */
283
     */
Línea 284... Línea 284...
284
    public function test_wikify_links() {
284
    public function test_wikify_links(): void {
285
        $this->assertSame('this is a link [ http://someaddress.com/query ]', wikify_links('this is a <a href="http://someaddress.com/query">link</a>'));
285
        $this->assertSame('this is a link [ http://someaddress.com/query ]', wikify_links('this is a <a href="http://someaddress.com/query">link</a>'));
286
    }
286
    }
287
 
287
 
288
    /**
288
    /**
289
     * @covers ::clean_text
289
     * @covers ::clean_text
290
     */
290
     */
291
    public function test_clean_text() {
291
    public function test_clean_text(): void {
292
        $text = "lala <applet>xx</applet>";
292
        $text = "lala <applet>xx</applet>";
Línea 299... Línea 299...
299
    /**
299
    /**
300
     * Test trusttext enabling.
300
     * Test trusttext enabling.
301
     *
301
     *
302
     * @covers ::trusttext_active
302
     * @covers ::trusttext_active
303
     */
303
     */
304
    public function test_trusttext_active() {
304
    public function test_trusttext_active(): void {
305
        global $CFG;
305
        global $CFG;
306
        $this->resetAfterTest();
306
        $this->resetAfterTest();
Línea 307... Línea 307...
307
 
307
 
308
        $this->assertFalse(trusttext_active());
308
        $this->assertFalse(trusttext_active());
Línea 313... Línea 313...
313
    /**
313
    /**
314
     * Test trusttext detection.
314
     * Test trusttext detection.
315
     *
315
     *
316
     * @covers ::trusttext_trusted
316
     * @covers ::trusttext_trusted
317
     */
317
     */
318
    public function test_trusttext_trusted() {
318
    public function test_trusttext_trusted(): void {
319
        global $CFG;
319
        global $CFG;
320
        $this->resetAfterTest();
320
        $this->resetAfterTest();
Línea 321... Línea 321...
321
 
321
 
322
        $syscontext = context_system::instance();
322
        $syscontext = context_system::instance();
Línea 395... Línea 395...
395
     * @param string $rolename
395
     * @param string $rolename
396
     * @param string $format
396
     * @param string $format
397
     * @param int $trust
397
     * @param int $trust
398
     */
398
     */
399
    public function test_trusttext_pre_edit(bool $expectedsanitised, int $enabled, string $rolename,
399
    public function test_trusttext_pre_edit(bool $expectedsanitised, int $enabled, string $rolename,
400
                                            string $format, int $trust) {
400
                                            string $format, int $trust): void {
401
        global $CFG, $DB;
401
        global $CFG, $DB;
402
        $this->resetAfterTest();
402
        $this->resetAfterTest();
Línea 403... Línea 403...
403
 
403
 
404
        $exploit = "abc<script>alert('xss')</script> < > &";
404
        $exploit = "abc<script>alert('xss')</script> < > &";
Línea 431... Línea 431...
431
 
431
 
432
    /**
432
    /**
433
     * Test removal of legacy trusttext flag.
433
     * Test removal of legacy trusttext flag.
434
     * @covers ::trusttext_strip
434
     * @covers ::trusttext_strip
435
     */
435
     */
436
    public function test_trusttext_strip() {
436
    public function test_trusttext_strip(): void {
437
        $this->assertSame('abc', trusttext_strip('abc'));
437
        $this->assertSame('abc', trusttext_strip('abc'));
438
        $this->assertSame('abc', trusttext_strip('ab#####TRUSTTEXT#####c'));
438
        $this->assertSame('abc', trusttext_strip('ab#####TRUSTTEXT#####c'));
Línea 439... Línea 439...
439
    }
439
    }
440
 
440
 
441
    /**
441
    /**
442
     * Test trust option of format_text().
442
     * Test trust option of format_text().
443
     * @covers ::format_text
443
     * @covers ::format_text
444
     */
444
     */
445
    public function test_format_text_trusted() {
445
    public function test_format_text_trusted(): void {
Línea 446... Línea 446...
446
        global $CFG;
446
        global $CFG;
Línea 495... Línea 495...
495
    }
495
    }
Línea 496... Línea 496...
496
 
496
 
497
    /**
497
    /**
498
     * @covers ::qualified_me
498
     * @covers ::qualified_me
499
     */
499
     */
500
    public function test_qualified_me() {
500
    public function test_qualified_me(): void {
501
        global $PAGE, $FULLME, $CFG;
501
        global $PAGE, $FULLME, $CFG;
Línea 502... Línea 502...
502
        $this->resetAfterTest();
502
        $this->resetAfterTest();
Línea 511... Línea 511...
511
    }
511
    }
Línea 512... Línea 512...
512
 
512
 
513
    /**
513
    /**
514
     * @covers \null_progress_trace
514
     * @covers \null_progress_trace
515
     */
515
     */
516
    public function test_null_progress_trace() {
516
    public function test_null_progress_trace(): void {
Línea 517... Línea 517...
517
        $this->resetAfterTest(false);
517
        $this->resetAfterTest(false);
518
 
518
 
519
        $trace = new null_progress_trace();
519
        $trace = new null_progress_trace();
Línea 527... Línea 527...
527
    }
527
    }
Línea 528... Línea 528...
528
 
528
 
529
    /**
529
    /**
530
     * @covers \null_progress_trace
530
     * @covers \null_progress_trace
531
     */
531
     */
532
    public function test_text_progress_trace() {
532
    public function test_text_progress_trace(): void {
Línea 533... Línea 533...
533
        $this->resetAfterTest(false);
533
        $this->resetAfterTest(false);
534
 
534
 
535
        $trace = new text_progress_trace();
535
        $trace = new text_progress_trace();
Línea 541... Línea 541...
541
    }
541
    }
Línea 542... Línea 542...
542
 
542
 
543
    /**
543
    /**
544
     * @covers \html_progress_trace
544
     * @covers \html_progress_trace
545
     */
545
     */
546
    public function test_html_progress_trace() {
546
    public function test_html_progress_trace(): void {
Línea 547... Línea 547...
547
        $this->resetAfterTest(false);
547
        $this->resetAfterTest(false);
548
 
548
 
549
        $trace = new html_progress_trace();
549
        $trace = new html_progress_trace();
Línea 555... Línea 555...
555
    }
555
    }
Línea 556... Línea 556...
556
 
556
 
557
    /**
557
    /**
558
     * @covers \html_list_progress_trace
558
     * @covers \html_list_progress_trace
559
     */
559
     */
560
    public function test_html_list_progress_trace() {
560
    public function test_html_list_progress_trace(): void {
Línea 561... Línea 561...
561
        $this->resetAfterTest(false);
561
        $this->resetAfterTest(false);
562
 
562
 
563
        $trace = new html_list_progress_trace();
563
        $trace = new html_list_progress_trace();
Línea 569... Línea 569...
569
    }
569
    }
Línea 570... Línea 570...
570
 
570
 
571
    /**
571
    /**
572
     * @covers \progress_trace_buffer
572
     * @covers \progress_trace_buffer
573
     */
573
     */
574
    public function test_progress_trace_buffer() {
574
    public function test_progress_trace_buffer(): void {
Línea 575... Línea 575...
575
        $this->resetAfterTest(false);
575
        $this->resetAfterTest(false);
576
 
576
 
577
        $trace = new progress_trace_buffer(new html_progress_trace());
577
        $trace = new progress_trace_buffer(new html_progress_trace());
Línea 598... Línea 598...
598
    }
598
    }
Línea 599... Línea 599...
599
 
599
 
600
    /**
600
    /**
601
     * @covers \combined_progress_trace
601
     * @covers \combined_progress_trace
602
     */
602
     */
603
    public function test_combined_progress_trace() {
603
    public function test_combined_progress_trace(): void {
Línea 604... Línea 604...
604
        $this->resetAfterTest(false);
604
        $this->resetAfterTest(false);
605
 
605
 
Línea 617... Línea 617...
617
    }
617
    }
Línea 618... Línea 618...
618
 
618
 
619
    /**
619
    /**
620
     * @covers ::set_debugging
620
     * @covers ::set_debugging
621
     */
621
     */
622
    public function test_set_debugging() {
622
    public function test_set_debugging(): void {
Línea 623... Línea 623...
623
        global $CFG;
623
        global $CFG;
Línea 624... Línea 624...
624
 
624
 
Línea 660... Línea 660...
660
    }
660
    }
Línea 661... Línea 661...
661
 
661
 
662
    /**
662
    /**
663
     * @covers ::strip_pluginfile_content
663
     * @covers ::strip_pluginfile_content
664
     */
664
     */
665
    public function test_strip_pluginfile_content() {
665
    public function test_strip_pluginfile_content(): void {
666
        $source = <<<SOURCE
666
        $source = <<<SOURCE
Línea 667... Línea 667...
667
Hello!
667
Hello!
Línea 701... Línea 701...
701
    }
701
    }
Línea 702... Línea 702...
702
 
702
 
703
    /**
703
    /**
704
     * @covers \purify_html
704
     * @covers \purify_html
705
     */
705
     */
Línea 706... Línea 706...
706
    public function test_purify_html_ruby() {
706
    public function test_purify_html_ruby(): void {
Línea 707... Línea 707...
707
 
707
 
708
        $this->resetAfterTest();
708
        $this->resetAfterTest();
Línea 725... Línea 725...
725
     * @param int|false $format    The content format
725
     * @param int|false $format    The content format
726
     * @param string    $expected  Expected value
726
     * @param string    $expected  Expected value
727
     * @dataProvider provider_content_to_text
727
     * @dataProvider provider_content_to_text
728
     * @covers ::content_to_text
728
     * @covers ::content_to_text
729
     */
729
     */
730
    public function test_content_to_text($content, $format, $expected) {
730
    public function test_content_to_text($content, $format, $expected): void {
731
        $content = content_to_text($content, $format);
731
        $content = content_to_text($content, $format);
732
        $this->assertEquals($expected, $content);
732
        $this->assertEquals($expected, $content);
733
    }
733
    }
Línea 734... Línea 734...
734
 
734
 
Línea 916... Línea 916...
916
     * @param string $email the email address to test
916
     * @param string $email the email address to test
917
     * @param boolean $result Expected result (true or false)
917
     * @param boolean $result Expected result (true or false)
918
     * @dataProvider    data_validate_email
918
     * @dataProvider    data_validate_email
919
     * @covers ::validate_email
919
     * @covers ::validate_email
920
     */
920
     */
921
    public function test_validate_email($email, $result) {
921
    public function test_validate_email($email, $result): void {
922
        if ($result) {
922
        if ($result) {
923
            $this->assertTrue(validate_email($email));
923
            $this->assertTrue(validate_email($email));
924
        } else {
924
        } else {
925
            $this->assertFalse(validate_email($email));
925
            $this->assertFalse(validate_email($email));
926
        }
926
        }
Línea 1041... Línea 1041...
1041
     * @param string $cfgslasharguments slasharguments setting.
1041
     * @param string $cfgslasharguments slasharguments setting.
1042
     * @param string|false $expected Expected value.
1042
     * @param string|false $expected Expected value.
1043
     * @dataProvider provider_get_file_argument
1043
     * @dataProvider provider_get_file_argument
1044
     * @covers ::get_file_argument
1044
     * @covers ::get_file_argument
1045
     */
1045
     */
1046
    public function test_get_file_argument($server, $cfgslasharguments, $expected) {
1046
    public function test_get_file_argument($server, $cfgslasharguments, $expected): void {
1047
        global $CFG;
1047
        global $CFG;
Línea 1048... Línea 1048...
1048
 
1048
 
1049
        // Overwrite the related settings.
1049
        // Overwrite the related settings.
1050
        $currentsetting = $CFG->slasharguments;
1050
        $currentsetting = $CFG->slasharguments;
Línea 1087... Línea 1087...
1087
    /**
1087
    /**
1088
     * Tests for extract_draft_file_urls_from_text() function.
1088
     * Tests for extract_draft_file_urls_from_text() function.
1089
     *
1089
     *
1090
     * @covers ::extract_draft_file_urls_from_text
1090
     * @covers ::extract_draft_file_urls_from_text
1091
     */
1091
     */
1092
    public function test_extract_draft_file_urls_from_text() {
1092
    public function test_extract_draft_file_urls_from_text(): void {
1093
        global $CFG;
1093
        global $CFG;
Línea 1094... Línea 1094...
1094
 
1094
 
1095
        $url1 = "{$CFG->wwwroot}/draftfile.php/5/user/draft/99999999/test1.jpg";
1095
        $url1 = "{$CFG->wwwroot}/draftfile.php/5/user/draft/99999999/test1.jpg";
Línea 1135... Línea 1135...
1135
    }
1135
    }
Línea 1136... Línea 1136...
1136
 
1136
 
1137
    /**
1137
    /**
1138
     * @covers ::print_password_policy
1138
     * @covers ::print_password_policy
1139
     */
1139
     */
1140
    public function test_print_password_policy() {
1140
    public function test_print_password_policy(): void {
1141
        $this->resetAfterTest(true);
1141
        $this->resetAfterTest(true);
Línea 1142... Línea 1142...
1142
        global $CFG;
1142
        global $CFG;
Línea 1207... Línea 1207...
1207
     * @throws coding_exception If called on a non-local URL.
1207
     * @throws coding_exception If called on a non-local URL.
1208
     * @see \moodle_url::out_as_local_url()
1208
     * @see \moodle_url::out_as_local_url()
1209
     * @covers \moodle_url::out_as_local_url
1209
     * @covers \moodle_url::out_as_local_url
1210
     * @dataProvider out_as_local_url_coding_exception_provider
1210
     * @dataProvider out_as_local_url_coding_exception_provider
1211
     */
1211
     */
1212
    public function test_out_as_local_url_coding_exception(\moodle_url $url, string $exmessage) {
1212
    public function test_out_as_local_url_coding_exception(\moodle_url $url, string $exmessage): void {
1213
        $this->expectException(\coding_exception::class);
1213
        $this->expectException(\coding_exception::class);
1214
        $this->expectExceptionMessage($exmessage);
1214
        $this->expectExceptionMessage($exmessage);
1215
        $localurl = $url->out_as_local_url();
1215
        $localurl = $url->out_as_local_url();
1216
    }
1216
    }
Línea 1244... Línea 1244...
1244
     * @throws coding_exception If called on a non-local URL.
1244
     * @throws coding_exception If called on a non-local URL.
1245
     * @see \moodle_url::out_as_local_url()
1245
     * @see \moodle_url::out_as_local_url()
1246
     * @covers \moodle_url::out_as_local_url
1246
     * @covers \moodle_url::out_as_local_url
1247
     * @dataProvider out_as_local_url_provider
1247
     * @dataProvider out_as_local_url_provider
1248
     */
1248
     */
1249
    public function test_out_as_local_url(\moodle_url $url, string $expected) {
1249
    public function test_out_as_local_url(\moodle_url $url, string $expected): void {
1250
        $this->assertEquals($expected, $url->out_as_local_url(false));
1250
        $this->assertEquals($expected, $url->out_as_local_url(false));
1251
    }
1251
    }
Línea 1252... Línea 1252...
1252
 
1252
 
1253
    /**
1253
    /**
Línea 1285... Línea 1285...
1285
     * @param bool $expected The expected result.
1285
     * @param bool $expected The expected result.
1286
     * @see \moodle_url::is_local_url()
1286
     * @see \moodle_url::is_local_url()
1287
     * @covers \moodle_url::is_local_url
1287
     * @covers \moodle_url::is_local_url
1288
     * @dataProvider is_local_url_provider
1288
     * @dataProvider is_local_url_provider
1289
     */
1289
     */
1290
    public function test_is_local_url(\moodle_url $url, bool $expected) {
1290
    public function test_is_local_url(\moodle_url $url, bool $expected): void {
1291
        $this->assertEquals($expected, $url->is_local_url(), "'{$url}' is not a local URL!");
1291
        $this->assertEquals($expected, $url->is_local_url(), "'{$url}' is not a local URL!");
1292
    }
1292
    }
Línea 1293... Línea 1293...
1293
 
1293
 
1294
    /**
1294
    /**