|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PPP\Wikidata\ValueParsers; |
|
4
|
|
|
|
|
5
|
|
|
use DataValues\GlobeCoordinateValue; |
|
6
|
|
|
use DataValues\LatLongValue; |
|
7
|
|
|
use DataValues\MonolingualTextValue; |
|
8
|
|
|
use DataValues\StringValue; |
|
9
|
|
|
use Mediawiki\Api\MediawikiApi; |
|
10
|
|
|
use Wikibase\DataModel\Entity\EntityIdValue; |
|
11
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
12
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
|
13
|
|
|
use Wikibase\EntityStore\Api\ApiEntityStore; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @covers PPP\Wikidata\ValueParsers\WikibaseValueParserFactory |
|
17
|
|
|
* |
|
18
|
|
|
* @licence GPLv2+ |
|
19
|
|
|
* @author Thomas Pellissier Tanon |
|
20
|
|
|
* |
|
21
|
|
|
* @todo mock instead of requests to the real API? |
|
22
|
|
|
*/ |
|
23
|
|
|
class WikibaseValueParserFactoryTest extends \PHPUnit_Framework_TestCase { |
|
24
|
|
|
|
|
25
|
|
|
private function newFactory() { |
|
26
|
|
|
return new WikibaseValueParserFactory( |
|
27
|
|
|
'fr', |
|
28
|
|
|
new ApiEntityStore(new MediawikiApi('http://www.wikidata.org/w/api.php')) |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testParserParseCommonsMedia() { |
|
33
|
|
|
$this->assertEquals( |
|
34
|
|
|
array(new StringValue('Foo.jpg')), |
|
35
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('Foo.jpg', 'commonsMedia') |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testParserParseExternalId() { |
|
40
|
|
|
$this->assertEquals( |
|
41
|
|
|
array(new StringValue('foo')), |
|
42
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('foo', 'external-id') |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testParserParseGlobeCoordinate() { |
|
47
|
|
|
$this->assertEquals( |
|
48
|
|
|
array(new GlobeCoordinateValue(new LatLongValue(42, 42), 1)), |
|
49
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('42°N, 42°E', 'globe-coordinate') |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testParserParseMonolingualText() { |
|
54
|
|
|
$this->assertEquals( |
|
55
|
|
|
array(new MonolingualTextValue('en', 'Foo')), |
|
56
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('Foo', 'monolingualtext') |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testParserParseString() { |
|
61
|
|
|
$this->assertEquals( |
|
62
|
|
|
array(new StringValue('foo')), |
|
63
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('foo', 'string') |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testParserParseUrl() { |
|
68
|
|
|
$this->assertEquals( |
|
69
|
|
|
array(new StringValue('http://exemple.org')), |
|
70
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('http://exemple.org', 'url') |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testParserParseWikibaseItem() { |
|
75
|
|
|
$this->assertEquals( |
|
76
|
|
|
array(new EntityIdValue(new ItemId('Q76'))), |
|
77
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('Barack Obama', 'wikibase-item') |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testParserParseWikibaseProperty() { |
|
82
|
|
|
$this->assertEquals( |
|
83
|
|
|
array(new EntityIdValue(new PropertyId('P569'))), |
|
84
|
|
|
$this->newFactory()->newWikibaseValueParser()->parse('Date de naissance', 'wikibase-property') |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|