Passed
Push — master ( dff8a4...2556d0 )
by Dispositif
08:19
created

TextUtilTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 38
c 2
b 0
f 0
dl 0
loc 84
ccs 27
cts 27
cp 1
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testStripPunctuation() 0 5 1
A testBreakingSpace() 0 7 1
A testStripAccents() 0 5 1
A testMb_ucfirst() 0 5 1
A testPredictCorrectParam() 0 5 1
A testStrEndsWith() 0 13 1
A testStr_starts_with() 0 13 1
A testCountAllCapsWords() 0 3 1
A testCutTextOnSpace() 0 3 1
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Domain\Utils;
11
12
use PHPUnit\Framework\TestCase;
13
14
class TextUtilTest extends TestCase
15
{
16 1
    public function testBreakingSpace()
17
    {
18 1
        $html = "bla&nbsp;bla\n";
19 1
        $text = html_entity_decode($html);
20 1
        $this::assertSame(
21 1
            'bla bla',
22 1
            TextUtil::trim(TextUtil::replaceNonBreakingSpaces($text))
23
        );
24 1
    }
25
26 1
    public function testMb_ucfirst()
27
    {
28 1
        $this::assertSame(
29 1
            'Économie galante',
30 1
            TextUtil::mb_ucfirst('économie galante')
31
        );
32 1
    }
33
34 1
    public function testStripPunctuation()
35
    {
36 1
        $this::assertSame(
37 1
            'blabla',
38 1
            TextUtil::stripPunctuation('bla¦}©§bla')
39
        );
40 1
    }
41
42 1
    public function testStripAccents()
43
    {
44 1
        $this::assertSame(
45 1
            'Ecealo',
46 1
            TextUtil::stripAccents('Écéàlô')
47
        );
48 1
    }
49
50 1
    public function testPredictCorrectParam()
51
    {
52 1
        $this::assertSame(
53 1
            'auteur',
54 1
            TextUtil::predictCorrectParam('autuer', ['auteur', 'bla', 'hautour'])
55
        );
56 1
    }
57
58
    public function testStrEndsWith()
59
    {
60
        $this::assertSame(
61
            true,
62
            TextUtil::str_ends_with('testaà', 'aà')
63
        );
64
        $this::assertSame(
65
            false,
66
            TextUtil::str_ends_with('testaà', 'test')
67
        );
68
        $this::assertSame(
69
            true,
70
            TextUtil::str_ends_with('testaà', '')
71
        );
72
    }
73
74
    public function testStr_starts_with()
75
    {
76
        $this::assertSame(
77
            true,
78
            TextUtil::str_starts_with('téstaà', 'tést')
79
        );
80
        $this::assertSame(
81
            false,
82
            TextUtil::str_starts_with('téstaa', 'aa')
83
        );
84
        $this::assertSame(
85
            true,
86
            TextUtil::str_starts_with('téstaa', '')
87
        );
88
    }
89
90
    public function testCutTextOnSpace()
91
    {
92
        $this::assertSame('bla bla…', TextUtil::cutTextOnSpace('bla bla bla', 8));
93
    }
94
95
    public function testCountAllCapsWords()
96
    {
97
        $this::assertSame(2, TextUtil::countAllCapsWords('Bla BLA Bla BLA'));
98
    }
99
}
100