summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Elastic/Lookup/ProximityPropertyValueLookupTest.php
blob: aef583706039103052d75978c04a0c65f2851cb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php

namespace SMW\Tests\Elastic\Lookup;

use SMW\Elastic\Lookup\ProximityPropertyValueLookup;
use SMW\Tests\PHPUnitCompat;
use SMW\DIProperty;
use SMW\RequestOptions;

/**
 * @covers \SMW\Elastic\Lookup\ProximityPropertyValueLookup
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class ProximityPropertyValueLookupTest extends \PHPUnit_Framework_TestCase {

	use PHPUnitCompat;

	private $logger;
	private $store;
	private $elasticClient;

	protected function setUp() {

		$this->logger = $this->getMockBuilder( '\Psr\Log\LoggerInterface' )
			->disableOriginalConstructor()
			->getMock();

		$this->idTable = $this->getMockBuilder( '\stdClass' )
			->disableOriginalConstructor()
			->setMethods( [ 'getSMWPropertyID' ] )
			->getMock();

		$this->idTable->expects( $this->any() )
			->method( 'getSMWPropertyID' )
			->will( $this->onConsecutiveCalls( 42, 1001, 9000, 110001 ) );

		$this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
			->disableOriginalConstructor()
			->setMethods( [ 'getObjectIds', 'getConnection' ] )
			->getMock();

		$this->store->expects( $this->any() )
			->method( 'getObjectIds' )
			->will( $this->returnValue( $this->idTable ) );

		$this->elasticClient = $this->getMockBuilder( '\SMW\Elastic\Connection\Client' )
			->disableOriginalConstructor()
			->getMock();

		$this->store->expects( $this->any() )
			->method( 'getConnection' )
			->will( $this->returnValue( $this->elasticClient ) );
	}

	public function testCanConstruct() {

		$this->assertInstanceOf(
			ProximityPropertyValueLookup::class,
			new ProximityPropertyValueLookup( $this->store )
		);
	}

	public function testLookup_AnyValue() {

		$params = [
			'index' => null,
			'type' => 'data',
			'body' => [
				'_source' => [ 'P:42.wpgField' ],
				'from' => 0,
				'size' => 500,
				'query' => [
					'exists' => [ 'field' => 'P:42.wpgField' ]
				]
			]
		];

		$this->elasticClient->expects( $this->once() )
			->method( 'search' )
			->with( $this->equalTo( $params ) );

		$instance = new ProximityPropertyValueLookup(
			$this->store
		);

		$instance->lookup( new DIProperty( 'Foo' ), '', new RequestOptions() );
	}

}