WikibaseEntityIdParserTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 8
dl 0
loc 99
rs 10
c 6
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A requireDataValue() 0 3 1
A validInputProvider() 0 53 1
A invalidInputProvider() 0 7 1
A getInstance() 0 6 1
A newParserOptions() 0 8 1
1
<?php
2
3
namespace PPP\Wikidata\ValueParsers;
4
5
use Mediawiki\Api\MediawikiApi;
6
use ValueParsers\ParserOptions;
7
use ValueParsers\Test\ValueParserTestBase;
8
use ValueParsers\ValueParser;
9
use Wikibase\DataModel\Entity\EntityIdValue;
10
use Wikibase\DataModel\Entity\ItemId;
11
use Wikibase\DataModel\Entity\PropertyId;
12
use Wikibase\EntityStore\Api\ApiEntityStore;
13
14
/**
15
 * @covers PPP\Wikidata\ValueParsers\WikibaseEntityIdParser
16
 *
17
 * @licence AGPLv3+
18
 * @author Thomas Pellissier Tanon
19
 *
20
 * @todo mock instead of requests to the real API?
21
 */
22
class WikibaseEntityIdParserTest extends ValueParserTestBase {
23
24
	/**
25
	 * @see ValueParserTestBase::validInputProvider
26
	 */
27
	public function validInputProvider() {
28
		return array(
29
			array(
30
				'Douglas Adams',
31
				array(
32
					new EntityIdValue(new ItemId('Q42')),
33
					new EntityIdValue(new ItemId('Q21454969')),
34
					new EntityIdValue(new ItemId('Q25212461'))
35
				)
36
			),
37
			array(
38
				'Barack Obama',
39
				array(new EntityIdValue(new ItemId('Q76')))
40
			),
41
			array(
42
				'P=NP',
43
				array(new EntityIdValue(new ItemId('Q746242')))
44
			),
45
			array(
46
				'TUNGSTÈNE',
47
				array(
48
					new EntityIdValue(new ItemId('Q743')),
49
					new EntityIdValue(new ItemId('Q3542087'))
50
				)
51
			),
52
			array(
53
				'Barack Obama',
54
				array(new EntityIdValue(new ItemId('Q76')))
55
			),
56
			array(
57
				'',
58
				array()
59
			),
60
			array(
61
				'abcabcabc',
62
				array()
63
			),
64
			array(
65
				'q42',
66
				array(new EntityIdValue(new ItemId('Q42')))
67
			),
68
			array(
69
				'VIAF',
70
				array(new EntityIdValue(new PropertyId('P214'))),
71
				$this->getInstance('property')
72
			),
73
			array(
74
				'P214',
75
				array(new EntityIdValue(new PropertyId('P214'))),
76
				$this->getInstance('property')
77
			),
78
		);
79
	}
80
81
	/**
82
	 * @see ValueParserTestBase::invalidInputProvider
83
	 */
84
	public function invalidInputProvider() {
85
		return array(
86
			array(
87
				new ItemId('Q23')
88
			)
89
		);
90
	}
91
92
	/**
93
	 * @see ValueParserTestBase::getInstance
94
	 */
95
	protected function getInstance($entityType = 'item') {
96
		return new WikibaseEntityIdParser(
97
			new ApiEntityStore(new MediawikiApi('http://www.wikidata.org/w/api.php')),
98
			$this->newParserOptions($entityType)
99
		);
100
	}
101
102
	/**
103
	 * @see ValueParserTestBase::newParserOptions
104
	 */
105
	protected function newParserOptions($entityType = 'item') {
106
		$parserOptions = new ParserOptions();
107
108
		$parserOptions->setOption(ValueParser::OPT_LANG, 'fr');
109
		$parserOptions->setOption(WikibaseEntityIdParser::OPT_ENTITY_TYPE, $entityType);
110
111
		return $parserOptions;
112
	}
113
114
	/**
115
	 * @return ValueParserTestBase::requireDataValue
0 ignored issues
show
Documentation introduced by
The doc-type ValueParserTestBase::requireDataValue could not be parsed: Unknown type name "ValueParserTestBase::requireDataValue" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
116
	 */
117
	protected function requireDataValue() {
118
		return false;
119
	}
120
}
121