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\ArticleTemplate; |
13
|
|
|
use App\Domain\Models\Wiki\TemplateConverter; |
14
|
|
|
use App\Domain\WikiTemplateFactory; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class ArticleTemplateTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @dataProvider provideArticleSerialize |
21
|
|
|
*/ |
22
|
|
|
public function testArticleSerialize(array $data, string $serial) |
23
|
|
|
{ |
24
|
|
|
$art = new ArticleTemplate(); |
25
|
|
|
$art->hydrate($data); |
26
|
|
|
$this::assertSame( |
27
|
|
|
$serial, |
28
|
|
|
$art->serialize(true) |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function provideArticleSerialize(): array |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
[ |
36
|
|
|
['titre' => 'bla'], |
37
|
|
|
'{{Article |auteur1= |titre=bla |périodique= |date= |lire en ligne=}}', |
38
|
|
|
], |
39
|
|
|
[ |
40
|
|
|
// {{article | langue = en | auteur1 = T. Breeze | auteur2 = A. Bailey | auteur3 = K. Balcombe | auteur4 = S. Potts | titre = Pollination services in the UK: How important are honeybees? | journal = Agriculture, Ecosystems and Environment | date = août 2011 | doi = 10.1016/j.agee.2011.03.020 }} |
41
|
|
|
[ |
42
|
|
|
'langue' => 'en', |
43
|
|
|
'auteur1' => 'T. Breeze', |
44
|
|
|
'auteur2' => 'A. Bailey', |
45
|
|
|
'auteur3' => 'K. Balcombe', |
46
|
|
|
'auteur4' => 'S. Potts', |
47
|
|
|
'titre' => 'Pollination services in the UK: How important are honeybees?', |
48
|
|
|
'journal' => 'Agriculture, Ecosystems and Environment', |
49
|
|
|
'numéro' => '13', |
50
|
|
|
'date' => 'août 2011', |
51
|
|
|
'doi' => '10.1016/j.agee.2011.03.020', |
52
|
|
|
], |
53
|
|
|
'{{Article |langue=en |auteur1=T. Breeze |auteur2=A. Bailey |auteur3=K. Balcombe |auteur4=S. Potts |titre=Pollination services in the UK: How important are honeybees? |périodique=Agriculture, Ecosystems and Environment |numéro=13 |date=août 2011 |lire en ligne= |doi=10.1016/j.agee.2011.03.020}}', |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @dataProvider provideConvertOuvrage2Article |
60
|
|
|
* @throws \Exception |
61
|
|
|
*/ |
62
|
|
|
public function testConvertFromOuvrage(string $ouvrageSerial, string $articleSerial) |
63
|
|
|
{ |
64
|
|
|
$ouvrage = WikiTemplateFactory::create('ouvrage'); |
65
|
|
|
$ouvrage->hydrateFromText($ouvrageSerial); |
66
|
|
|
|
67
|
|
|
/** @noinspection PhpParamsInspection */ |
68
|
|
|
$article = TemplateConverter::ArticleFromOuvrage(/** @scrutinizer ignore-type */ $ouvrage); |
69
|
|
|
$this::assertSame( |
70
|
|
|
$articleSerial, |
71
|
|
|
$article->serialize(true) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public final function provideConvertOuvrage2Article(): array |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
[ |
79
|
|
|
'{{Ouvrage|langue=en|auteur=Barry Walfish|lire en ligne=https://www.jstor.org/stable/1453892|titre=The Two Commentaries of Abraham Ibn Ezra on the Book of Esther|périodique=The Jewish Quarterly Review, New Series|tome=79|numéro=4|mois=avril|année=1989|passage=323-343|éditeur=University of Pennsylvania Press}}', |
80
|
|
|
"{{Article |langue=en |auteur1=Barry Walfish |titre=The Two Commentaries of Abraham Ibn Ezra on the Book of Esther |périodique=The Jewish Quarterly Review, New Series |éditeur=University of Pennsylvania Press |volume=79 |numéro=4 |date=avril 1989 |pages=323-343 |lire en ligne=https://www.jstor.org/stable/1453892}}", |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
"{{Ouvrage|langue=en|auteur=Hans Vlieghe|titre=Flemish Art and Architecture, 1585-1700|périodique=The Burlington Magazine|lieu=New Haven|éditeur=Yale University Press|année=1998|lire en ligne={{Google Livres|AS_NXFoY0M4C}}|isbn=978-0-30010-469-1|pages totales=339}}", |
84
|
|
|
"{{Article |langue=en |auteur1=Hans Vlieghe |titre=Flemish Art and Architecture, 1585-1700 |périodique=The Burlington Magazine |lieu=New Haven |éditeur=Yale University Press |date=1998 |pages=339 |isbn=978-0-30010-469-1 |lire en ligne={{Google Livres|AS_NXFoY0M4C}}}}", |
85
|
|
|
], |
86
|
|
|
[ |
87
|
|
|
"{{Ouvrage|nom1=Collectif|prénom2=Alphonse|nom2= Wollbrett|directeur2=oui|titre=Le canton de Bouxwiller|lieu= Saverne|éditeur=SHASE|année=1978|issn=0245-8411|périodique=Pays d'Alsace|numéro=103bis}}", |
88
|
|
|
"{{Article |auteur1= |nom1=Collectif |prénom2=Alphonse |nom2=Wollbrett |directeur2=oui |titre=Le canton de Bouxwiller |périodique=Pays d'Alsace |lieu=Saverne |éditeur=SHASE |numéro=103bis |date=1978 |issn=0245-8411 |lire en ligne=}}", |
89
|
|
|
], |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|