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 TemplateParserTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @dataProvider provideStyleSeparator |
18
|
|
|
* |
19
|
|
|
* @param $text |
20
|
|
|
* @param $expected |
21
|
|
|
*/ |
22
|
6 |
|
public function testFindUserStyleSeparator($text, $expected) |
23
|
|
|
{ |
24
|
6 |
|
$this::assertSame( |
25
|
6 |
|
$expected, |
26
|
6 |
|
TemplateParser::findUserStyleSeparator($text) |
27
|
|
|
); |
28
|
6 |
|
} |
29
|
|
|
|
30
|
|
|
public static function provideStyleSeparator() |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
['{{Ouvrage|langue=fr|prénom1=Ernest|nom1=Nègre|titre=Toponymie}}', '|'], |
34
|
|
|
['{{Ouvrage |langue=fr |prénom1=Ernest |nom1=Nègre |titre=Toponymie }}', ' |'], |
35
|
|
|
['{{Ouvrage | langue=fr | prénom1=Ernest | nom1=Nègre | titre=Toponymie }}', ' | '], |
36
|
|
|
[ |
37
|
|
|
'{{Ouvrage |
38
|
|
|
|langue=fr |
39
|
|
|
|prénom1=Ernest |
40
|
|
|
|nom1=Nègre |
41
|
|
|
|titre=Toponymie |
42
|
|
|
}}', |
43
|
|
|
"\n|", |
44
|
|
|
], |
45
|
|
|
['{{Ouvrage |
46
|
|
|
|langue=fr |
47
|
|
|
|prénom1=Ernest |
48
|
|
|
|nom1=Nègre |
49
|
|
|
|titre=Toponymie |
50
|
|
|
}}', |
51
|
|
|
"\n |", |
52
|
|
|
], |
53
|
|
|
['{{Ouvrage |
54
|
|
|
| langue=fr |
55
|
|
|
}}', |
56
|
|
|
"\n | ", |
57
|
|
|
], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @dataProvider provideParseDataFromTemplate |
63
|
|
|
* |
64
|
|
|
* @param $template |
65
|
|
|
* @param $text |
66
|
|
|
*/ |
67
|
|
|
public function testParseDataFromTemplate($template, $text, array $expected) |
68
|
|
|
{ |
69
|
|
|
$this::assertEquals( |
70
|
|
|
$expected, |
71
|
|
|
TemplateParser::parseDataFromTemplate($template, $text) |
72
|
|
|
); |
73
|
2 |
|
} |
74
|
|
|
|
75
|
2 |
|
/** |
76
|
2 |
|
* TODO {{nobr|Alexandre {{IV}}}} |
77
|
2 |
|
* todo \n. |
78
|
|
|
* |
79
|
2 |
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public static function provideParseDataFromTemplate() |
82
|
|
|
{ |
83
|
|
|
return [ |
84
|
|
|
['ouvrage', '{{ ouvrage | title =bla | nom = po }}', ['title' => 'bla', 'nom' => 'po']], |
85
|
|
|
['ouvrage', '{{ouvrage|bla|po}}', ['1' => 'bla', '2' => 'po']], |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @dataProvider providePageTemplate |
91
|
|
|
*/ |
92
|
|
|
public function testExtractPageTemplateContent(string $text, $expected) |
93
|
|
|
{ |
94
|
|
|
$this::assertSame( |
95
|
|
|
$expected, |
96
|
|
|
TemplateParser::extractPageTemplateContent($text) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function providePageTemplate(): array |
101
|
|
|
{ |
102
|
|
|
return [ |
103
|
|
|
['bla', null], |
104
|
|
|
['bla {{P.}}250 bla', ['{{P.}}250', '250']], |
105
|
|
|
['bla {{p.|125-133}} bla', ['{{p.|125-133}}', '125-133']], |
106
|
|
|
['bla {{p.}}125-133 bla', ['{{p.}}125-133', '125-133']], |
107
|
|
|
['bla {{p.}}10, 20, 35-36 bla', ['{{p.}}10, 20, 35-36', '10, 20, 35-36']], |
108
|
|
|
['{{p.|125-133}} bla {{p.|55}}', ['{{p.|125-133}}', '125-133']], |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|