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