summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/QuerySegmentListBuildManagerTest.php
blob: 6245b2b9eab3fbb1839443b8d24ba271b20ec517 (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
<?php

namespace SMW\Tests\SQLStore\QueryEngine;

use SMW\SQLStore\QueryEngine\QuerySegmentListBuildManager;

/**
 * @covers \SMW\SQLStore\QueryEngine\QuerySegmentListBuildManager
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 2.5
 *
 * @author mwjames
 */
class QuerySegmentListBuildManagerTest extends \PHPUnit_Framework_TestCase {

	private $connection;
	private $querySegmentListBuilder;
	private $orderCondition;

	protected function setUp() {

		$this->connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' )
			->disableOriginalConstructor()
			->getMock();

		$this->querySegmentListBuilder = $this->getMockBuilder( '\SMW\SQLStore\QueryEngine\QuerySegmentListBuilder' )
			->disableOriginalConstructor()
			->getMock();

		$this->orderCondition = $this->getMockBuilder( '\SMW\SQLStore\QueryEngine\OrderCondition' )
			->disableOriginalConstructor()
			->getMock();
	}

	public function testCanConstruct() {

		$this->assertInstanceOf(
			QuerySegmentListBuildManager::class,
			new QuerySegmentListBuildManager( $this->connection, $this->querySegmentListBuilder, $this->orderCondition )
		);
	}

	public function testGetQuerySegmentFrom() {

		$description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
			->disableOriginalConstructor()
			->getMock();

		$query = $this->getMockBuilder( '\SMWQuery' )
			->disableOriginalConstructor()
			->getMock();

		$query->expects( $this->atLeastOnce() )
			->method( 'getDescription' )
			->will( $this->returnValue( $description ) );

		$this->querySegmentListBuilder->expects( $this->once() )
			->method( 'getQuerySegmentFrom' );

		$this->orderCondition->expects( $this->once() )
			->method( 'apply' );

		$instance = new QuerySegmentListBuildManager(
			$this->connection,
			$this->querySegmentListBuilder,
			$this->orderCondition
		);

		$instance->getQuerySegmentFrom( $query );
	}

}