Completed
Push — master ( 1597db...37b3e5 )
by mw
16:02
created

testParseOnMissingAnnotatedLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace SIL\Tests;
4
5
use SIL\AnnotatedLanguageParserFunction;
6
7
/**
8
 * @covers \SIL\AnnotatedLanguageParserFunction
9
 * @group semantic-interlanguage-links
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class AnnotatedLanguageParserFunctionTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
21
			->disableOriginalConstructor()
22
			->getMock();
23
24
		$this->assertInstanceOf(
25
			AnnotatedLanguageParserFunction::class,
26
			new AnnotatedLanguageParserFunction( $interlanguageLinksLookup )
27
		);
28
	}
29
30
	public function testParseOnMissingAnnotatedLanguage() {
31
32
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
33
			->disableOriginalConstructor()
34
			->getMock();
35
36
		$interlanguageLinksLookup->expects( $this->once() )
37
			->method( 'findPageLanguageForTarget' )
38
			->will( $this->returnValue( '' ) );
39
40
		$interlanguageLinksLookup->expects( $this->once() )
41
			->method( 'getRedirectTargetFor' )
42
			->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) );
43
44
		$instance = new AnnotatedLanguageParserFunction(
45
			$interlanguageLinksLookup
46
		);
47
48
		$this->assertEquals(
49
			'',
50
			$instance->parse( \Title::newFromText( 'Foo' ), 'FakeTemplate' )
51
		);
52
	}
53
54
	public function testParseOnAnnotatedLanguageWithoutTemplate() {
55
56
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
57
			->disableOriginalConstructor()
58
			->getMock();
59
60
		$interlanguageLinksLookup->expects( $this->once() )
61
			->method( 'findPageLanguageForTarget' )
62
			->will( $this->returnValue( 'en' ) );
63
64
		$interlanguageLinksLookup->expects( $this->once() )
65
			->method( 'getRedirectTargetFor' )
66
			->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) );
67
68
		$instance = new AnnotatedLanguageParserFunction(
69
			$interlanguageLinksLookup
70
		);
71
72
		$expected = 'en';
73
74
		$this->assertEquals(
75
			$expected,
76
			$instance->parse( \Title::newFromText( 'Foo' ), '' )
77
		);
78
	}
79
80
	public function testParseOnAnnotatedLanguageWithTemplate() {
81
82
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
83
			->disableOriginalConstructor()
84
			->getMock();
85
86
		$interlanguageLinksLookup->expects( $this->once() )
87
			->method( 'findPageLanguageForTarget' )
88
			->will( $this->returnValue( 'en' ) );
89
90
		$interlanguageLinksLookup->expects( $this->once() )
91
			->method( 'getRedirectTargetFor' )
92
			->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) );
93
94
		$instance = new AnnotatedLanguageParserFunction(
95
			$interlanguageLinksLookup
96
		);
97
98
		$expected = '{{FakeTemplate|target-link=Foo|lang-code=en|lang-name=English}}';
99
100
		$this->assertEquals(
101
			array( $expected, "noparse" => false, "isHTML" => false ),
102
			$instance->parse( \Title::newFromText( 'Foo' ), 'FakeTemplate' )
103
		);
104
	}
105
106
}
107