1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class DummyModel extends BOTK\Model\AbstractModel |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public function asTurtle() { return '<urn:a:b> owl:sameAs <urn:a:b> .';} |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
class AbstractModelTest extends PHPUnit_Framework_TestCase |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
protected $vocabulary = array( |
11
|
|
|
'botk' => 'http://http://linkeddata.center/botk/v1#', |
12
|
|
|
'schema' => 'http://schema.org/', |
13
|
|
|
'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
14
|
|
|
'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
15
|
|
|
'dct' => 'http://purl.org/dc/terms/', |
16
|
|
|
'foaf' => 'http://xmlns.com/foaf/0.1/', |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
public function testGetVocabulary() |
21
|
|
|
{ |
22
|
|
|
$vocabulary = array( |
|
|
|
|
23
|
|
|
'botk' => 'http://http://linkeddata.center/botk/v1#', |
24
|
|
|
'schema' => 'http://schema.org/', |
25
|
|
|
'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
26
|
|
|
'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
27
|
|
|
'dct' => 'http://purl.org/dc/terms/', |
28
|
|
|
'foaf' => 'http://xmlns.com/foaf/0.1/', |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
$obj = new DummyModel(array()); |
32
|
|
|
|
33
|
|
|
$this->assertEquals($this->vocabulary, $obj->getVocabulary()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
View Code Duplication |
public function testSetVocabulary() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$vocabulary = $this->vocabulary; |
40
|
|
|
$vocabulary['my'] = 'urn:test:'; |
41
|
|
|
|
42
|
|
|
$obj = new DummyModel(array()); |
43
|
|
|
$obj->setVocabulary('my','urn:test:'); |
44
|
|
|
|
45
|
|
|
$this->assertEquals($vocabulary, $obj->getVocabulary()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
View Code Duplication |
public function testUnsetVocabulary() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$vocabulary = $this->vocabulary; |
52
|
|
|
unset($vocabulary['foaf']); |
53
|
|
|
|
54
|
|
|
$obj = new DummyModel(array()); |
55
|
|
|
$obj->unsetVocabulary('foaf'); |
56
|
|
|
|
57
|
|
|
$this->assertEquals($vocabulary, $obj->getVocabulary()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @dataProvider uris |
63
|
|
|
*/ |
64
|
|
|
public function testGetUri($data, $expectedData) |
65
|
|
|
{ |
66
|
|
|
$obj = new DummyModel($data); |
67
|
|
|
$obj->setIdGenerator(function($d){return'abc';}); |
|
|
|
|
68
|
|
|
$this->assertEquals($expectedData, $obj->getUri()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function uris() |
73
|
|
|
{ |
74
|
|
|
return array( |
75
|
|
|
array( array(), 'http://linkeddata.center/botk/resource/abc'), |
76
|
|
|
array( array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
77
|
|
|
array( array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
78
|
|
|
array( array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function testTurtleHeader() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$obj = new DummyModel(array()); |
85
|
|
|
$s =""; |
86
|
|
|
foreach( $this->vocabulary as $p=>$v){ |
87
|
|
|
$s.= "@prefix $p: <$v> .\n"; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->assertEquals($s, $obj->getTurtleHeader()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
View Code Duplication |
public function testTurtleHeaderWithBase() |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$obj = new DummyModel(array()); |
97
|
|
|
$s ="@base <urn:a:b> .\n"; |
98
|
|
|
foreach( $this->vocabulary as $p=>$v){ |
99
|
|
|
$s.= "@prefix $p: <$v> .\n"; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
public function testasString() |
108
|
|
|
{ |
109
|
|
|
$obj = new DummyModel(array()); |
110
|
|
|
$s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
111
|
|
|
|
112
|
|
|
$this->assertEquals($s, (string)$obj); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.