summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/System/InstallationConfigurationIntegrityTest.php
blob: 986d6419e7de8b57cd629a0e64767d2a3abd1637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php

namespace SMW\Tests\System;

use SMW\ApplicationFactory;
use SMW\Tests\Utils\GlobalsProvider;

/**
 * @group SMW
 * @group SMWExtension
 *
 * @group semantic-mediawiki-system
 * @group mediawiki-databaseless
 *
 * @license GNU GPL v2+
 * @since 1.9
 *
 * @author mwjames
 */
class InstallationGlobalsProviderIntegrityTest extends \PHPUnit_Framework_TestCase {

	private $globalsProvider;
	private $applicationFactory;

	protected function setUp() {
		parent::setUp();

		$this->globalsProvider = GlobalsProvider::getInstance();
		$this->applicationFactory = ApplicationFactory::getInstance();
	}

	protected function tearDown() {
		$this->globalsProvider->clear();
		$this->applicationFactory->clear();

		parent::tearDown();
	}

	public function testNamespaceSettingOnExampleIfSet() {

		$expected = 'http://example.org/id/';

		if ( $this->globalsProvider->get( 'smwgNamespace' ) !== $expected ) {
			$this->markTestSkipped( "Skip test due to missing {$expected} setting" );
		}

		$this->assertSame(
			$this->globalsProvider->get( 'smwgNamespace' ),
			$this->applicationFactory->getSettings()->get( 'smwgNamespace' )
		);
	}

	/**
	 * @dataProvider smwgNamespacesWithSemanticLinksProvider
	 */
	public function testNamespacesWithSemanticLinksOnTravisCustomNamespace( $type, $container ) {

		if ( !defined( 'NS_TRAVIS' ) ) {
			$this->markTestSkipped( 'Test can only be executed with a specified NS_TRAVIS' );
		}

		$namespace = NS_TRAVIS;
		$extraNamespaces = $this->globalsProvider->get( 'wgExtraNamespaces' );

		$this->assertTrue(
			isset( $extraNamespaces[$namespace] )
		);

		$foundNamespaceEntry = false;

		foreach ( $container as $key => $value ) {
			if ( $key === $namespace ) {
				$foundNamespaceEntry = true;
				break;
			}
		}

		$this->assertTrue(
			$foundNamespaceEntry,
			"Asserts that smwgNamespacesWithSemanticLinks retrieved from {$type} contains the expected {$namespace} NS"
		);
	}

	/**
	 * @since 1.9
	 */
	public function smwgNamespacesWithSemanticLinksProvider() {

		$provider = [];

		$provider[] = [
			'GLOBALS',
			GlobalsProvider::getInstance()->get( 'smwgNamespacesWithSemanticLinks' )
		];

		$provider[] = [
			'Settings',
			ApplicationFactory::getInstance()->getSettings()->get( 'smwgNamespacesWithSemanticLinks' )
		];

		return $provider;
	}

}