SiteLanguageLinksParserOutputAppenderTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 116
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 18 1
A testAddLanguageTargetLinksToOutput() 0 27 1
A testCompareLanguageTargetLinksForExistingLanguageEntry() 0 33 1
A testAddLanguageTargetLinksToOutputFromStoreForMultipleInvocation() 0 31 1
1
<?php
2
3
namespace SIL\Tests;
4
5
use SIL\SiteLanguageLinksParserOutputAppender;
6
use SIL\InterlanguageLink;
7
8
use SMW\DIWikiPage;
9
use SMWDIBlob as DIBlob;
10
11
/**
12
 * @covers \SIL\SiteLanguageLinksParserOutputAppender
13
 * @group semantic-interlanguage-links
14
 *
15
 * @license GNU GPL v2+
16
 * @since 1.0
17
 *
18
 * @author mwjames
19
 */
20
class SiteLanguageLinksParserOutputAppenderTest extends \PHPUnit_Framework_TestCase {
21
22
	public function testCanConstruct() {
23
24
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
28
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->assertInstanceOf(
33
			'\SIL\SiteLanguageLinksParserOutputAppender',
34
			new SiteLanguageLinksParserOutputAppender(
35
				$parserOutput,
36
				$interlanguageLinksLookup
37
			)
38
		);
39
	}
40
41
	public function testAddLanguageTargetLinksToOutput() {
42
43
		$interlanguageLink = new InterlanguageLink( 'en', 'Foo' );
44
45
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
46
			->disableOriginalConstructor()
47
			->getMock();
48
49
		$parserOutput->expects( $this->once() )
50
			->method( 'addLanguageLink' );
51
52
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
53
			->disableOriginalConstructor()
54
			->getMock();
55
56
		$interlanguageLinksLookup->expects( $this->once() )
57
			->method( 'queryLanguageTargetLinks' )
58
			->with( $this->equalTo( $interlanguageLink ) )
59
			->will( $this->returnValue( [ 'fr' => 'Bar' ] ) );
60
61
		$instance = new SiteLanguageLinksParserOutputAppender(
62
			$parserOutput,
63
			$interlanguageLinksLookup
64
		);
65
66
		$instance->tryAddLanguageTargetLinksToOutput( $interlanguageLink );
67
	}
68
69
	public function testCompareLanguageTargetLinksForExistingLanguageEntry() {
70
71
		$interlanguageLink = new InterlanguageLink( 'en', 'Yui' );
72
73
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
74
			->disableOriginalConstructor()
75
			->getMock();
76
77
		$parserOutput->expects( $this->never() )
78
			->method( 'addLanguageLink' );
79
80
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
81
			->disableOriginalConstructor()
82
			->getMock();
83
84
		$interlanguageLinksLookup->expects( $this->once() )
85
			->method( 'queryLanguageTargetLinks' )
86
			->with( $this->equalTo( $interlanguageLink ) )
87
			->will( $this->returnValue( [ 'en' => \Title::newFromText( 'Foo' ) ] ) );
88
89
		$instance = new SiteLanguageLinksParserOutputAppender(
90
			$parserOutput,
91
			$interlanguageLinksLookup
92
		);
93
94
		$knownTarget = $instance->tryAddLanguageTargetLinksToOutput(
95
			$interlanguageLink
96
		);
97
98
		$this->assertFalse(
99
			 $knownTarget
100
		);
101
	}
102
103
	public function testAddLanguageTargetLinksToOutputFromStoreForMultipleInvocation() {
104
105
		$interlanguageLink = new InterlanguageLink( 'en', 'Foo' );
106
107
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
108
			->disableOriginalConstructor()
109
			->getMock();
110
111
		$parserOutput->expects( $this->once() )
112
			->method( 'addLanguageLink' )
113
			->with( $this->equalTo( 'sil:vi:Yan' ) );
114
115
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
116
			->disableOriginalConstructor()
117
			->getMock();
118
119
		$interlanguageLinksLookup->expects( $this->atLEastOnce() )
120
			->method( 'queryLanguageTargetLinks' )
121
			->with( $this->equalTo( $interlanguageLink ) )
122
			->will( $this->returnValue( [ 'vi' => \Title::newFromText( 'Yan' ) ] ) );
123
124
		$instance = new SiteLanguageLinksParserOutputAppender(
125
			$parserOutput,
126
			$interlanguageLinksLookup
127
		);
128
129
		$instance->tryAddLanguageTargetLinksToOutput( $interlanguageLink );
130
131
		// Simualate call from a second parser call
132
		$instance->tryAddLanguageTargetLinksToOutput( $interlanguageLink );
133
	}
134
135
}
136