ApiEntityIdForTermLookupTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 1
c 4
b 0
f 0
lcom 0
cbo 5
dl 0
loc 47
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testGetEntityIdsForTerm() 0 44 1
1
<?php
2
3
namespace Wikibase\EntityStore\Api;
4
5
use Mediawiki\Api\SimpleRequest;
6
use Wikibase\DataModel\Entity\BasicEntityIdParser;
7
use Wikibase\DataModel\Entity\ItemId;
8
use Wikibase\DataModel\Term\Term;
9
10
/**
11
 * @covers Wikibase\EntityStore\Api\ApiEntityIdForTermLookup
12
 *
13
 * @licence GPLv2+
14
 * @author Thomas Pellissier Tanon
15
 */
16
class ApiEntityIdForTermLookupTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testGetEntityIdsForTerm() {
19
		$mediawikiApiMock = $this->getMockBuilder( 'Mediawiki\Api\MediawikiApi' )
20
			->disableOriginalConstructor()
21
			->getMock();
22
		$mediawikiApiMock->expects( $this->once() )
23
			->method( 'getRequest' )
24
			->with( $this->equalTo(
25
				new SimpleRequest(
26
					'wbsearchentities',
27
					[
28
						'search' => 'foo',
29
						'language' => 'en',
30
						'type' => 'item',
31
						'limit' => 50
32
					]
33
				)
34
			) )
35
			->will( $this->returnValue( [
36
				'search' => [
37
					[
38
						'id' => 'Q1',
39
						'label' => 'foo',
40
						'aliases' => [ 'bar', 'baz' ]
41
					],
42
					[
43
						'id' => 'Q2',
44
						'label' => 'bar',
45
						'aliases' => [ 'baz', 'foo' ]
46
					],
47
					[
48
						'id' => 'Q3',
49
						'label' => 'bar',
50
						'aliases' => [ 'baz' ]
51
					]
52
				]
53
			] ) );
54
55
		$lookup = new ApiEntityIdForTermLookup( $mediawikiApiMock, new BasicEntityIdParser() );
56
57
		$this->assertEquals(
58
			[ new ItemId( 'Q1' ), new ItemId( 'Q2' ) ],
59
			$lookup->getEntityIdsForTerm( new Term( 'en', 'foo' ), 'item' )
60
		);
61
	}
62
}
63