Completed
Push — master ( f99eb7...4c2f46 )
by mw
50:24 queued 17:14
created

NamespaceManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace SMW\Test;
4
5
use SMW\NamespaceManager;
6
use SMW\Tests\TestEnvironment;
7
8
/**
9
 * @covers \SMW\NamespaceManager
10
 * @group semantic-mediawiki
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.9
14
 *
15
 * @author mwjames
16
 */
17
class NamespaceManagerTest extends \PHPUnit_Framework_TestCase {
18
19
	private $testEnvironment;
20
21
	protected function setUp() {
22
		$this->testEnvironment = new TestEnvironment();
23
	}
24
25
	protected function tearDown() {
26
		$this->testEnvironment->tearDown();
27
	}
28
29
	private function newInstance( &$test = array(), $langCode = 'en' ) {
30
31
		$default = array(
32
			'smwgNamespacesWithSemanticLinks' => array(),
33
			'wgNamespacesWithSubpages' => array(),
34
			'wgExtraNamespaces'  => array(),
35
			'wgNamespaceAliases' => array(),
36
			'wgLanguageCode'     => $langCode
37
		);
38
39
		$test = array_merge( $default, $test );
40
41
		$smwBasePath = __DIR__ . '../../../..';
42
43
		return new NamespaceManager( $test, $smwBasePath );
0 ignored issues
show
Unused Code introduced by
The call to NamespaceManager::__construct() has too many arguments starting with $smwBasePath.

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...
44
	}
45
46
	public function testCanConstruct() {
47
48
		$this->assertInstanceOf(
49
			'\SMW\NamespaceManager',
50
			$this->newInstance()
51
		);
52
	}
53
54
	public function testExecution() {
55
56
		$test = array();
57
58
		$this->newInstance( $test )->init();
59
60
		$this->assertNotEmpty(
61
			$test
62
		);
63
	}
64
65
	public function testExecutionWithIncompleteConfiguration() {
66
67
		$test = array(
68
			'wgExtraNamespaces'  => '',
69
			'wgNamespaceAliases' => ''
70
		);
71
72
		$this->newInstance( $test )->init();
73
74
		$this->assertNotEmpty(
75
			$test
76
		);
77
	}
78
79
	public function testExecutionWithLanguageFallback() {
80
81
		$test = array();
82
83
		$this->newInstance( $test, 'foo' )->init();
84
85
		$this->assertNotEmpty(
86
			$test
87
		);
88
	}
89
90
	public function testGetCanonicalNames() {
91
92
		$this->testEnvironment->addConfiguration(
93
			'smwgHistoricTypeNamespace',
94
			false
95
		);
96
97
		$result = NamespaceManager::getCanonicalNames();
98
99
		$this->assertInternalType(
100
			'array',
101
			$result
102
		);
103
104
		$this->assertCount(
105
			4,
106
			$result
107
		);
108
	}
109
110
	public function testGetCanonicalNamesWithTypeNamespace() {
111
112
		$this->testEnvironment->addConfiguration(
113
			'smwgHistoricTypeNamespace',
114
			true
115
		);
116
117
		$result = NamespaceManager::getCanonicalNames();
118
119
		$this->assertInternalType(
120
			'array',
121
			$result
122
		);
123
124
		$this->assertCount(
125
			6,
126
			$result
127
		);
128
	}
129
130
	public function testBuildNamespaceIndex() {
131
		$this->assertInternalType(
132
			'array',
133
			NamespaceManager::buildNamespaceIndex( 100 )
134
		);
135
	}
136
137
	public function testInitCustomNamespace() {
138
139
		$test = array();
140
		NamespaceManager::initCustomNamespace( $test );
141
142
		$this->assertNotEmpty( $test );
143
		$this->assertEquals(
144
			100,
145
			$test['smwgNamespaceIndex'],
146
			'Asserts that smwgNamespaceIndex is being set to a default index'
147
		);
148
	}
149
150
}
151