|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PPP\DataModel; |
|
4
|
|
|
|
|
5
|
|
|
use stdClass; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @covers PPP\DataModel\JsonLdResourceNode |
|
9
|
|
|
* |
|
10
|
|
|
* @licence AGPLv3+ |
|
11
|
|
|
* @author Thomas Pellissier Tanon |
|
12
|
|
|
*/ |
|
13
|
|
|
class JsonLdResourceNodeTest extends \PHPUnit_Framework_TestCase { |
|
14
|
|
|
|
|
15
|
|
|
public function testGetValue() { |
|
16
|
|
|
$node = new JsonLdResourceNode('Douglas Adams', (object) array('http://schema.org/name' => 'Douglas Adams')); |
|
17
|
|
|
$this->assertEquals('Douglas Adams', $node->getValue()); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testGetGraph() { |
|
21
|
|
|
$node = new JsonLdResourceNode( |
|
22
|
|
|
'Douglas Adams', |
|
23
|
|
|
(object) array('http://schema.org/name' => (object) array('@value' => 'Douglas Adams')) |
|
24
|
|
|
); |
|
25
|
|
|
$this->assertEquals(((object) array('@context' => 'http://schema.org', 'name' => 'Douglas Adams')), $node->getGraph()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testGetValueType() { |
|
29
|
|
|
$node = new JsonLdResourceNode('Douglas Adams', new stdClass()); |
|
30
|
|
|
$this->assertEquals('resource-jsonld', $node->getValueType()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testGetType() { |
|
34
|
|
|
$node = new JsonLdResourceNode('Douglas Adams', new stdClass()); |
|
35
|
|
|
$this->assertEquals('resource', $node->getType()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @dataProvider equalsProvider |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testEquals(ResourceNode $node, $target) { |
|
42
|
|
|
$this->assertTrue($node->equals($target)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function equalsProvider() { |
|
46
|
|
|
return array( |
|
47
|
|
|
array( |
|
48
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', '@id' => 'foo', 'name' => 'baz')), |
|
49
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', '@id' => 'foo', 'name' => 'bar')) |
|
50
|
|
|
), |
|
51
|
|
|
array( |
|
52
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'sameAs' => 'foo')), |
|
53
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'sameAs' => array('foo', 'bar'))) |
|
54
|
|
|
), |
|
55
|
|
|
array( |
|
56
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', '@id' => 'foo', 'name' => 'bar')), |
|
57
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'sameAs' => array('foo', 'bar'))) |
|
58
|
|
|
), |
|
59
|
|
|
array( |
|
60
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'sameAs' => array('foo', 'bar'))), |
|
61
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', '@id' => 'foo', 'name' => 'bar')) |
|
62
|
|
|
), |
|
63
|
|
|
array( |
|
64
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'name' => 'bar')), |
|
65
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'name' => 'bar')) |
|
66
|
|
|
), |
|
67
|
|
|
array( |
|
68
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'parent' => (object) array('@id' => 'foo', 'name' => 'foo'))), |
|
69
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'parent' => (object) array('@id' => 'foo'))) |
|
70
|
|
|
) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @dataProvider nonEqualsProvider |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testNonEquals(ResourceNode $node, $target) { |
|
78
|
|
|
$this->assertFalse($node->equals($target)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function nonEqualsProvider() { |
|
82
|
|
|
return array( |
|
83
|
|
|
array( |
|
84
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('http://schema.org/name' => 'Douglas Adams')), |
|
85
|
|
|
new MissingNode() |
|
86
|
|
|
), |
|
87
|
|
|
array( |
|
88
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', '@id' => 'foo', 'name' => 'bar')), |
|
89
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', '@id' => 'bar', 'name' => 'bar')) |
|
90
|
|
|
), |
|
91
|
|
|
array( |
|
92
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org', 'name' => 'bar')), |
|
93
|
|
|
new JsonLdResourceNode('Douglas Adams', (object) array('@context' => 'http://schema.org')) |
|
94
|
|
|
) |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|