Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 41... Línea 41...
41
    /**
41
    /**
42
     * Tests the static parse charset method.
42
     * Tests the static parse charset method.
43
     *
43
     *
44
     * @covers ::parse_charset()
44
     * @covers ::parse_charset()
45
     */
45
     */
46
    public function test_parse_charset() {
46
    public function test_parse_charset(): void {
47
        $this->assertSame('windows-1250', core_text::parse_charset('Cp1250'));
47
        $this->assertSame('windows-1250', core_text::parse_charset('Cp1250'));
48
        // Some encoding moodle does not use.
48
        // Some encoding moodle does not use.
49
        $this->assertSame('windows-1252', core_text::parse_charset('ms-ansi'));
49
        $this->assertSame('windows-1252', core_text::parse_charset('ms-ansi'));
50
    }
50
    }
Línea 51... Línea 51...
51
 
51
 
52
    /**
52
    /**
53
     * Tests the static convert method.
53
     * Tests the static convert method.
54
     *
54
     *
55
     * @covers ::convert()
55
     * @covers ::convert()
56
     */
56
     */
57
    public function test_convert() {
57
    public function test_convert(): void {
58
        $this->assertSame('', core_text::convert('', 'utf-8', 'utf-8'));
58
        $this->assertSame('', core_text::convert('', 'utf-8', 'utf-8'));
59
        $utf8 = "Žluťoučký koníček";
59
        $utf8 = "Žluťoučký koníček";
60
        $iso2 = pack("H*", "ae6c75bb6f75e86bfd206b6f6eede8656b");
60
        $iso2 = pack("H*", "ae6c75bb6f75e86bfd206b6f6eede8656b");
61
        $win  = pack("H*", "8e6c759d6f75e86bfd206b6f6eede8656b");
61
        $win  = pack("H*", "8e6c759d6f75e86bfd206b6f6eede8656b");
Línea 114... Línea 114...
114
    /**
114
    /**
115
     * Tests the static sub string method.
115
     * Tests the static sub string method.
116
     *
116
     *
117
     * @covers ::substr()
117
     * @covers ::substr()
118
     */
118
     */
119
    public function test_substr() {
119
    public function test_substr(): void {
120
        $str = "Žluťoučký koníček";
120
        $str = "Žluťoučký koníček";
121
        $this->assertSame($str, core_text::substr($str, 0));
121
        $this->assertSame($str, core_text::substr($str, 0));
122
        $this->assertSame('luťoučký koníček', core_text::substr($str, 1));
122
        $this->assertSame('luťoučký koníček', core_text::substr($str, 1));
123
        $this->assertSame('luť', core_text::substr($str, 1, 3));
123
        $this->assertSame('luť', core_text::substr($str, 1, 3));
124
        $this->assertSame($str, core_text::substr($str, 0, 100));
124
        $this->assertSame($str, core_text::substr($str, 0, 100));
Línea 164... Línea 164...
164
    /**
164
    /**
165
     * Tests the static string length method.
165
     * Tests the static string length method.
166
     *
166
     *
167
     * @covers ::strlen()
167
     * @covers ::strlen()
168
     */
168
     */
169
    public function test_strlen() {
169
    public function test_strlen(): void {
170
        $str = "Žluťoučký koníček";
170
        $str = "Žluťoučký koníček";
171
        $this->assertSame(17, core_text::strlen($str));
171
        $this->assertSame(17, core_text::strlen($str));
Línea 172... Línea 172...
172
 
172
 
173
        $iso2 = pack("H*", "ae6c75bb6f75e86bfd206b6f6eede8656b");
173
        $iso2 = pack("H*", "ae6c75bb6f75e86bfd206b6f6eede8656b");
Línea 209... Línea 209...
209
    /**
209
    /**
210
     * Test unicode safe string truncation.
210
     * Test unicode safe string truncation.
211
     *
211
     *
212
     * @covers ::str_max_bytes()
212
     * @covers ::str_max_bytes()
213
     */
213
     */
214
    public function test_str_max_bytes() {
214
    public function test_str_max_bytes(): void {
215
        // These are all 3 byte characters, so this is a 12-byte string.
215
        // These are all 3 byte characters, so this is a 12-byte string.
216
        $str = '言語設定';
216
        $str = '言語設定';
Línea 217... Línea 217...
217
 
217
 
Línea 264... Línea 264...
264
    /**
264
    /**
265
     * Tests the static strtolower method.
265
     * Tests the static strtolower method.
266
     *
266
     *
267
     * @covers ::strtolower()
267
     * @covers ::strtolower()
268
     */
268
     */
269
    public function test_strtolower() {
269
    public function test_strtolower(): void {
270
        $str = "Žluťoučký koníček";
270
        $str = "Žluťoučký koníček";
271
        $low = 'žluťoučký koníček';
271
        $low = 'žluťoučký koníček';
272
        $this->assertSame($low, core_text::strtolower($str));
272
        $this->assertSame($low, core_text::strtolower($str));
Línea 273... Línea 273...
273
 
273
 
Línea 306... Línea 306...
306
    /**
306
    /**
307
     * Tests the static strtoupper.
307
     * Tests the static strtoupper.
308
     *
308
     *
309
     * @covers ::strtoupper()
309
     * @covers ::strtoupper()
310
     */
310
     */
311
    public function test_strtoupper() {
311
    public function test_strtoupper(): void {
312
        $str = "Žluťoučký koníček";
312
        $str = "Žluťoučký koníček";
313
        $up  = 'ŽLUŤOUČKÝ KONÍČEK';
313
        $up  = 'ŽLUŤOUČKÝ KONÍČEK';
314
        $this->assertSame($up, core_text::strtoupper($str));
314
        $this->assertSame($up, core_text::strtoupper($str));
Línea 315... Línea 315...
315
 
315
 
Línea 345... Línea 345...
345
    /**
345
    /**
346
     * Test the strrev method.
346
     * Test the strrev method.
347
     *
347
     *
348
     * @covers ::strrev()
348
     * @covers ::strrev()
349
     */
349
     */
350
    public function test_strrev() {
350
    public function test_strrev(): void {
351
        $strings = array(
351
        $strings = array(
352
            "Žluťoučký koníček" => "kečínok ýkčuoťulŽ",
352
            "Žluťoučký koníček" => "kečínok ýkčuoťulŽ",
353
            'ŽLUŤOUČKÝ KONÍČEK' => "KEČÍNOK ÝKČUOŤULŽ",
353
            'ŽLUŤOUČKÝ KONÍČEK' => "KEČÍNOK ÝKČUOŤULŽ",
354
            '言語設定' => '定設語言',
354
            '言語設定' => '定設語言',
355
            '简体中文' => '文中体简',
355
            '简体中文' => '文中体简',
Línea 370... Línea 370...
370
    /**
370
    /**
371
     * Tests the static strpos method.
371
     * Tests the static strpos method.
372
     *
372
     *
373
     * @covers ::strpos()
373
     * @covers ::strpos()
374
     */
374
     */
375
    public function test_strpos() {
375
    public function test_strpos(): void {
376
        $str = "Žluťoučký koníček";
376
        $str = "Žluťoučký koníček";
377
        $this->assertSame(10, core_text::strpos($str, 'koníč'));
377
        $this->assertSame(10, core_text::strpos($str, 'koníč'));
Línea 378... Línea 378...
378
 
378
 
379
        // Check that null argument is allowed.
379
        // Check that null argument is allowed.
Línea 383... Línea 383...
383
    /**
383
    /**
384
     * Tests the static strrpos.
384
     * Tests the static strrpos.
385
     *
385
     *
386
     * @covers ::strrpos()
386
     * @covers ::strrpos()
387
     */
387
     */
388
    public function test_strrpos() {
388
    public function test_strrpos(): void {
389
        $str = "Žluťoučký koníček";
389
        $str = "Žluťoučký koníček";
390
        $this->assertSame(11, core_text::strrpos($str, 'o'));
390
        $this->assertSame(11, core_text::strrpos($str, 'o'));
Línea 391... Línea 391...
391
 
391
 
392
        // Check that null argument is allowed.
392
        // Check that null argument is allowed.
Línea 396... Línea 396...
396
    /**
396
    /**
397
     * Tests the static specialtoascii method.
397
     * Tests the static specialtoascii method.
398
     *
398
     *
399
     * @covers ::specialtoascii()
399
     * @covers ::specialtoascii()
400
     */
400
     */
401
    public function test_specialtoascii() {
401
    public function test_specialtoascii(): void {
402
        $str = "Žluťoučký koníček";
402
        $str = "Žluťoučký koníček";
403
        $this->assertSame('Zlutoucky konicek', core_text::specialtoascii($str));
403
        $this->assertSame('Zlutoucky konicek', core_text::specialtoascii($str));
Línea 404... Línea 404...
404
 
404
 
405
        $utf8 = "Der eine stößt den Speer zum Mann";
405
        $utf8 = "Der eine stößt den Speer zum Mann";
Línea 425... Línea 425...
425
     * Tests the static encode_mimeheader method.
425
     * Tests the static encode_mimeheader method.
426
     *
426
     *
427
     * @covers ::encode_mimeheader()
427
     * @covers ::encode_mimeheader()
428
     * @covers \moodle_phpmailer::encodeHeader()
428
     * @covers \moodle_phpmailer::encodeHeader()
429
     */
429
     */
430
    public function test_encode_mimeheader() {
430
    public function test_encode_mimeheader(): void {
431
        global $CFG;
431
        global $CFG;
432
        require_once($CFG->libdir.'/phpmailer/moodle_phpmailer.php');
432
        require_once($CFG->libdir.'/phpmailer/moodle_phpmailer.php');
433
        $mailer = new moodle_phpmailer();
433
        $mailer = new moodle_phpmailer();
Línea 434... Línea 434...
434
 
434
 
Línea 468... Línea 468...
468
    /**
468
    /**
469
     * Tests the static entities_to_utf8 method.
469
     * Tests the static entities_to_utf8 method.
470
     *
470
     *
471
     * @covers ::entities_to_utf8()
471
     * @covers ::entities_to_utf8()
472
     */
472
     */
473
    public function test_entities_to_utf8() {
473
    public function test_entities_to_utf8(): void {
474
        $str = "Žluťoučký koníček©"&<>§«";
474
        $str = "Žluťoučký koníček©"&<>§«";
475
        $this->assertSame("Žluťoučký koníček©\"&<>§«", core_text::entities_to_utf8($str));
475
        $this->assertSame("Žluťoučký koníček©\"&<>§«", core_text::entities_to_utf8($str));
Línea 476... Línea 476...
476
 
476
 
477
        // Check that null argument is allowed.
477
        // Check that null argument is allowed.
Línea 481... Línea 481...
481
    /**
481
    /**
482
     * Tests the static utf8_to_entities method.
482
     * Tests the static utf8_to_entities method.
483
     *
483
     *
484
     * @covers ::utf8_to_entities()
484
     * @covers ::utf8_to_entities()
485
     */
485
     */
486
    public function test_utf8_to_entities() {
486
    public function test_utf8_to_entities(): void {
487
        $str = "&#x17d;luťoučký kon&iacute;ček&copy;&quot;&amp;&lt;&gt;&sect;&laquo;";
487
        $str = "&#x17d;luťoučký kon&iacute;ček&copy;&quot;&amp;&lt;&gt;&sect;&laquo;";
488
        $this->assertSame("&#x17d;lu&#x165;ou&#x10d;k&#xfd; kon&iacute;&#x10d;ek&copy;&quot;&amp;&lt;&gt;&sect;&laquo;", core_text::utf8_to_entities($str));
488
        $this->assertSame("&#x17d;lu&#x165;ou&#x10d;k&#xfd; kon&iacute;&#x10d;ek&copy;&quot;&amp;&lt;&gt;&sect;&laquo;", core_text::utf8_to_entities($str));
489
        $this->assertSame("&#381;lu&#357;ou&#269;k&#253; kon&iacute;&#269;ek&copy;&quot;&amp;&lt;&gt;&sect;&laquo;", core_text::utf8_to_entities($str, true));
489
        $this->assertSame("&#381;lu&#357;ou&#269;k&#253; kon&iacute;&#269;ek&copy;&quot;&amp;&lt;&gt;&sect;&laquo;", core_text::utf8_to_entities($str, true));
Línea 490... Línea 490...
490
 
490
 
Línea 500... Línea 500...
500
    /**
500
    /**
501
     * Tests the static trim_utf8_bom method.
501
     * Tests the static trim_utf8_bom method.
502
     *
502
     *
503
     * @covers ::trim_utf8_bom()
503
     * @covers ::trim_utf8_bom()
504
     */
504
     */
505
    public function test_trim_utf8_bom() {
505
    public function test_trim_utf8_bom(): void {
506
        $bom = "\xef\xbb\xbf";
506
        $bom = "\xef\xbb\xbf";
507
        $str = "Žluťoučký koníček";
507
        $str = "Žluťoučký koníček";
508
        $this->assertSame($str.$bom, core_text::trim_utf8_bom($bom.$str.$bom));
508
        $this->assertSame($str.$bom, core_text::trim_utf8_bom($bom.$str.$bom));
Línea 509... Línea 509...
509
 
509
 
Línea 514... Línea 514...
514
    /**
514
    /**
515
     * Tests the static remove_unicode_non_characters method.
515
     * Tests the static remove_unicode_non_characters method.
516
     *
516
     *
517
     * @covers ::remove_unicode_non_characters()
517
     * @covers ::remove_unicode_non_characters()
518
     */
518
     */
519
    public function test_remove_unicode_non_characters() {
519
    public function test_remove_unicode_non_characters(): void {
520
        // Confirm that texts which don't contain these characters are unchanged.
520
        // Confirm that texts which don't contain these characters are unchanged.
521
        $this->assertSame('Frogs!', core_text::remove_unicode_non_characters('Frogs!'));
521
        $this->assertSame('Frogs!', core_text::remove_unicode_non_characters('Frogs!'));
Línea 522... Línea 522...
522
 
522
 
523
        // Even if they contain some very scary characters.
523
        // Even if they contain some very scary characters.
Línea 540... Línea 540...
540
    /**
540
    /**
541
     * Tests the static get_encodings method.
541
     * Tests the static get_encodings method.
542
     *
542
     *
543
     * @covers ::get_encodings()
543
     * @covers ::get_encodings()
544
     */
544
     */
545
    public function test_get_encodings() {
545
    public function test_get_encodings(): void {
546
        $encodings = core_text::get_encodings();
546
        $encodings = core_text::get_encodings();
547
        $this->assertTrue(is_array($encodings));
547
        $this->assertTrue(is_array($encodings));
548
        $this->assertTrue(count($encodings) > 1);
548
        $this->assertTrue(count($encodings) > 1);
549
        $this->assertTrue(isset($encodings['UTF-8']));
549
        $this->assertTrue(isset($encodings['UTF-8']));
550
    }
550
    }
Línea 552... Línea 552...
552
    /**
552
    /**
553
     * Tests the static code2utf8 method.
553
     * Tests the static code2utf8 method.
554
     *
554
     *
555
     * @covers ::code2utf8()
555
     * @covers ::code2utf8()
556
     */
556
     */
557
    public function test_code2utf8() {
557
    public function test_code2utf8(): void {
558
        $this->assertSame('Ž', core_text::code2utf8(381));
558
        $this->assertSame('Ž', core_text::code2utf8(381));
559
    }
559
    }
Línea 560... Línea 560...
560
 
560
 
561
    /**
561
    /**
562
     * Tests the static utf8ord method.
562
     * Tests the static utf8ord method.
563
     *
563
     *
564
     * @covers ::utf8ord()
564
     * @covers ::utf8ord()
565
     */
565
     */
566
    public function test_utf8ord() {
566
    public function test_utf8ord(): void {
567
        $this->assertSame(ord(''), core_text::utf8ord(''));
567
        $this->assertSame(ord(''), core_text::utf8ord(''));
568
        $this->assertSame(ord('f'), core_text::utf8ord('f'));
568
        $this->assertSame(ord('f'), core_text::utf8ord('f'));
569
        $this->assertSame(0x03B1, core_text::utf8ord('α'));
569
        $this->assertSame(0x03B1, core_text::utf8ord('α'));
570
        $this->assertSame(0x0439, core_text::utf8ord('й'));
570
        $this->assertSame(0x0439, core_text::utf8ord('й'));
Línea 578... Línea 578...
578
    /**
578
    /**
579
     * Tests the static strtotitle method.
579
     * Tests the static strtotitle method.
580
     *
580
     *
581
     * @covers ::strtotitle()
581
     * @covers ::strtotitle()
582
     */
582
     */
583
    public function test_strtotitle() {
583
    public function test_strtotitle(): void {
584
        $str = "žluťoučký koníček";
584
        $str = "žluťoučký koníček";
585
        $this->assertSame("Žluťoučký Koníček", core_text::strtotitle($str));
585
        $this->assertSame("Žluťoučký Koníček", core_text::strtotitle($str));
Línea 586... Línea 586...
586
 
586
 
587
        // Check that null argument is allowed.
587
        // Check that null argument is allowed.
Línea 591... Línea 591...
591
    /**
591
    /**
592
     * Test strrchr.
592
     * Test strrchr.
593
     *
593
     *
594
     * @covers ::strrchr()
594
     * @covers ::strrchr()
595
     */
595
     */
596
    public function test_strrchr() {
596
    public function test_strrchr(): void {
597
        $str = "Žluťoučký koníček";
597
        $str = "Žluťoučký koníček";
598
        $this->assertSame('koníček', core_text::strrchr($str, 'koní'));
598
        $this->assertSame('koníček', core_text::strrchr($str, 'koní'));
599
        $this->assertSame('Žluťoučký ', core_text::strrchr($str, 'koní', true));
599
        $this->assertSame('Žluťoučký ', core_text::strrchr($str, 'koní', true));
600
        $this->assertFalse(core_text::strrchr($str, 'A'));
600
        $this->assertFalse(core_text::strrchr($str, 'A'));
601
        $this->assertFalse(core_text::strrchr($str, 'ç', true));
601
        $this->assertFalse(core_text::strrchr($str, 'ç', true));
Línea 610... Línea 610...
610
     * @dataProvider is_charset_supported_provider()
610
     * @dataProvider is_charset_supported_provider()
611
     * @param string $charset
611
     * @param string $charset
612
     * @param bool $expected
612
     * @param bool $expected
613
     * @covers ::is_charset_supported()
613
     * @covers ::is_charset_supported()
614
     */
614
     */
615
    public function test_is_charset_supported(string $charset, bool $expected) {
615
    public function test_is_charset_supported(string $charset, bool $expected): void {
616
        $charset = core_text::parse_charset($charset);
616
        $charset = core_text::parse_charset($charset);
617
        $this->assertEquals($expected, core_text::is_charset_supported($charset));
617
        $this->assertEquals($expected, core_text::is_charset_supported($charset));
618
    }
618
    }
Línea 619... Línea 619...
619
 
619