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\Domain\Property\Property; |
40
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Property\PropertyInterface; |
41
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Property\PropertyListInterface; |
42
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Thing\ThingInterface; |
43
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Type\Type; |
44
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Vocabulary\Vocabulary; |
45
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Vocabulary\VocabularyInterface; |
46
|
|
|
use Jkphl\RdfaLiteMicrodata\Tests\AbstractTest; |
47
|
|
|
use Jkphl\RdfaLiteMicrodata\Tests\Domain\VocabularyTest; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Base class for parser & iterator tests |
51
|
|
|
* |
52
|
|
|
* @package Jkphl\RdfaLiteMicrodata |
53
|
|
|
* @subpackage Jkphl\RdfaLiteMicrodata\Tests |
54
|
|
|
*/ |
55
|
|
|
abstract class ParserIteratorTestBase extends AbstractTest |
56
|
|
|
{ |
57
|
|
|
/** |
58
|
|
|
* Test HTML with person RDFa Lite 1.1 |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected static $personRdfa; |
63
|
|
|
/** |
64
|
|
|
* Fixture directory |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
protected static $fixtures; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Setup all tests |
72
|
|
|
*/ |
73
|
|
|
public static function setUpBeforeClass() |
74
|
|
|
{ |
75
|
|
|
self::$fixtures = dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR; |
76
|
|
|
self::$personRdfa = file_get_contents(self::$fixtures.'person-rdfa-lite.html'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Validate parsing results |
81
|
|
|
* |
82
|
|
|
* @param ThingInterface[] $things Parsing Results |
83
|
|
|
*/ |
84
|
|
|
protected function validatePersonResult(array $things) |
85
|
|
|
{ |
86
|
|
|
$schemaOrgVocabulary = new Vocabulary(VocabularyTest::SCHEMA_ORG_URI); |
87
|
|
|
$foafVocabulary = new Vocabulary('http://xmlns.com/foaf/0.1/'); |
88
|
|
|
|
89
|
|
|
$this->assertTrue(is_array($things)); |
90
|
|
|
$this->assertEquals(1, count($things)); |
91
|
|
|
$thing = $things[0]; |
92
|
|
|
$type = new Type('Person', $schemaOrgVocabulary); |
93
|
|
|
$foafType = new Type('Person', $foafVocabulary); |
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf(ThingInterface::class, $thing); |
96
|
|
|
$this->assertEquals([$type, $foafType], $thing->getTypes()); |
97
|
|
|
$this->assertEquals('#joschi', $thing->getResourceId()); |
98
|
|
|
|
99
|
|
|
$this->validateProperties($thing, $schemaOrgVocabulary); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Validate properties |
104
|
|
|
* |
105
|
|
|
* @param ThingInterface $thing Thing |
106
|
|
|
* @param VocabularyInterface $schemaOrgVocabulary schema.org vocabulary |
107
|
|
|
*/ |
108
|
|
|
protected function validateProperties(ThingInterface $thing, VocabularyInterface $schemaOrgVocabulary) |
109
|
|
|
{ |
110
|
|
|
$properties = $thing->getProperties(); |
111
|
|
|
$this->assertInstanceOf(PropertyListInterface::class, $properties); |
112
|
|
|
$this->assertEquals(4, count($properties)); |
113
|
|
|
|
114
|
|
|
$this->validateProperty($thing, 'name', $schemaOrgVocabulary, 'Joschi Kuphal'); |
115
|
|
|
$this->validateProperty($thing, 'telephone', $schemaOrgVocabulary, '+49 911 9593945'); |
116
|
|
|
$this->validateProperty($thing, 'image', $schemaOrgVocabulary, 'https://jkphl.is/avatar.jpg'); |
117
|
|
|
$this->validateProperty($thing, 'preferredAnimal', new Vocabulary('http://open.vocab.org/terms/'), 'Unicorn'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Validate a single property |
122
|
|
|
* |
123
|
|
|
* @param ThingInterface $thing Thing |
124
|
|
|
* @param string $name Property name |
125
|
|
|
* @param VocabularyInterface $vocabulary Property vocabulary |
126
|
|
|
* @param string $value Property value |
127
|
|
|
*/ |
128
|
|
|
protected function validateProperty(ThingInterface $thing, $name, VocabularyInterface $vocabulary, $value) |
129
|
|
|
{ |
130
|
|
|
$property = $thing->getProperty($name, $vocabulary); |
131
|
|
|
$this->assertTrue(is_array($property)); |
132
|
|
|
$this->assertEquals(1, count($property)); |
133
|
|
|
$this->assertInstanceOf(PropertyInterface::class, $property[0]); |
134
|
|
|
$this->assertEquals(new Property($name, $vocabulary, $value), $property[0]); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|