Passed
Push — dev ( 043eb4...bf3609 )
by Dispositif
06:23
created

provideConvertOuvrage2Article()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 14
rs 10
c 1
b 0
f 0
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);
1 ignored issue
show
Bug introduced by
It seems like $ouvrage can also be of type App\Domain\Models\Wiki\ArticleTemplate and App\Domain\Models\Wiki\GoogleLivresTemplate and App\Domain\Models\Wiki\LienBriseTemplate and App\Domain\Models\Wiki\LienWebTemplate; however, parameter $ouvrage of App\Domain\Models\Wiki\T...r::ArticleFromOuvrage() does only seem to accept App\Domain\Models\Wiki\OuvrageTemplate, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        $article = TemplateConverter::ArticleFromOuvrage(/** @scrutinizer ignore-type */ $ouvrage);
Loading history...
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