annotatedNodeProvider()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
namespace PPP\Wikidata\ValueParsers;
4
5
use DataValues\StringValue;
6
use Mediawiki\Api\MediawikiApi;
7
use PPP\DataModel\ResourceListNode;
8
use PPP\DataModel\StringResourceNode;
9
use PPP\Wikidata\WikibaseResourceNode;
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\ResourceListNodeParser
17
 *
18
 * @licence AGPLv3+
19
 * @author Thomas Pellissier Tanon
20
 *
21
 * @todo mock instead of requests to the real API?
22
 */
23
class ResourceListNodeParserTest extends \PHPUnit_Framework_TestCase {
24
25
	/**
26
	 * @dataProvider annotatedNodeProvider
27
	 */
28
	public function testParse(ResourceListNode $inputNode, $type, ResourceListNode $expectedNode) {
29
		$valueParserFactory = new WikibaseValueParserFactory(
30
			'en',
31
			new ApiEntityStore(new MediawikiApi('http://www.wikidata.org/w/api.php'))
32
		);
33
		$resourceListNodeParser = new ResourceListNodeParser($valueParserFactory->newWikibaseValueParser());
34
35
		$this->assertEquals($expectedNode, $resourceListNodeParser->parse($inputNode, $type));
36
	}
37
38
	public function annotatedNodeProvider() {
39
		return array(
40
			array(
41
				new ResourceListNode(array(new StringResourceNode('Ramesses III'))),
42
				'wikibase-item',
43
				new ResourceListNode(array(new WikibaseResourceNode('Ramesses III', new EntityIdValue(new ItemId('Q1528')))))
44
			),
45
			array(
46
				new ResourceListNode(array(new WikibaseResourceNode('Ramesses III', new EntityIdValue(new ItemId('Q1528'))))),
47
				'wikibase-item',
48
				new ResourceListNode(array(new WikibaseResourceNode('Ramesses III', new EntityIdValue(new ItemId('Q1528')))))
49
			),
50
			array(
51
				new ResourceListNode(array(new StringResourceNode('P=NP'))),
52
				'wikibase-item',
53
				new ResourceListNode(array(new WikibaseResourceNode('P=NP', new EntityIdValue(new ItemId('Q746242')))))
54
			),
55
			array(
56
				new ResourceListNode(array(new StringResourceNode('Place of birth'))),
57
				'wikibase-property',
58
				new ResourceListNode(array(new WikibaseResourceNode('Place of birth', new EntityIdValue(new PropertyId('P19')))))
59
			),
60
			array(
61
				new ResourceListNode(array(new StringResourceNode('foo'))),
62
				'string',
63
				new ResourceListNode(array(new WikibaseResourceNode('foo', new StringValue('foo'))))
64
			),
65
		);
66
	}
67
}
68