|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PPP\Wikidata\ValueFormatters\JsonLd\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use PPP\Wikidata\ValueFormatters\JsonLd\JsonLdFormatterTestBase; |
|
6
|
|
|
use ValueFormatters\FormatterOptions; |
|
7
|
|
|
use ValueFormatters\ValueFormatter; |
|
8
|
|
|
use Wikibase\DataModel\Entity\EntityIdValue; |
|
9
|
|
|
use Wikibase\DataModel\Entity\Item; |
|
10
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
11
|
|
|
use Wikibase\DataModel\Entity\Property; |
|
12
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
|
13
|
|
|
use Wikibase\DataModel\Services\Lookup\ItemLookup; |
|
14
|
|
|
use Wikibase\DataModel\Services\Lookup\PropertyLookup; |
|
15
|
|
|
use Wikibase\DataModel\Term\Fingerprint; |
|
16
|
|
|
use Wikibase\DataModel\Term\Term; |
|
17
|
|
|
use Wikibase\DataModel\Term\TermList; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @covers PPP\Wikidata\ValueFormatters\JsonLd\Entity\JsonLdEntityIdFormatter |
|
21
|
|
|
* |
|
22
|
|
|
* @licence AGPLv3+ |
|
23
|
|
|
* @author Thomas Pellissier Tanon |
|
24
|
|
|
*/ |
|
25
|
|
|
class JsonLdEntityIdFormatterTest extends JsonLdFormatterTestBase { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @see JsonLdFormatterTestBase::validProvider |
|
29
|
|
|
*/ |
|
30
|
|
|
public function validProvider() { |
|
31
|
|
|
$withItemLookupMock = $this->getMock('Wikibase\DataModel\Services\Lookup\ItemLookup'); |
|
32
|
|
|
$withItemLookupMock->expects($this->once()) |
|
33
|
|
|
->method('getItemForId') |
|
34
|
|
|
->with($this->equalTo(new ItemId('Q42'))) |
|
35
|
|
|
->willReturn(new Item( |
|
36
|
|
|
new ItemId('Q42'), |
|
37
|
|
|
new Fingerprint(new TermList(array(new Term('en', 'Douglas Adams')))) |
|
38
|
|
|
)); |
|
39
|
|
|
$withoutItemLookupMock = $this->getMock('Wikibase\DataModel\Services\Lookup\ItemLookup'); |
|
40
|
|
|
$withoutItemLookupMock->expects($this->once()) |
|
41
|
|
|
->method('getItemForId') |
|
42
|
|
|
->with($this->equalTo(new ItemId('Q42'))) |
|
43
|
|
|
->willReturn(null); |
|
44
|
|
|
|
|
45
|
|
|
$withPropertyLookupMock = $this->getMock('Wikibase\DataModel\Services\Lookup\PropertyLookup'); |
|
46
|
|
|
$withPropertyLookupMock->expects($this->once()) |
|
47
|
|
|
->method('getPropertyForId') |
|
48
|
|
|
->with($this->equalTo(new PropertyId('P214'))) |
|
49
|
|
|
->willReturn(new Property( |
|
50
|
|
|
new PropertyId('P214'), |
|
51
|
|
|
new Fingerprint(new TermList(array(new Term('en', 'VIAF')))), |
|
52
|
|
|
'string' |
|
53
|
|
|
)); |
|
54
|
|
|
$withoutPropertyLookupMock = $this->getMock('Wikibase\DataModel\Services\Lookup\PropertyLookup'); |
|
55
|
|
|
$withoutPropertyLookupMock->expects($this->once()) |
|
56
|
|
|
->method('getPropertyForId') |
|
57
|
|
|
->with($this->equalTo(new PropertyId('P214'))) |
|
58
|
|
|
->willReturn(null); |
|
59
|
|
|
|
|
60
|
|
|
return array( |
|
61
|
|
|
array( |
|
62
|
|
|
new EntityIdValue(new ItemId('Q42')), |
|
63
|
|
|
(object) array( |
|
64
|
|
|
'@type' => 'Thing', |
|
65
|
|
|
'@id' => 'http://www.wikidata.org/entity/Q42', |
|
66
|
|
|
'name' => (object) array('@value' => 'Douglas Adams', '@language' => 'en') |
|
67
|
|
|
), |
|
68
|
|
|
null, |
|
69
|
|
|
$this->getFormatter( |
|
70
|
|
|
$withItemLookupMock, |
|
71
|
|
|
$this->getMock('Wikibase\DataModel\Services\Lookup\PropertyLookup') |
|
72
|
|
|
) |
|
73
|
|
|
), |
|
74
|
|
|
array( |
|
75
|
|
|
new EntityIdValue(new ItemId('Q42')), |
|
76
|
|
|
(object) array( |
|
77
|
|
|
'@type' => 'Thing', |
|
78
|
|
|
'@id' => 'http://www.wikidata.org/entity/Q42', |
|
79
|
|
|
'name' => 'Q42' |
|
80
|
|
|
), |
|
81
|
|
|
null, |
|
82
|
|
|
$this->getFormatter( |
|
83
|
|
|
$withoutItemLookupMock, |
|
84
|
|
|
$this->getMock('Wikibase\DataModel\Services\Lookup\PropertyLookup') |
|
85
|
|
|
) |
|
86
|
|
|
), |
|
87
|
|
|
array( |
|
88
|
|
|
new EntityIdValue(new PropertyId('P214')), |
|
89
|
|
|
(object) array( |
|
90
|
|
|
'@type' => 'Property', |
|
91
|
|
|
'@id' => 'http://www.wikidata.org/entity/P214', |
|
92
|
|
|
'name' => (object) array('@value' => 'VIAF', '@language' => 'en') |
|
93
|
|
|
), |
|
94
|
|
|
null, |
|
95
|
|
|
$this->getFormatter( |
|
96
|
|
|
$this->getMock('Wikibase\DataModel\Services\Lookup\ItemLookup'), |
|
97
|
|
|
$withPropertyLookupMock |
|
98
|
|
|
) |
|
99
|
|
|
), |
|
100
|
|
|
array( |
|
101
|
|
|
new EntityIdValue(new PropertyId('P214')), |
|
102
|
|
|
(object) array( |
|
103
|
|
|
'@type' => 'Property', |
|
104
|
|
|
'@id' => 'http://www.wikidata.org/entity/P214', |
|
105
|
|
|
'name' => 'P214' |
|
106
|
|
|
), |
|
107
|
|
|
null, |
|
108
|
|
|
$this->getFormatter( |
|
109
|
|
|
$this->getMock('Wikibase\DataModel\Services\Lookup\ItemLookup'), |
|
110
|
|
|
$withoutPropertyLookupMock |
|
111
|
|
|
) |
|
112
|
|
|
) |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @see JsonLdFormatterTestBase::getInstance |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function getInstance(FormatterOptions $options = null) { |
|
120
|
|
|
return null; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
private function getFormatter(ItemLookup $itemLookup, PropertyLookup $propertyLookup) { |
|
124
|
|
|
$options = new FormatterOptions(array( |
|
125
|
|
|
ValueFormatter::OPT_LANG => 'en', |
|
126
|
|
|
JsonLdEntityFormatter::OPT_ENTITY_BASE_URI => 'http://www.wikidata.org/entity/' |
|
127
|
|
|
)); |
|
128
|
|
|
|
|
129
|
|
|
return new JsonLdEntityIdFormatter( |
|
130
|
|
|
$itemLookup, |
|
131
|
|
|
new JsonLdItemFormatter(new JsonLdEntityFormatter($options), $options), |
|
132
|
|
|
$propertyLookup, |
|
133
|
|
|
new JsonLdPropertyFormatter(new JsonLdEntityFormatter($options), $options), |
|
134
|
|
|
$options |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|