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

TextUtilTest::testCutTextOnSpace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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