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