Completed
Push — master ( d0ca26...98fb90 )
by mw
37:57
created

NamespaceManagerTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Test;
4
5
use SMW\NamespaceManager;
6
use SMW\Tests\TestEnvironment;
7
use SMW\ExtraneousLanguage;
8
9
/**
10
 * @covers \SMW\NamespaceManager
11
 * @group semantic-mediawiki
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.9
15
 *
16
 * @author mwjames
17
 */
18
class NamespaceManagerTest extends \PHPUnit_Framework_TestCase {
19
20
	private $testEnvironment;
21
	private $extraneousLanguage;
22
	private $default;
23
24
25
	protected function setUp() {
26
		$this->testEnvironment = new TestEnvironment();
27
28
		$this->extraneousLanguage = $this->getMockBuilder( '\SMW\ExtraneousLanguage\ExtraneousLanguage' )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->extraneousLanguage->expects( $this->any() )
33
			->method( 'setLanguageCode' )
34
			->will( $this->returnSelf() );
35
36
		$this->extraneousLanguage->expects( $this->any() )
37
			->method( 'getNamespaces' )
38
			->will( $this->returnValue( array() ) );
39
40
		$this->extraneousLanguage->expects( $this->any() )
41
			->method( 'getNamespaceAliases' )
42
			->will( $this->returnValue( array() ) );
43
44
		$this->default = array(
45
			'smwgNamespacesWithSemanticLinks' => array(),
46
			'wgNamespacesWithSubpages' => array(),
47
			'wgExtraNamespaces'  => array(),
48
			'wgNamespaceAliases' => array(),
49
			'wgLanguageCode'     => 'en'
50
		);
51
	}
52
53
	protected function tearDown() {
54
		$this->testEnvironment->tearDown();
55
	}
56
57
	public function testCanConstruct() {
58
59
		$this->assertInstanceOf(
60
			'\SMW\NamespaceManager',
61
			new NamespaceManager( $test, $this->extraneousLanguage )
0 ignored issues
show
Unused Code introduced by
The call to NamespaceManager::__construct() has too many arguments starting with $this->extraneousLanguage.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
62
		);
63
	}
64
65
	public function testExecution() {
66
		$test = $this->default;
67
68
		$instance = new NamespaceManager( $test, $this->extraneousLanguage );
0 ignored issues
show
Unused Code introduced by
The call to NamespaceManager::__construct() has too many arguments starting with $this->extraneousLanguage.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
69
		$instance->init();
70
71
		$this->assertNotEmpty(
72
			$test
73
		);
74
	}
75
76
	public function testExecutionWithIncompleteConfiguration() {
77
78
		$test = $this->default + array(
79
			'wgExtraNamespaces'  => '',
80
			'wgNamespaceAliases' => ''
81
		);
82
83
		$instance = new NamespaceManager( $test, $this->extraneousLanguage );
0 ignored issues
show
Unused Code introduced by
The call to NamespaceManager::__construct() has too many arguments starting with $this->extraneousLanguage.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
84
		$instance->init();
85
86
		$this->assertNotEmpty(
87
			$test
88
		);
89
	}
90
91
	public function testGetCanonicalNames() {
92
93
		$this->testEnvironment->addConfiguration(
94
			'smwgHistoricTypeNamespace',
95
			false
96
		);
97
98
		$result = NamespaceManager::getCanonicalNames();
99
100
		$this->assertInternalType(
101
			'array',
102
			$result
103
		);
104
105
		$this->assertCount(
106
			4,
107
			$result
108
		);
109
	}
110
111
	public function testGetCanonicalNamesWithTypeNamespace() {
112
113
		$this->testEnvironment->addConfiguration(
114
			'smwgHistoricTypeNamespace',
115
			true
116
		);
117
118
		$result = NamespaceManager::getCanonicalNames();
119
120
		$this->assertInternalType(
121
			'array',
122
			$result
123
		);
124
125
		$this->assertCount(
126
			6,
127
			$result
128
		);
129
	}
130
131
	public function testBuildNamespaceIndex() {
132
		$this->assertInternalType(
133
			'array',
134
			NamespaceManager::buildNamespaceIndex( 100 )
135
		);
136
	}
137
138
	public function testInitCustomNamespace() {
139
140
		$test = array();
141
		NamespaceManager::initCustomNamespace( $test );
142
143
		$this->assertNotEmpty( $test );
144
		$this->assertEquals(
145
			100,
146
			$test['smwgNamespaceIndex']
147
		);
148
	}
149
150
}
151