Completed
Push — master ( c3e068...3f9a02 )
by
unknown
02:14
created

testLoadIwMapForExternalRepositoryMatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 9.408
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SEQL\Tests;
4
5
use SEQL\DynamicInterwikiPrefixLoader;
6
7
/**
8
 * @covers \SEQL\DynamicInterwikiPrefixLoader
9
 * @group semantic-external-query-lookup
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class DynamicInterwikiPrefixLoaderTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$interwikiPrefixMap = array();
21
22
		$this->assertInstanceOf(
23
			'\SEQL\DynamicInterwikiPrefixLoader',
24
			new DynamicInterwikiPrefixLoader( $interwikiPrefixMap )
25
		);
26
	}
27
28
	public function testLoadIwMapForExternalRepositoryMatch() {
29
30
		$interwikiPrefixMap = array(
31
			'mw-foo' => array(
32
				'http://example.org:8080/mw-foo/index.php/$1', // corresponds to iw_url
33
				'http://example.org:8080/mw-foo/api.php',      // corresponds to iw_api
34
				true                                           // corresponds to iw_local
35
			)
36
		);
37
38
		$instance = new DynamicInterwikiPrefixLoader( $interwikiPrefixMap );
39
40
		$expected = array(
41
			'iw_prefix' => 'mw-foo',
42
			'iw_url' => 'http://example.org:8080/mw-foo/index.php/$1',
43
			'iw_api' => 'http://example.org:8080/mw-foo/api.php',
44
			'iw_wikiid' => 'mw-foo',
45
			'iw_local' => true,
46
			'iw_trans' => false
47
		);
48
49
		$interwiki = array();
50
51
		$this->assertFalse(
52
			$instance->tryToLoadIwMapForExternalRepository( 'mw-foo', $interwiki )
53
		);
54
55
		$this->assertEquals(
56
			$expected,
57
			$interwiki
58
		);
59
	}
60
61
	public function testTryLoadIwMapForNoExternalRepositoryMatch() {
62
63
		$interwikiPrefixMap = array();
64
65
		$instance = new DynamicInterwikiPrefixLoader( $interwikiPrefixMap );
66
67
		$interwiki = array();
68
69
		$this->assertTrue(
70
			$instance->tryToLoadIwMapForExternalRepository( 'mw-foo', $interwiki )
71
		);
72
73
		$this->assertEmpty(
74
			$interwiki
75
		);
76
	}
77
78
}
79