testMatchResultsToLanguageForValidSearchResultSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 9.264
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SIL\Tests\Search;
4
5
use SIL\Search\LanguageResultMatchFinder;
6
7
use Title;
8
9
/**
10
 * @covers \SIL\Search\LanguageResultMatchFinder
11
 *
12
 * @group semantic-interlanguage-links
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class LanguageResultMatchFinderTest extends \PHPUnit_Framework_TestCase {
20
21
	public function testCanConstruct() {
22
23
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->assertInstanceOf(
28
			'\SIL\Search\LanguageResultMatchFinder',
29
			new LanguageResultMatchFinder( $interlanguageLinksLookup )
30
		);
31
	}
32
33
	public function testNoMatchResultsToLanguageForNonEmptySearchResultSetThatContainsNullLanguage() {
34
35
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
36
			->disableOriginalConstructor()
37
			->getMock();
38
39
		$instance = new LanguageResultMatchFinder( $interlanguageLinksLookup );
40
41
		$searchResultSet = $this->getMockBuilder( '\SearchResultSet' )
42
			->disableOriginalConstructor()
43
			->getMock();
44
45
		$this->assertNull(
46
			$instance->matchResultsToLanguage( $searchResultSet, 'en' )
47
		);
48
	}
49
50
	public function testNoMatchResultsToLanguageForValidSearchResultSetThatContainsNullLanguage() {
51
52
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
53
			->disableOriginalConstructor()
54
			->getMock();
55
56
		$instance = new LanguageResultMatchFinder( $interlanguageLinksLookup );
57
58
		$searchresult = $this->getMockBuilder( '\SearchResult' )
59
			->disableOriginalConstructor()
60
			->getMock();
61
62
		$searchresult->expects( $this->once() )
63
			->method( 'getTitle' )
64
			->will( $this->returnValue( Title::newFromText( __METHOD__ ) ) );
65
66
		$searchResultSet = $this->getMockBuilder( '\SearchResultSet' )
67
			->disableOriginalConstructor()
68
			->getMock();
69
70
		$searchResultSet->expects( $this->any() )
71
			->method( 'next' )
72
			->will( $this->onConsecutiveCalls( $searchresult, false ) );
73
74
		$this->assertNull(
75
			$instance->matchResultsToLanguage( $searchResultSet, 'en' )
76
		);
77
	}
78
79
	public function testMatchResultsToLanguageForValidSearchResultSet() {
80
81
		$title = Title::newFromText( __METHOD__ );
82
83
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
84
			->disableOriginalConstructor()
85
			->getMock();
86
87
		$interlanguageLinksLookup->expects( $this->atLeastOnce() )
88
			->method( 'hasSilAnnotationFor' )
89
			->with( $this->equalTo( $title ) )
90
			->will( $this->returnValue( true ) );
91
92
		$interlanguageLinksLookup->expects( $this->atLeastOnce() )
93
			->method( 'findPageLanguageForTarget' )
94
			->with( $this->equalTo( $title ) )
95
			->will( $this->returnValue( 'mhr' ) );
96
97
		$instance = new LanguageResultMatchFinder( $interlanguageLinksLookup );
98
99
		$searchresult = $this->getMockBuilder( '\SearchResult' )
100
			->disableOriginalConstructor()
101
			->getMock();
102
103
		$searchresult->expects( $this->atLeastOnce() )
104
			->method( 'getTitle' )
105
			->will( $this->returnValue( $title ) );
106
107
		$searchResultSet = $this->getMockBuilder( '\SearchResultSet' )
108
			->disableOriginalConstructor()
109
			->getMock();
110
111
		$searchResultSet->expects( $this->any() )
112
			->method( 'next' )
113
			->will( $this->onConsecutiveCalls( $searchresult, $searchresult, false ) );
114
115
		$this->assertInstanceOf(
116
			'\SIL\Search\MappedSearchResultSet',
117
			$instance->matchResultsToLanguage( $searchResultSet, 'mhr' )
118
		);
119
	}
120
121
}
122