Passed
Push — master ( aea8b9...d57411 )
by Dispositif
03:07
created

WikiRefsFixerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 203
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 95
c 1
b 0
f 1
dl 0
loc 203
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A provideFixGenericWikiSyntax() 0 80 1
A provideFixRefSpacingSyntax() 0 14 1
A testFixConcatenatedRefs() 0 3 1
A testFixRefSpacingSyntax() 0 3 1
A provideConcatenatedRefFixture() 0 65 1
A testFixRefWikiSyntax() 0 3 1
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 WikiRefsFixerTest extends TestCase
15
{
16
    public static function provideConcatenatedRefFixture(): array
17
    {
18
        return [
19
            [
20
                // skip
21
                '<references>
22
                <ref name="A">fu</ref>
23
                <ref name="B">fu</ref>',
24
                '<references>
25
                <ref name="A">fu</ref>
26
                <ref name="B">fu</ref>',
27
            ],
28
            [
29
                // skip
30
                '{{{Références | références=
31
                <ref name="A">fu</ref>
32
                <ref name="B">fu</ref>}}',
33
                '{{{Références | références=
34
                <ref name="A">fu</ref>
35
                <ref name="B">fu</ref>}}',
36
            ],
37
            [
38
                '{{Références nombreuses|taille=30 | références=
39
                <!-- :0 -->
40
                <ref name="A">fu</ref>
41
                <ref name="B">fu</ref>',
42
                '{{Références nombreuses|taille=30 | références=
43
                <!-- :0 -->
44
                <ref name="A">fu</ref>
45
                <ref name="B">fu</ref>',
46
            ],
47
            ['<ref>fu</ref><ref name="1">bar</ref>', '<ref>fu</ref>{{,}}<ref name="1">bar</ref>'],
48
            ['<ref>fu</ref>  <ref name="1">bar</ref>', '<ref>fu</ref>{{,}}<ref name="1">bar</ref>'],
49
            [
50
                // carriage return
51
                '<ref>fu</ref>
52
            <ref name="1">bar</ref>', '<ref>fu</ref>{{,}}<ref name="1">bar</ref>'],
53
            ['<ref>fu</ref>{{,}}<ref name="1">bar</ref>', '<ref>fu</ref>{{,}}<ref name="1">bar</ref>'],
54
            ['<ref name="A" /> <ref name="B">', '<ref name="A" />{{,}}<ref name="B">'],
55
            ['<ref name=A /><ref name="B">', '<ref name=A />{{,}}<ref name="B">'],
56
            ['<ref name=A/><ref name="B">', '<ref name=A/>{{,}}<ref name="B">'],
57
            // sfn
58
            [
59
                '<ref name=A/>{{Sfn|O. Teissier|1860|p=42-43}}<ref name=B/>',
60
                '<ref name=A/>{{,}}{{Sfn|O. Teissier|1860|p=42-43}}{{,}}<ref name=B/>',
61
            ],
62
            [
63
                '</ref>{{Sfn|O. Teissier|1860|p=42-43}}<ref name=B>',
64
                '</ref>{{,}}{{Sfn|O. Teissier|1860|p=42-43}}{{,}}<ref name=B>',
65
            ],
66
            [
67
                '{{Sfn|O. Teissier}}{{Sfn|O. Teissier}}',
68
                '{{Sfn|O. Teissier}}{{,}}{{Sfn|O. Teissier}}',
69
            ],
70
            ['</ref><ref group=n>fu</ref>', '</ref>{{,}}<ref group=n>fu</ref>'],
71
            [
72
                // inchanged with {{Références|références=
73
                '<ref name="A">fu</ref><ref name="B">bar</ref><ref name="C"/> bla {{Références|références=  <ref name="C">fu</ref><ref name="D">bar</ref> bla',
74
                '<ref name="A">fu</ref><ref name="B">bar</ref><ref name="C"/> bla {{Références|références=  <ref name="C">fu</ref><ref name="D">bar</ref> bla',
75
            ],
76
            [
77
                // inchanged with multilines {{Références|références=
78
                '<ref name="A">fu</ref><ref name="B">bar</ref><ref name="C"/> bla {{Références
79
                |références=<ref name="C">fu</ref><ref name="D">bar</ref> bla',
80
                '<ref name="A">fu</ref><ref name="B">bar</ref><ref name="C"/> bla {{Références
81
                |références=<ref name="C">fu</ref><ref name="D">bar</ref> bla',
82
            ],
83
        ];
84
    }
85
86
    public static function provideFixRefSpacingSyntax(): array
87
    {
88
        return [
89
            ['bla <ref>A</ref>.', 'bla<ref>A</ref>.'],
90
            ['bla <ref name="C"/>', 'bla<ref name="C"/>'],
91
            ['| <ref>', '| <ref>'], // unchanged
92
            ['| <ref name="C"/>', '| <ref name="C"/>'], // unchanged
93
            ['= <ref>', '= <ref>'], // unchanged
94
            ['= <ref name="C"/>', '= <ref name="C"/>'], // unchanged
95
            ['5 <ref>', '5 <ref>'], // unchanged
96
            ['9 <ref name="C"/>', '9 <ref name="C"/>'], // unchanged
97
            ['<ref> A </ref>', '<ref> A </ref>'],
98
            ['bla <ref name="B">A</ref>', 'bla<ref name="B">A</ref>'],
99
            ['bla <ref name="C"/> bla', 'bla<ref name="C"/> bla'],
100
        ];
101
    }
102
103
    public static function provideFixGenericWikiSyntax(): array
104
    {
105
        return [
106
            [
107
                <<<EOF
108
                {{Infobox}}
109
                Blab <ref name="A">fu</ref>
110
                <ref name="B">fu</ref>.
111
                bzear
112
                {{Références |taille=3 |références=
113
                
114
                <ref name="C">fu</ref>
115
                <ref name="D">fu</ref> <ref name="E">fu</ref>
116
                }}
117
                EOF,
118
                <<<EOF
119
                {{Infobox}}
120
                Blab<ref name="A">fu</ref>{{,}}<ref name="B">fu</ref>.
121
                bzear
122
                {{Références |taille=3 |références=
123
                
124
                <ref name="C">fu</ref>
125
                <ref name="D">fu</ref> <ref name="E">fu</ref>
126
                }}
127
                EOF
128
    ,
129
            ],
130
            [
131
                <<<EOF
132
                {{Infobox}}
133
                Blab <ref name="A">fu</ref>
134
                <ref name="B">fu</ref>.
135
                bzear
136
                {{Références nombreuses |taille=3 |références=
137
                <ref name="C">fu</ref>
138
                <ref name="D">fu</ref>
139
                }}
140
                EOF,
141
                <<<EOF
142
                {{Infobox}}
143
                Blab<ref name="A">fu</ref>{{,}}<ref name="B">fu</ref>.
144
                bzear
145
                {{Références nombreuses |taille=3 |références=
146
                <ref name="C">fu</ref>
147
                <ref name="D">fu</ref>
148
                }}
149
                EOF,
150
            ],
151
            [
152
                <<<EOF
153
                {{Infobox}}
154
                Blab <ref name="A">fu</ref>
155
                <ref name="B">fu</ref>.
156
                bzear
157
                {{Références nombreuses |taille=3 |références=
158
                <ref name="C">fu</ref>
159
                <ref name="D">fu</ref>
160
                }}
161
                EOF,
162
                <<<EOF
163
                {{Infobox}}
164
                Blab<ref name="A">fu</ref>{{,}}<ref name="B">fu</ref>.
165
                bzear
166
                {{Références nombreuses |taille=3 |références=
167
                <ref name="C">fu</ref>
168
                <ref name="D">fu</ref>
169
                }}
170
                EOF,
171
            ],
172
            [
173
                "le ''Paso de l'[[abrivado]]'', spécialement composé par [[Eddie Vartan]]
174
175
== Notes et références ==
176
{{Références|groupe=Note|colonnes=2}}
177
{{Références|références=
178
<ref name=ATP>
179
{{Pdf}}{{Lien web|url=http://www.sports.gouv.fr/IMG/pdf/atlas.pdf|titre=Atlas national des fédérations sportives 2012.|site=www.sports.gouv.fr|consulté le=05 mars 2015}}
180
.</ref>
181
|colonnes=2}}",
182
                "le ''Paso de l'[[abrivado]]'', spécialement composé par [[Eddie Vartan]]
183
184
== Notes et références ==
185
{{Références|groupe=Note|colonnes=2}}
186
{{Références|références=
187
<ref name=ATP>
188
{{Pdf}}{{Lien web|url=http://www.sports.gouv.fr/IMG/pdf/atlas.pdf|titre=Atlas national des fédérations sportives 2012.|site=www.sports.gouv.fr|consulté le=05 mars 2015}}
189
.</ref>
190
|colonnes=2}}",
191
            ],
192
        ];
193
    }
194
195
    /**
196
     * @dataProvider provideConcatenatedRefFixture
197
     */
198
    public function testFixConcatenatedRefs($text, $expected)
199
    {
200
        $this::assertSame($expected, WikiRefsFixer::fixConcatenatedRefsSyntax($text));
201
    }
202
203
    /**
204
     * @dataProvider provideFixRefSpacingSyntax
205
     */
206
    public function testFixRefSpacingSyntax($text, $expected)
207
    {
208
        $this::assertSame($expected, WikiRefsFixer::fixRefSpacingSyntax($text));
209
    }
210
211
    /**
212
     * @dataProvider provideFixGenericWikiSyntax
213
     */
214
    public function testFixRefWikiSyntax($text, $expected)
215
    {
216
        $this::assertSame($expected, WikiRefsFixer::fixRefWikiSyntax($text));
217
    }
218
}
219