Passed
Push — master ( bacc5f...5eccc7 )
by Dispositif
02:22
created

WikiPageActionTest::provideReplaceTemplateInText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nc 1
nop 0
dl 0
loc 40
rs 9.504
c 0
b 0
f 0
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\Application\Tests;
11
12
use App\Application\WikiPageAction;
13
use PHPUnit\Framework\TestCase;
14
15
class WikiPageActionTest extends TestCase
16
{
17
    /**
18
     * @dataProvider provideReplaceTemplateInText
19
     *
20
     * @param string $text
21
     * @param string $origin
22
     * @param string $replace
23
     * @param string $expected
24
     */
25
    public function testReplaceTemplateInText(string $text, string $origin, string $replace, string $expected)
26
    {
27
        $this::assertSame(
28
            $expected,
29
            WikiPageAction::replaceTemplateInText($text, $origin, $replace)
30
        );
31
    }
32
33
    public function provideReplaceTemplateInText()
34
    {
35
        return [
36
            [
37
                // saut de ligne {{en}} \n{{ouvrage}}
38
                "zzzzzzz {{Ouvrage|langue=|titre=bla}} zzzz {{de}}
39
{{Ouvrage|langue=|titre=bla}} zerqsdfqs",
40
                '{{Ouvrage|langue=|titre=bla}}',
41
                '{{Ouvrage|langue=|titre=BLO}}',
42
                "zzzzzzz {{Ouvrage|langue=de|titre=BLO}} zzzz {{Ouvrage|langue=de|titre=BLO}} zerqsdfqs",
43
            ],
44
            [
45
                'zzzzzzz {{ouvrage|titre=ping}} aaa {{Ouvrage|langue=|titre=bla}} zzzz {{de}} {{Ouvrage|langue=|titre=bla}} zerqsdfqs',
46
                '{{Ouvrage|langue=|titre=bla}}',
47
                '{{Ouvrage|langue=|titre=BLO}}',
48
                'zzzzzzz {{ouvrage|titre=ping}} aaa {{Ouvrage|langue=de|titre=BLO}} zzzz {{Ouvrage|langue=de|titre=BLO}} zerqsdfqs',
49
            ],
50
            [
51
                'zzzzzzz {{Ouvrage|titre=bla}} zzzz {{en}} {{Ouvrage|titre=bla}} zerqsdfqs',
52
                '{{Ouvrage|titre=bla}}',
53
                '{{Ouvrage|lang=en|titre=BLO}}',
54
                'zzzzzzz {{Ouvrage|lang=en|titre=BLO}} zzzz {{Ouvrage|lang=en|titre=BLO}} zerqsdfqs',
55
            ],
56
            [
57
                'zzzzzzz {{Ouvrage|titre=bla}} zzzz {{fr}} {{Ouvrage|titre=bla}} zerqsdfqs',
58
                '{{Ouvrage|titre=bla}}',
59
                '{{Ouvrage|titre=BLO}}',
60
                'zzzzzzz {{Ouvrage|titre=BLO}} zzzz {{fr}} {{Ouvrage|titre=BLO}} zerqsdfqs',
61
            ],
62
            [
63
                'zzzzzzz {{Ouvrage|titre=bla}} zzzz {{fr}} {{Ouvrage|titre=bla}} zerqsdfqs',
64
                '{{Ouvrage|titre=bla}}',
65
                '{{Ouvrage|langue=fr|titre=BLO}}',
66
                'zzzzzzz {{Ouvrage|langue=fr|titre=BLO}} zzzz {{fr}} {{Ouvrage|langue=fr|titre=BLO}} zerqsdfqs',
67
            ],
68
            [
69
                'zzzzzzz {{Ouvrage|langue=fr|titre=bla}} zzzz {{fr}} {{Ouvrage|langue=fr|titre=bla}} zerqsdfqs',
70
                '{{Ouvrage|langue=fr|titre=bla}}',
71
                '{{Ouvrage|langue=fr|titre=BLO}}',
72
                'zzzzzzz {{Ouvrage|langue=fr|titre=BLO}} zzzz {{fr}} {{Ouvrage|langue=fr|titre=BLO}} zerqsdfqs',
73
            ],
74
        ];
75
    }
76
77
    //    public function testIntegration()
78
    //    {
79
    //        // Mediawiki namespace not PSR-4
80
    //        require_once __DIR__.'/../../../vendor/addwiki/mediawiki-api-base/tests/Integration/TestEnvironment.php';
81
    //        putenv('ADDWIKI_MW_API=http://localhost:8888/api.php');
82
    //
83
    ////        $api = MediawikiApi::newFromPage( TestEnvironment::newInstance()->getPageUrl() );
84
    ////        $this::assertInstanceOf( 'Mediawiki\Api\MediawikiApi', $api );
85
    //        $api = TestEnvironment::newInstance()->getApi();
86
    //        $page = new WikiPageAction(new MediawikiFactory($api), 'test');
87
    //        $this::assertInstanceOf('App\Application\WikiPageAction', $page);
88
    ////        dump($page);
89
    //    }
90
}
91