|
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\Tests; |
|
11
|
|
|
|
|
12
|
|
|
use App\Domain\Models\Wiki\OuvrageClean; |
|
13
|
|
|
use App\Domain\Models\Wiki\OuvrageTemplate; |
|
14
|
|
|
use App\Domain\OuvrageComplete; |
|
15
|
|
|
use Exception; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class OuvrageCompleteTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testGetResult() |
|
21
|
|
|
{ |
|
22
|
|
|
$origin = new OuvrageTemplate(); |
|
23
|
|
|
$origin->hydrateFromText( |
|
24
|
|
|
'{{Ouvrage |id =Bonneton|nom1=Collectif | titre = Loiret : un département à l\'élégance naturelle | éditeur = Christine Bonneton | lieu = Paris | année = 2 septembre 1998 | isbn = 978-2-86253-234-9| pages totales = 319 }}' |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
$google = new OuvrageTemplate(); |
|
28
|
|
|
$google->hydrateFromText( |
|
29
|
|
|
'{{ouvrage|langue=fr|auteur1=Clément Borgal|titre=Loiret|année=1998|pages totales=319|isbn=9782862532349}}' |
|
30
|
|
|
); |
|
31
|
|
|
|
|
32
|
|
|
$comp = new OuvrageComplete($origin, $google); |
|
33
|
|
|
$this::assertEquals( |
|
34
|
|
|
'{{Ouvrage |langue=fr |id=Bonneton |nom1=Collectif |titre=Loiret : un département à l\'élégance naturelle |éditeur=Christine Bonneton |lieu=Paris |année=2 septembre 1998 |isbn=978-2-86253-234-9 |pages totales=319}}', |
|
35
|
|
|
$comp->getResult()->serialize() |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @dataProvider provideComplete |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $originStr |
|
43
|
|
|
* @param string $onlineStr |
|
44
|
|
|
* @param string $expected |
|
45
|
|
|
* |
|
46
|
|
|
* @throws Exception |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testComplete(string $originStr, string $onlineStr, string $expected) |
|
49
|
|
|
{ |
|
50
|
|
|
$origin = new OuvrageTemplate(); |
|
51
|
|
|
$origin->hydrateFromText($originStr); |
|
52
|
|
|
|
|
53
|
|
|
$online = new OuvrageClean(); |
|
54
|
|
|
$online->hydrateFromText($onlineStr); |
|
55
|
|
|
|
|
56
|
|
|
$comp = new OuvrageComplete($origin, $online); |
|
57
|
|
|
$this::assertEquals( |
|
58
|
|
|
$expected, |
|
59
|
|
|
$comp->getResult()->serialize(true) |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function provideComplete() |
|
64
|
|
|
{ |
|
65
|
|
|
return [ |
|
66
|
|
|
[ |
|
67
|
|
|
// Wikidata+BnF completion of sitelinks |
|
68
|
|
|
'{{Ouvrage|prénom1=Paul|nom1=Durand|titre=La vie}}', |
|
69
|
|
|
'{{Ouvrage|prénom1=Paul|nom1=Durand|lien auteur1=Paul Durand (écrivain)|titre=La Vie|lien titre=La Vie (livre)}}', |
|
70
|
|
|
'{{Ouvrage|prénom1=Paul|nom1=Durand|lien auteur1=Paul Durand (écrivain)|titre=La vie|lien titre=La Vie (livre)|éditeur=|année=|isbn=}}', |
|
71
|
|
|
], |
|
72
|
|
|
[ |
|
73
|
|
|
// Wikidata+BnF completion of sitelinks : prénoms différents |
|
74
|
|
|
'{{Ouvrage|prénom1=Paul A.|nom1=Durand|titre=La vie|isbn=1234}}', |
|
75
|
|
|
'{{Ouvrage|prénom1=Paul-André|nom1=Durand|lien auteur1=Paul Durand (écrivain)|titre=La Vie|isbn=1234}}', |
|
76
|
|
|
'{{Ouvrage|prénom1=Paul A.|nom1=Durand|lien auteur1=Paul Durand (écrivain)|titre=La vie|éditeur=|année=|isbn=1234}}', |
|
77
|
|
|
], |
|
78
|
|
|
[ |
|
79
|
|
|
// Google partiel |
|
80
|
|
|
'{{Ouvrage|titre=}}', |
|
81
|
|
|
'{{Ouvrage|titre=|présentation en ligne=https://books.google.com/books?id=day56Sz-rEEC}}', |
|
82
|
|
|
'{{Ouvrage|titre=|éditeur=|année=|isbn=|lire en ligne=https://books.google.com/books?id=day56Sz-rEEC}}', |
|
83
|
|
|
], |
|
84
|
|
|
[ |
|
85
|
|
|
// Google total |
|
86
|
|
|
'{{Ouvrage|titre=}}', |
|
87
|
|
|
'{{Ouvrage|titre=|lire en ligne=https://books.google.com/books?id=day56Sz-rEEC}}', |
|
88
|
|
|
'{{Ouvrage|titre=|éditeur=|année=|isbn=|lire en ligne=https://books.google.com/books?id=day56Sz-rEEC}}', |
|
89
|
|
|
], |
|
90
|
|
|
[ |
|
91
|
|
|
//isbn invalide |
|
92
|
|
|
'{{Ouvrage|titre=}}', |
|
93
|
|
|
'{{Ouvrage|titre=|isbn invalide=bla}}', |
|
94
|
|
|
'{{Ouvrage|titre=|éditeur=|année=|isbn=}}', |
|
95
|
|
|
], |
|
96
|
|
|
// date/année |
|
97
|
|
|
[ |
|
98
|
|
|
'{{Ouvrage|titre=}}', |
|
99
|
|
|
'{{Ouvrage|titre=|année=2009}}', |
|
100
|
|
|
'{{Ouvrage|titre=|éditeur=|année=2009|isbn=}}', |
|
101
|
|
|
], |
|
102
|
|
|
[ |
|
103
|
|
|
'{{Ouvrage|titre=|date=2011}}', |
|
104
|
|
|
'{{Ouvrage|titre=|année=2009}}', |
|
105
|
|
|
'{{Ouvrage|titre=|éditeur=|date=2011|isbn=}}', |
|
106
|
|
|
], |
|
107
|
|
|
/* |
|
108
|
|
|
* titre + sous-titre |
|
109
|
|
|
*/ // pas d'ajout si déjà titre volume/chapitre/tome ou nature ouvrage |
|
110
|
|
|
[ |
|
111
|
|
|
'{{Ouvrage|titre = Loiret Joli|titre chapitre=Bla}}', |
|
112
|
|
|
'{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}', |
|
113
|
|
|
'{{Ouvrage|titre=Loiret Joli|éditeur=|année=|isbn=|titre chapitre=Bla}}', |
|
114
|
|
|
], |
|
115
|
|
|
// titres identiques mais sous-titre manquant |
|
116
|
|
|
[ |
|
117
|
|
|
'{{Ouvrage|titre = Loiret Joli}}', |
|
118
|
|
|
'{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}', |
|
119
|
|
|
'{{Ouvrage|titre=Loiret Joli|sous-titre=un département|éditeur=|année=|isbn=}}', |
|
120
|
|
|
], |
|
121
|
|
|
// punctuation titre différente, sous-titre manquant |
|
122
|
|
|
[ |
|
123
|
|
|
'{{Ouvrage|titre = Loiret Joli !!!!}}', |
|
124
|
|
|
'{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}', |
|
125
|
|
|
'{{Ouvrage|titre=Loiret Joli !!!!|sous-titre=un département|éditeur=|année=|isbn=}}', |
|
126
|
|
|
], |
|
127
|
|
|
// sous-titre inclus dans titre original |
|
128
|
|
|
[ |
|
129
|
|
|
'{{Ouvrage|titre = Loiret Joli : un département}}', |
|
130
|
|
|
'{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}', |
|
131
|
|
|
'{{Ouvrage|titre=Loiret Joli|sous-titre=un département|éditeur=|année=|isbn=}}', |
|
132
|
|
|
], |
|
133
|
|
|
// sous-titre absent online |
|
134
|
|
|
[ |
|
135
|
|
|
'{{Ouvrage|titre = Loiret Joli|sous-titre=un département}}', |
|
136
|
|
|
'{{Ouvrage|titre = Loiret Joli}}', |
|
137
|
|
|
'{{Ouvrage|titre=Loiret Joli|sous-titre=un département|éditeur=|année=|isbn=}}', |
|
138
|
|
|
], |
|
139
|
|
|
// titre absent online |
|
140
|
|
|
[ |
|
141
|
|
|
'{{Ouvrage|auteur1=bla|titre = Loiret Joli}}', |
|
142
|
|
|
'{{Ouvrage|auteur1=bla}}', |
|
143
|
|
|
'{{Ouvrage|auteur1=bla|titre=Loiret Joli|éditeur=|année=|isbn=}}', |
|
144
|
|
|
], |
|
145
|
|
|
// titre volume existe -> skip |
|
146
|
|
|
[ |
|
147
|
|
|
'{{Ouvrage|titre = Loiret Joli|titre volume=Bla}}', |
|
148
|
|
|
'{{Ouvrage|titre = Loiret Joli|sous-titre=Fubar}}', |
|
149
|
|
|
'{{Ouvrage|titre=Loiret Joli|titre volume=Bla|éditeur=|année=|isbn=}}', |
|
150
|
|
|
], |
|
151
|
|
|
[ |
|
152
|
|
|
'{{Ouvrage|titre = Loiret Joli|collection=Bla}}', |
|
153
|
|
|
'{{Ouvrage|titre = Loiret Joli|sous-titre=Fubar}}', |
|
154
|
|
|
'{{Ouvrage|titre=Loiret Joli|éditeur=|collection=Bla|année=|isbn=}}', |
|
155
|
|
|
], |
|
156
|
|
|
]; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @dataProvider provideAuthors |
|
161
|
|
|
* |
|
162
|
|
|
* @throws Exception |
|
163
|
|
|
*/ |
|
164
|
|
|
public function testSameAuthors($originStr, $onlineStr, bool $same) |
|
165
|
|
|
{ |
|
166
|
|
|
$origin = new OuvrageTemplate(); |
|
167
|
|
|
$origin->hydrateFromText($originStr); |
|
168
|
|
|
|
|
169
|
|
|
$online = new OuvrageClean(); |
|
170
|
|
|
$online->hydrateFromText($onlineStr); |
|
171
|
|
|
|
|
172
|
|
|
$comp = new OuvrageComplete($origin, $online); |
|
173
|
|
|
$this::assertEquals( |
|
174
|
|
|
$same, |
|
175
|
|
|
$comp->hasSameAuthors() |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function provideAuthors(): array |
|
180
|
|
|
{ |
|
181
|
|
|
return [ |
|
182
|
|
|
[ |
|
183
|
|
|
'{{Ouvrage|auteurs=Bob Martin|titre =Bla}}', |
|
184
|
|
|
'{{Ouvrage|prénom1=Bob|nom1=Martin|titre =Bla}}', |
|
185
|
|
|
true, |
|
186
|
|
|
], |
|
187
|
|
|
[ |
|
188
|
|
|
'{{Ouvrage|auteurs=Bob Martin|titre =Bla}}', |
|
189
|
|
|
'{{Ouvrage|prénom1=TATA|nom1=Martin|titre =Bla}}', |
|
190
|
|
|
false, |
|
191
|
|
|
], |
|
192
|
|
|
]; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|