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