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