Completed
Push — master ( c3e068...3f9a02 )
by
unknown
02:14
created

ByHttpRequestQueryLookupTest::testGetQueryResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SEQL\Tests;
4
5
use SMWQuery as Query;
6
7
/**
8
 * @covers \SEQL\ByHttpRequestQueryLookup
9
 * @group semantic-external-query-lookup
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class ByHttpRequestQueryLookupTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' )
21
			->disableOriginalConstructor()
22
			->getMock();
23
24
		$this->assertInstanceOf(
25
			'\SMW\Store',
26
			$instance
27
		);
28
	}
29
30
	public function testGetQueryResult() {
31
32
		$description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
33
			->disableOriginalConstructor()
34
			->getMockForAbstractClass();
35
36
		$query = $this->getMockBuilder( '\SMWQuery' )
37
			->disableOriginalConstructor()
38
			->getMock();
39
40
		$query->expects( $this->any() )
41
			->method( 'getDescription' )
42
			->will( $this->returnValue( $description ) );
43
44
		$instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' )
45
			->disableOriginalConstructor()
46
			->setMethods( null )
47
			->getMock();
48
49
		$this->assertInstanceOf(
50
			'\SMWQueryResult',
51
			$instance->getQueryResult( $query )
52
		);
53
	}
54
55
	public function testGetEmptyQueryResult_MODE_DEBUG() {
56
57
		$description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
58
			->disableOriginalConstructor()
59
			->getMockForAbstractClass();
60
61
		$query = $this->getMockBuilder( '\SMWQuery' )
62
			->disableOriginalConstructor()
63
			->getMock();
64
65
		$query->expects( $this->any() )
66
			->method( 'getDescription' )
67
			->will( $this->returnValue( $description ) );
68
69
		$query->expects( $this->once() )
70
			->method( 'addErrors' );
71
72
		$instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' )
73
			->disableOriginalConstructor()
74
			->setMethods( null )
75
			->getMock();
76
77
		$query->querymode = Query::MODE_DEBUG;
78
79
		$this->assertInstanceOf(
80
			'\SMWQueryResult',
81
			$instance->getQueryResult( $query )
82
		);
83
	}
84
85
	public function testGetQueryResultForSimulatedInterwikiMatch() {
86
87
		$interwiki = $this->getMockBuilder( '\Interwiki' )
88
			->disableOriginalConstructor()
89
			->getMock();
90
91
		$description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
92
			->disableOriginalConstructor()
93
			->getMockForAbstractClass();
94
95
		$query = $this->getMockBuilder( '\SMWQuery' )
96
			->disableOriginalConstructor()
97
			->getMock();
98
99
		$query->expects( $this->any() )
100
			->method( 'getDescription' )
101
			->will( $this->returnValue( $description ) );
102
103
		$query->expects( $this->atLeastOnce() )
104
			->method( 'getExtraPrintouts' )
105
			->will( $this->returnValue( array() ) );
106
107
		$query->expects( $this->once() )
108
			->method( 'getSortKeys' )
109
			->will( $this->returnValue( array() ) );
110
111
		$instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' )
112
			->disableOriginalConstructor()
113
			->setMethods( array( 'tryToMatchInterwikiFor' ) )
114
			->getMock();
115
116
		$instance->expects( $this->once() )
117
			->method( 'tryToMatchInterwikiFor' )
118
			->will( $this->returnValue( $interwiki ) );
119
120
		$this->assertInstanceOf(
121
			'\SMWQueryResult',
122
			$instance->getQueryResult( $query )
123
		);
124
	}
125
126
}
127