Passed
Push — master ( 99b995...983f4d )
by Dispositif
02:27
created

WikiTextUtilTest::testGetWikilinkPages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * This file is part of dispositif/wikibot application
4
 * 2019 : Philippe M. <[email protected]>
5
 * For the full copyright and MIT license information, please 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 WikiTextUtilTest extends TestCase
15
{
16
    /**
17
     * @dataProvider provideExternalLink
18
     */
19
    public function testStripExternalLink($text, $expected)
20
    {
21
        $this::assertSame(
22
            $expected,
23
            WikiTextUtil::stripExternalLink($text)
24
        );
25
    }
26
27
    public function provideExternalLink(): array
28
    {
29
        return [
30
            ['[[fu]] [http://google.fr bla] [http://google.com blo]', '[[fu]] bla blo'],
31
            ['bla [http://google.fr]', 'bla'],
32
        ];
33
    }
34
35
    public function testUpperfirst()
36
    {
37
        $this::assertSame(
38
            'Économie',
39
            WikiTextUtil::mb_ucfirst('économie')
40
        );
41
    }
42
43
    public function testLowerfirst()
44
    {
45
        $this::assertSame(
46
            'économie',
47
            WikiTextUtil::mb_lowerfirst('Économie')
48
        );
49
    }
50
51
    public function testGetWikilinkPages()
52
    {
53
        $text = 'bla [[fu|bar]] et [[back]] mais pas [[wikt:toto|bou]]';
54
55
        $this::assertSame(
56
            ['fu', 'back'],
57
            WikiTextUtil::getWikilinkPages($text)
58
        );
59
    }
60
61
    public function testRemoveHTMLcomments()
62
    {
63
        $text = 'blabla<!-- sdfqfqs 
64
<!-- blbal 
65
    --> ez';
66
        $this::assertSame(
67
            'blabla ez',
68
            WikiTextUtil::removeHTMLcomments($text)
69
        );
70
    }
71
72
    public function testIsCommented()
73
    {
74
        $text = 'blabla<!-- sdfqfqs 
75
        --> ez';
76
        $this::assertSame(
77
            true,
78
            WikiTextUtil::isCommented($text)
79
        );
80
81
        $this::assertSame(
82
            false,
83
            WikiTextUtil::isCommented('bla')
84
        );
85
    }
86
87
    /**
88
     * @dataProvider provideWikify
89
     *
90
     * @param string $text
91
     * @param string $expected
92
     */
93
    public function testUnWikify(string $text, string $expected)
94
    {
95
        $this::assertEquals(
96
            $expected,
97
            WikiTextUtil::unWikify($text)
98
        );
99
    }
100
101
    public function provideWikify()
102
    {
103
        return [
104
            ['blabla<!-- fu -->', 'blabla'],
105
            ['{{lang|en|fubar}}', 'fubar'],
106
            ['{{langue|en|fubar}}', 'fubar'],
107
            ['[[wikilien]', 'wikilien'],
108
            ['[[wiki|wikilien]]', 'wikilien'],
109
            ['{{en}}', '{{en}}'],
110
        ];
111
    }
112
}
113