|
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\OuvrageTemplate; |
|
14
|
|
|
use App\Domain\Models\Wiki\TemplateConverter; |
|
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= |pages= |issn= |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 |pages= |issn= |lire en ligne= |doi=10.1016/j.agee.2011.03.020}}', |
|
54
|
|
|
], |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @dataProvider provideConvertOuvrage2Article |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testConvertFromOuvrage(string $ouvrageSerial, string $articleSerial) |
|
62
|
|
|
{ |
|
63
|
|
|
$ouvrage = \App\Domain\WikiTemplateFactory::create('ouvrage'); |
|
64
|
|
|
$ouvrage->hydrateFromText($ouvrageSerial); |
|
65
|
|
|
|
|
66
|
|
|
$article = TemplateConverter::ArticleFromOuvrage($ouvrage); |
|
|
|
|
|
|
67
|
|
|
$this::assertSame( |
|
68
|
|
|
$articleSerial, |
|
69
|
|
|
$article->serialize(true) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public final function provideConvertOuvrage2Article(): array |
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
[ |
|
77
|
|
|
'{{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}}', |
|
78
|
|
|
"{{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 |issn= |lire en ligne=https://www.jstor.org/stable/1453892}}", |
|
79
|
|
|
], |
|
80
|
|
|
[ |
|
81
|
|
|
"{{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}}", |
|
82
|
|
|
"{{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 |issn= |isbn=978-0-30010-469-1 |lire en ligne={{Google Livres|AS_NXFoY0M4C}}}}", |
|
83
|
|
|
], |
|
84
|
|
|
[ |
|
85
|
|
|
"{{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}}", |
|
86
|
|
|
"{{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 |pages= |issn=0245-8411 |lire en ligne=}}", |
|
87
|
|
|
], |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|