Completed
Push — master ( 2f5cae...701262 )
by Joschi
03:21
created

ParserTest::testEmptyDefaultVocabulary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/**
4
 * rdfa-lite-microdata
5
 *
6
 * @category Jkphl
7
 * @package Jkphl\RdfaLiteMicrodata
8
 * @subpackage Jkphl\RdfaLiteMicrodata\Tests
9
 * @author Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Jkphl\RdfaLiteMicrodata\Tests\Application;
38
39
use Jkphl\RdfaLiteMicrodata\Application\Parser\Parser;
40
use Jkphl\RdfaLiteMicrodata\Infrastructure\Factories\HtmlDocumentFactory;
41
use Jkphl\RdfaLiteMicrodata\Infrastructure\Parser\RdfaLiteElementProcessor;
42
use Jkphl\RdfaLiteMicrodata\Infrastructure\Service\ThingGateway;
43
44
/**
45
 * Parser tests
46
 *
47
 * @package Jkphl\RdfaLiteMicrodata
48
 * @subpackage Jkphl\RdfaLiteMicrodata\Tests
49
 */
50
class ParserTest extends ParserIteratorTestBase
51
{
52
    /**
53
     * Test person parsing
54
     */
55
    public function testPerson()
56
    {
57
        $htmlDocumentFactory = new HtmlDocumentFactory();
58
        $rdfaElementProcessor = new RdfaLiteElementProcessor();
59
        $parser = new Parser($htmlDocumentFactory, $rdfaElementProcessor);
60
        $this->assertInstanceOf(Parser::class, $parser);
61
62
        $things = $parser->parse(self::$personRdfa);
63
        $this->validatePersonResult($things);
64
    }
65
66
    /**
67
     * Test article parsing
68
     */
69
    public function testArticle()
70
    {
71
        $htmlDocumentFactory = new HtmlDocumentFactory();
72
        $rdfaElementProcessor = new RdfaLiteElementProcessor();
73
        $parser = new Parser($htmlDocumentFactory, $rdfaElementProcessor);
74
        $this->assertInstanceOf(Parser::class, $parser);
75
76
        $things = $parser->parse(
77
            file_get_contents(
78
                dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'article-rdfa-lite.html'
79
            )
80
        );
81
        $this->assertArrayEquals(
82
            $this->castArray(
83
                json_decode(
84
                    file_get_contents(
85
                        dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'article-rdfa-lite.json'
86
                    )
87
                )
88
            ),
89
            $this->castArray((new ThingGateway())->export($things))
90
        );
91
    }
92
93
    /**
94
     * Test empty default vocabulary parsing
95
     *
96
     * @expectedException \Jkphl\RdfaLiteMicrodata\Infrastructure\Exceptions\RuntimeException
97
     * @expectedExceptionCode 1487030264
98
     */
99
    public function testEmptyDefaultVocabulary()
100
    {
101
        $htmlDocumentFactory = new HtmlDocumentFactory();
102
        $rdfaElementProcessor = new RdfaLiteElementProcessor();
103
        $parser = new Parser($htmlDocumentFactory, $rdfaElementProcessor);
104
        $this->assertInstanceOf(Parser::class, $parser);
105
106
        $parser->parse(
107
            file_get_contents(
108
                dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'empty-default-vocab-rdfa-lite.html'
109
            )
110
        );
111
    }
112
113
    /**
114
     * Test unknown vocabulary prefix parsing
115
     *
116
     * @expectedException \Jkphl\RdfaLiteMicrodata\Infrastructure\Exceptions\OutOfBoundsException
117
     * @expectedExceptionCode 1486928423
118
     */
119
    public function testUnknownVocabularyPrefix()
120
    {
121
        $htmlDocumentFactory = new HtmlDocumentFactory();
122
        $rdfaElementProcessor = new RdfaLiteElementProcessor();
123
        $parser = new Parser($htmlDocumentFactory, $rdfaElementProcessor);
124
        $this->assertInstanceOf(Parser::class, $parser);
125
126
        $parser->parse(
127
            file_get_contents(
128
                dirname(
129
                    __DIR__
130
                ).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'unknown-vocab-prefix-rdfa-lite.html'
131
            )
132
        );
133
    }
134
}
135