|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PPP\Wikidata\ValueFormatters; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
|
6
|
|
|
use Mediawiki\Api\MediawikiApi; |
|
7
|
|
|
use PPP\Wikidata\Cache\PerSiteLinkCache; |
|
8
|
|
|
use PPP\Wikidata\ValueFormatters\JsonLd\Entity\JsonLdEntityFormatter; |
|
9
|
|
|
use PPP\Wikidata\ValueFormatters\JsonLd\Entity\JsonLdItemFormatter; |
|
10
|
|
|
use PPP\Wikidata\ValueFormatters\JsonLd\JsonLdFormatterTestBase; |
|
11
|
|
|
use PPP\Wikidata\Wikipedia\MediawikiArticle; |
|
12
|
|
|
use PPP\Wikidata\Wikipedia\MediawikiArticleImage; |
|
13
|
|
|
use PPP\Wikidata\Wikipedia\MediawikiArticleProvider; |
|
14
|
|
|
use ValueFormatters\FormatterOptions; |
|
15
|
|
|
use ValueFormatters\ValueFormatter; |
|
16
|
|
|
use Wikibase\DataModel\Entity\Item; |
|
17
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
18
|
|
|
use Wikibase\DataModel\SiteLink; |
|
19
|
|
|
use Wikibase\DataModel\SiteLinkList; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @covers PPP\Wikidata\ValueFormatters\ExtendedJsonLdItemFormatter |
|
23
|
|
|
* |
|
24
|
|
|
* @licence AGPLv3+ |
|
25
|
|
|
* @author Thomas Pellissier Tanon |
|
26
|
|
|
*/ |
|
27
|
|
|
class ExtendedJsonLdItemFormatterTest extends JsonLdFormatterTestBase { |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @see JsonLdFormatterTestBase::validProvider |
|
31
|
|
|
*/ |
|
32
|
|
|
public function validProvider() { |
|
33
|
|
|
$item = new Item( |
|
34
|
|
|
new ItemId('Q42'), |
|
35
|
|
|
null, |
|
36
|
|
|
new SiteLinkList(array(new SiteLink('enwiki', 'Douglas Adams'))) |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
return array( |
|
40
|
|
|
array( |
|
41
|
|
|
$item, |
|
42
|
|
|
(object) array( |
|
43
|
|
|
'@type' => 'Thing', |
|
44
|
|
|
'@id' => 'http://www.wikidata.org/entity/Q42', |
|
45
|
|
|
'name' => 'Q42', |
|
46
|
|
|
'potentialAction' => array( |
|
47
|
|
|
(object) array( |
|
48
|
|
|
'@type' => 'ViewAction', |
|
49
|
|
|
'name' => array( |
|
50
|
|
|
(object) array('@value' => 'View on Wikidata', '@language' => 'en'), |
|
51
|
|
|
(object) array('@value' => 'Voir sur Wikidata', '@language' => 'fr') |
|
52
|
|
|
), |
|
53
|
|
|
'image' => '//upload.wikimedia.org/wikipedia/commons/f/ff/Wikidata-logo.svg', |
|
54
|
|
|
'target' => '//www.wikidata.org/entity/Q42' |
|
55
|
|
|
), |
|
56
|
|
|
(object) array( |
|
57
|
|
|
'@type' => 'ViewAction', |
|
58
|
|
|
'name' => array( |
|
59
|
|
|
(object) array('@value' => 'View on Wikipedia', '@language' => 'en'), |
|
60
|
|
|
(object) array('@value' => 'Voir sur Wikipédia', '@language' => 'fr') |
|
61
|
|
|
), |
|
62
|
|
|
'image' => '//upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/64px-Wikipedia-logo-v2.svg.png', |
|
63
|
|
|
'target' => 'http://en.wikipedia.org/wiki/Douglas_Adams' |
|
64
|
|
|
) |
|
65
|
|
|
), |
|
66
|
|
|
'image' => (object) array( |
|
67
|
|
|
'@type' => 'ImageObject', |
|
68
|
|
|
'@id' => 'http://commons.wikimedia.org/wiki/Image:Douglas_adams_portrait_cropped.jpg', |
|
69
|
|
|
'contentUrl' => '//upload.wikimedia.org/wikipedia/commons/c/c0/Douglas_adams_portrait_cropped.jpg', |
|
70
|
|
|
'name' => 'Douglas adams portrait cropped.jpg', |
|
71
|
|
|
'width' => 100, |
|
72
|
|
|
'height' => 200 |
|
73
|
|
|
), |
|
74
|
|
|
'@reverse' => (object) array( |
|
75
|
|
|
'about'=> (object) array( |
|
76
|
|
|
'@type' => 'Article', |
|
77
|
|
|
'@id'=> 'http://en.wikipedia.org/wiki/Douglas_Adams', |
|
78
|
|
|
'inLanguage'=> 'en', |
|
79
|
|
|
'headline'=> 'Fooo barr baz gaaaaaaa...', |
|
80
|
|
|
'author'=> (object) array( |
|
81
|
|
|
'@type'=> 'Organization', |
|
82
|
|
|
'@id' => 'http://www.wikidata.org/entity/Q52', |
|
83
|
|
|
'name' => 'Wikipedia' |
|
84
|
|
|
), |
|
85
|
|
|
'license'=> 'http://creativecommons.org/licenses/by-sa/3.0/' |
|
86
|
|
|
) |
|
87
|
|
|
) |
|
88
|
|
|
), |
|
89
|
|
|
new FormatterOptions(array( |
|
90
|
|
|
JsonLdEntityFormatter::OPT_ENTITY_BASE_URI => 'http://www.wikidata.org/entity/', |
|
91
|
|
|
ValueFormatter::OPT_LANG => 'en' |
|
92
|
|
|
)) |
|
93
|
|
|
), |
|
94
|
|
|
array( |
|
95
|
|
|
$item, |
|
96
|
|
|
(object) array( |
|
97
|
|
|
'@type' => 'Thing', |
|
98
|
|
|
'@id' => 'http://www.wikidata.org/entity/Q42', |
|
99
|
|
|
'name' => 'Q42', |
|
100
|
|
|
'potentialAction' => array( |
|
101
|
|
|
(object) array( |
|
102
|
|
|
'@type' => 'ViewAction', |
|
103
|
|
|
'name' => array( |
|
104
|
|
|
(object) array('@value' => 'View on Wikidata', '@language' => 'en'), |
|
105
|
|
|
(object) array('@value' => 'Voir sur Wikidata', '@language' => 'fr') |
|
106
|
|
|
), |
|
107
|
|
|
'image' => '//upload.wikimedia.org/wikipedia/commons/f/ff/Wikidata-logo.svg', |
|
108
|
|
|
'target' => '//www.wikidata.org/entity/Q42' |
|
109
|
|
|
) |
|
110
|
|
|
) |
|
111
|
|
|
), |
|
112
|
|
|
new FormatterOptions(array( |
|
113
|
|
|
JsonLdEntityFormatter::OPT_ENTITY_BASE_URI => 'http://www.wikidata.org/entity/', |
|
114
|
|
|
ValueFormatter::OPT_LANG => 'ru' |
|
115
|
|
|
)) |
|
116
|
|
|
) |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @see JsonLdFormatterTestBase::getInstance |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function getInstance(FormatterOptions $options = null) { |
|
124
|
|
|
$articleHeaderCache = new PerSiteLinkCache(new ArrayCache(), 'wphead'); |
|
125
|
|
|
$articleHeaderCache->save(new MediawikiArticle( |
|
126
|
|
|
new SiteLink('enwiki', 'Douglas Adams'), |
|
127
|
|
|
'Fooo barr baz gaaaaaaa...', |
|
128
|
|
|
'en', |
|
129
|
|
|
'http://en.wikipedia.org/wiki/Douglas_Adams', |
|
130
|
|
|
new MediawikiArticleImage( |
|
131
|
|
|
'//upload.wikimedia.org/wikipedia/commons/c/c0/Douglas_adams_portrait_cropped.jpg', |
|
132
|
|
|
100, |
|
133
|
|
|
200, |
|
134
|
|
|
'Douglas adams portrait cropped.jpg' |
|
135
|
|
|
) |
|
136
|
|
|
)); |
|
137
|
|
|
|
|
138
|
|
|
return new ExtendedJsonLdItemFormatter( |
|
139
|
|
|
new JsonLdItemFormatter(new JsonLdEntityFormatter($options), $options), |
|
|
|
|
|
|
140
|
|
|
new MediawikiArticleProvider( |
|
141
|
|
|
array( |
|
142
|
|
|
'enwiki' => new MediawikiApi('http://example.org') |
|
143
|
|
|
), |
|
144
|
|
|
$articleHeaderCache |
|
145
|
|
|
), |
|
146
|
|
|
$options |
|
|
|
|
|
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):