InterwikiLanguageLinkTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 148
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testCanConstruct() 0 7 1
A testConstructorArgumentGetter() 0 22 1
A testConstructDataValue() 0 50 1
A testGetHash() 0 21 1
A testGetContainerId() 0 17 1
A testGetInterwikiReference() 0 11 1
1
<?php
2
3
namespace SIL\Tests;
4
5
use SIL\InterwikiLanguageLink;
6
use SIL\PropertyRegistry;
7
8
use Title;
9
10
/**
11
 * @covers \SIL\InterwikiLanguageLink
12
 *
13
 * @group semantic-interlanguage-links
14
 *
15
 * @license GNU GPL v2+
16
 * @since 1.0
17
 *
18
 * @author mwjames
19
 */
20
class InterwikiLanguageLinkTest extends \PHPUnit_Framework_TestCase {
21
22
	protected function setUp() {
23
		parent::setUp();
24
25
		$propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' )
26
			->disableOriginalConstructor()
27
			->getMock();
28
29
		$instance = new PropertyRegistry();
30
		$instance->register( $propertyRegistry );
31
	}
32
33
	public function testCanConstruct() {
34
35
		$this->assertInstanceOf(
36
			'\SIL\InterwikiLanguageLink',
37
			new InterwikiLanguageLink( 'en:Foo' )
38
		);
39
	}
40
41
	public function testConstructorArgumentGetter() {
42
43
		$title = $this->getMockBuilder( '\Title' )
44
			->disableOriginalConstructor()
45
			->getMock();
46
47
		$title->expects( $this->once() )
48
			->method( 'getInterwiki' )
49
			->will( $this->returnValue( 'en' ) );
50
51
		$instance = new InterwikiLanguageLink( $title );
52
53
		$this->assertEquals(
54
			'en',
55
			$instance->getLanguageCode()
56
		);
57
58
		$this->assertInstanceOf(
59
			'\Title',
60
			$instance->getInterwikiReference()
61
		);
62
	}
63
64
	public function testConstructDataValue() {
65
66
		$title = $this->getMockBuilder( '\Title' )
67
			->disableOriginalConstructor()
68
			->getMock();
69
70
		$title->expects( $this->any() )
71
			->method( 'getInterwiki' )
72
			->will( $this->returnValue( 'en' ) );
73
74
		$title->expects( $this->any() )
75
			->method( 'getNamespace' )
76
			->will( $this->returnValue( NS_MAIN ) );
77
78
		$title->expects( $this->any() )
79
			->method( 'getDBKey' )
80
			->will( $this->returnValue( 'Foo' ) );
81
82
		$instance = new InterwikiLanguageLink( $title );
83
84
		$this->assertInstanceOf(
85
			'\SMWDataValue',
86
			$instance->newLanguageDataValue()
87
		);
88
89
		$this->assertEquals(
90
			PropertyRegistry::SIL_IWL_LANG,
91
			$instance->newLanguageDataValue()->getProperty()->getKey()
92
		);
93
94
		$this->assertInstanceOf(
95
			'\SMWDataValue',
96
			$instance->newInterwikiReferenceDataValue()
97
		);
98
99
		$this->assertEquals(
100
			PropertyRegistry::SIL_IWL_REF,
101
			$instance->newInterwikiReferenceDataValue()->getProperty()->getKey()
102
		);
103
104
		$this->assertInstanceOf(
105
			'\SMW\DIProperty',
106
			$instance->newContainerProperty()
107
		);
108
109
		$this->assertEquals(
110
			PropertyRegistry::SIL_CONTAINER,
111
			$instance->newContainerProperty()->getKey()
112
		);
113
	}
114
115
	public function testGetHash() {
116
117
		$title = $this->getMockBuilder( '\Title' )
118
			->disableOriginalConstructor()
119
			->getMock();
120
121
		$title->expects( $this->any() )
122
			->method( 'getInterwiki' )
123
			->will( $this->returnValue( 'en' ) );
124
125
		$title->expects( $this->any() )
126
			->method( 'getPrefixedText' )
127
			->will( $this->returnValue( 'Foo' ) );
128
129
		$instance = new InterwikiLanguageLink( $title );
130
131
		$this->assertContains(
132
			'en#Foo',
133
			$instance->getHash()
134
		);
135
	}
136
137
	public function testGetContainerId() {
138
139
		$title = $this->getMockBuilder( '\Title' )
140
			->disableOriginalConstructor()
141
			->getMock();
142
143
		$title->expects( $this->once() )
144
			->method( 'getInterwiki' )
145
			->will( $this->returnValue( 'en' ) );
146
147
		$instance = new InterwikiLanguageLink( $title );
148
149
		$this->assertContains(
150
			'iwl.en',
151
			$instance->getContainerId()
152
		);
153
	}
154
155
	public function testGetInterwikiReference() {
156
157
		$linkReference = Title::newFromText( 'en:Foo' );
158
159
		$instance = new InterwikiLanguageLink( 'en:Foo' );
160
161
		$this->assertSame(
162
			$linkReference,
163
			$instance->getInterwikiReference()
164
		);
165
	}
166
167
}
168