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\Ports; |
38
|
|
|
|
39
|
|
|
use Jkphl\RdfaLiteMicrodata\Ports\Parser\RdfaLite\Html; |
40
|
|
|
use Jkphl\RdfaLiteMicrodata\Ports\Parser\RdfaLite\Xml; |
41
|
|
|
use Jkphl\RdfaLiteMicrodata\Tests\AbstractTest; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* RDFa Lite parser tests |
45
|
|
|
* |
46
|
|
|
* @package Jkphl\RdfaLiteMicrodata |
47
|
|
|
* @subpackage Jkphl\RdfaLiteMicrodata\Tests |
48
|
|
|
*/ |
49
|
|
|
class RdfaLiteParserTest extends AbstractTest |
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* Test parsing an RDFa Lite HTML file |
53
|
|
|
*/ |
54
|
|
|
public function testRdfaLiteHtmlFile() |
55
|
|
|
{ |
56
|
|
|
$things = Html::parseFile( |
57
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'article-rdfa-lite.html' |
58
|
|
|
); |
59
|
|
|
$this->assertArrayEquals( |
60
|
|
|
$this->castArray( |
61
|
|
|
json_decode( |
62
|
|
|
file_get_contents( |
63
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'article-rdfa-lite.json' |
64
|
|
|
) |
65
|
|
|
) |
66
|
|
|
), |
67
|
|
|
$this->castArray($things) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test an invalid file |
73
|
|
|
* |
74
|
|
|
* @expectedException \Jkphl\RdfaLiteMicrodata\Ports\Exceptions\RuntimeException |
75
|
|
|
* @expectedExceptionCode 1487190674 |
76
|
|
|
*/ |
77
|
|
|
public function testInvalidFile() |
78
|
|
|
{ |
79
|
|
|
Html::parseFile('invalid'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Test an XML runtime exception |
84
|
|
|
* |
85
|
|
|
* @expectedException \Jkphl\RdfaLiteMicrodata\Ports\Exceptions\RuntimeException |
86
|
|
|
*/ |
87
|
|
|
public function testHTMLRuntimeException() |
88
|
|
|
{ |
89
|
|
|
Html::parseFile( |
90
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'empty-default-vocab-rdfa-lite.html' |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Test an HTML out of bounds exception |
96
|
|
|
* |
97
|
|
|
* @expectedException \Jkphl\RdfaLiteMicrodata\Ports\Exceptions\OutOfBoundsException |
98
|
|
|
*/ |
99
|
|
|
public function testHTMLOutOfBoundsException() |
100
|
|
|
{ |
101
|
|
|
Html::parseFile( |
102
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'unknown-vocab-prefix-rdfa-lite.html' |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Test parsing an RDFa Lite XML (XHTML) file |
108
|
|
|
*/ |
109
|
|
|
public function testRdfaLiteXmlFile() |
110
|
|
|
{ |
111
|
|
|
$things = Xml::parseFile( |
112
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'typed-property-rdfa-lite.xhtml' |
113
|
|
|
); |
114
|
|
|
$this->assertArrayEquals( |
115
|
|
|
$this->castArray( |
116
|
|
|
json_decode( |
117
|
|
|
file_get_contents( |
118
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures' |
119
|
|
|
.DIRECTORY_SEPARATOR.'typed-property-rdfa-lite.json' |
120
|
|
|
) |
121
|
|
|
) |
122
|
|
|
), |
123
|
|
|
$this->castArray($things) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Test an XML runtime exception |
130
|
|
|
* |
131
|
|
|
* @expectedException \Jkphl\RdfaLiteMicrodata\Ports\Exceptions\RuntimeException |
132
|
|
|
*/ |
133
|
|
|
public function testXMLRuntimeException() |
134
|
|
|
{ |
135
|
|
|
Xml::parseFile( |
136
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'empty-default-vocab-rdfa-lite.html' |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Test an XML out of bounds exception |
142
|
|
|
* |
143
|
|
|
* @expectedException \Jkphl\RdfaLiteMicrodata\Ports\Exceptions\OutOfBoundsException |
144
|
|
|
*/ |
145
|
|
|
public function testXMLOutOfBoundsException() |
146
|
|
|
{ |
147
|
|
|
Xml::parseFile( |
148
|
|
|
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'unknown-vocab-prefix-rdfa-lite.html' |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|