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\Models\Wiki\Tests; |
11
|
|
|
|
12
|
|
|
use App\Domain\Models\Wiki\OuvrageTemplate; |
13
|
|
|
use App\Domain\WikiTemplateFactory; |
14
|
|
|
use Exception; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class AbstractWikiTemplateTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
public function testIsValidForEdit(){ |
20
|
|
|
$article = WikiTemplateFactory::create('article'); |
21
|
|
|
$article->hydrate( |
22
|
|
|
[ |
23
|
|
|
'auteur' => 'Michou', |
24
|
|
|
'titre' => 'Au soleil', |
25
|
|
|
'périodique' => 'Paris Match', |
26
|
|
|
'année' => '2010', // équivalence 'date' |
27
|
|
|
] |
28
|
|
|
); |
29
|
|
|
$this::assertTrue($article->isValidForEdit()); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
$articleInc = WikiTemplateFactory::create('article'); |
33
|
|
|
$articleInc->hydrate( |
34
|
|
|
[ |
35
|
|
|
'auteur' => 'Michou', |
36
|
|
|
'titre' => 'Au soleil', |
37
|
|
|
'date' => '2010', // année ??? |
38
|
|
|
] |
39
|
|
|
); |
40
|
|
|
$this::assertFalse($articleInc->isValidForEdit()); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
$empty = new OuvrageTemplate(); |
44
|
|
|
$this::assertFalse($empty->isValidForEdit()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testOuvrageSerialize() |
48
|
|
|
{ |
49
|
|
|
$ouvrage = WikiTemplateFactory::create('ouvrage'); |
50
|
|
|
$ouvrage->hydrate( |
51
|
|
|
[ |
52
|
|
|
'nom1' => 'Michou', |
53
|
|
|
'prénom1' => 'Bob', |
54
|
|
|
'titre' => 'Au soleil', |
55
|
|
|
] |
56
|
|
|
); |
57
|
|
|
$ouvrage->setParam('auteur2', 'Sophie'); |
58
|
|
|
$this::assertSame( |
59
|
|
|
'{{Ouvrage|nom1=Michou|auteur2=Sophie|prénom1=Bob|titre=Au soleil|éditeur=|année=|pages totales=|isbn=}}', |
60
|
|
|
$ouvrage->serialize() |
61
|
|
|
); |
62
|
|
|
$this::assertSame( |
63
|
|
|
'{{Ouvrage|prénom1=Bob|nom1=Michou|auteur2=Sophie|titre=Au soleil|éditeur=|année=|pages totales=|isbn=}}', |
64
|
|
|
$ouvrage->serialize(true) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @throws Exception |
70
|
|
|
*/ |
71
|
|
|
public function testSerialize() |
72
|
|
|
{ |
73
|
|
|
$data = [ |
74
|
|
|
// '1' => 'fr', |
75
|
|
|
'url' => 'http://google.com', |
76
|
|
|
'auteur1' => 'Bob', |
77
|
|
|
'date' => '2010-11-25', |
78
|
|
|
'titre' => 'foo bar', |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
$lienWeb = WikiTemplateFactory::create('lien web'); |
82
|
|
|
$lienWeb->hydrate($data); |
83
|
|
|
|
84
|
|
|
$this::assertSame( |
85
|
|
|
'{{lien web|auteur1=Bob|titre=Foo bar|url=http://google.com|date=2010-11-25|consulté le=}}', |
86
|
|
|
$lienWeb->serialize(true) |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$this::assertSame( |
90
|
|
|
'{{lien web|url=http://google.com|auteur1=Bob|date=2010-11-25|consulté le=|titre=Foo bar}}', |
91
|
|
|
$lienWeb->serialize() |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$lienWeb->userSeparator = "\n|"; |
95
|
|
|
$this::assertSame( |
96
|
|
|
'{{lien web |
97
|
|
|
|url=http://google.com |
98
|
|
|
|auteur1=Bob |
99
|
|
|
|date=2010-11-25 |
100
|
|
|
|consulté le= |
101
|
|
|
|titre=Foo bar |
102
|
|
|
}}', |
103
|
|
|
$lienWeb->serialize() |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$lienWeb->userMultiSpaced = true; |
107
|
|
|
$lienWeb->userSeparator = "\n|"; |
108
|
|
|
$this::assertSame( |
109
|
|
|
'{{lien web |
110
|
|
|
|url = http://google.com |
111
|
|
|
|auteur1 = Bob |
112
|
|
|
|date = 2010-11-25 |
113
|
|
|
|consulté le = |
114
|
|
|
|titre = Foo bar |
115
|
|
|
}}', |
116
|
|
|
$lienWeb->serialize() |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testAliasParameter() |
121
|
|
|
{ |
122
|
|
|
$lienWeb = WikiTemplateFactory::create('lien web'); |
123
|
|
|
$lienWeb->hydrate( |
124
|
|
|
[ |
125
|
|
|
'lang' => 'fr', |
126
|
|
|
] |
127
|
|
|
); |
128
|
|
|
$this::assertSame( |
129
|
|
|
'{{lien web|langue=fr|titre=|url=|consulté le=}}', |
130
|
|
|
$lienWeb->serialize() |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function testEmptyValue() |
136
|
|
|
{ |
137
|
|
|
$data = [ |
138
|
|
|
'url' => 'http://google.com', |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
$lienWeb = WikiTemplateFactory::create('lien web'); |
142
|
|
|
$lienWeb->hydrate($data); |
143
|
|
|
|
144
|
|
|
$lienWeb->setParam('url', ''); |
145
|
|
|
|
146
|
|
|
$this::assertSame( |
147
|
|
|
'{{lien web|titre=|url=|consulté le=}}', |
148
|
|
|
$lienWeb->serialize(true) |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testUserOrder() |
153
|
|
|
{ |
154
|
|
|
$data = [ |
155
|
|
|
'url' => 'http://google.com', |
156
|
|
|
'langue' => 'fr', |
157
|
|
|
]; |
158
|
|
|
|
159
|
|
|
$lienWeb = WikiTemplateFactory::create('lien web'); |
160
|
|
|
$lienWeb->hydrate($data); |
161
|
|
|
|
162
|
|
|
$this::assertSame( |
163
|
|
|
'{{lien web|langue=fr|titre=|url=http://google.com|consulté le=}}', |
164
|
|
|
$lienWeb->serialize(true) |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|