summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/MWNamespaceCanonicalNameMatchTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/MWNamespaceCanonicalNameMatchTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/MWNamespaceCanonicalNameMatchTest.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/MWNamespaceCanonicalNameMatchTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/MWNamespaceCanonicalNameMatchTest.php
new file mode 100644
index 00000000..b76cc65f
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/MWNamespaceCanonicalNameMatchTest.php
@@ -0,0 +1,87 @@
+<?php
+
+namespace SMW\Tests\Integration\MediaWiki;
+
+use MWNamespace;
+use SMW\NamespaceManager;
+use SMW\Settings;
+use SMW\Tests\Utils\MwHooksHandler;
+
+/**
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class MWNamespaceCanonicalNameMatchTest extends \PHPUnit_Framework_TestCase {
+
+ private $mwHooksHandler;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->mwHooksHandler = new MwHooksHandler();
+ }
+
+ public function tearDown() {
+ $this->mwHooksHandler->restoreListedHooks();
+
+ parent::tearDown();
+ }
+
+ public function testRunNamespaceManagerWithNoConstantsDefined() {
+
+ $this->mwHooksHandler->deregisterListedHooks();
+
+ $default = [
+ 'smwgNamespacesWithSemanticLinks' => [],
+ 'wgNamespacesWithSubpages' => [],
+ 'wgExtraNamespaces' => [],
+ 'wgNamespaceAliases' => [],
+ 'wgContentNamespaces' => [],
+ 'wgNamespacesToBeSearchedDefault' => [],
+ 'wgLanguageCode' => 'en'
+ ];
+
+ $instance = $this->getMockBuilder( '\SMW\NamespaceManager' )
+ ->setMethods( [ 'isDefinedConstant' ] )
+ ->getMock();
+
+ $instance->expects( $this->atLeastOnce() )
+ ->method( 'isDefinedConstant' )
+ ->will( $this->returnValue( false ) );
+
+ $instance->init( $default );
+ }
+
+ public function testCanonicalNames() {
+
+ $this->mwHooksHandler->deregisterListedHooks();
+
+ $count = 0;
+ $index = NamespaceManager::buildNamespaceIndex( Settings::newFromGlobals()->get( 'smwgNamespaceIndex' ) );
+ $names = NamespaceManager::getCanonicalNames();
+
+ $this->assertInternalType( 'array', $names );
+ $this->assertInternalType( 'array', $index );
+
+ foreach ( $index as $ns => $idx ) {
+
+ $mwNamespace = MWNamespace::getCanonicalName( $idx );
+
+ if ( $mwNamespace && isset( $names[$idx] ) ) {
+ $this->assertEquals( $mwNamespace, $names[$idx] );
+ $count++;
+ }
+ }
+
+ $this->assertCount(
+ $count,
+ $names,
+ "Asserts that expected amount of cannonical names have been verified"
+ );
+ }
+
+}