Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

(Bug 34383) Canonical namespace names #47

Merged
merged 3 commits into from

2 participants

@mwjames
Owner
@JeroenDeDauw JeroenDeDauw was assigned
@mwjames
Owner

Based on the above change-set but not really related to the bug, I will re-introduces enableSemantics() which can be called in LocalSettings after $smwgNamespaceIndex is set.

enableSemantics() will contain NamespaceManager::initCustomNamespace( $GLOBALS ); which is responsible to define the NS constants which solves the issue as in [1] without the need to introduce delayed loading.

If users don't include enableSemantics() in LocalSettings, \SMW\Setup will run NamespaceCustomizer anyway but in this case SMW-NS can't be used within LocalSetting unless it is put into delayed loading.

If users include enableSemantics() in LocalSettings, references to SMW-NS work as before (of course after the inclusion of enableSemantics) which should minimize any inconvenience introduced by using Composer as installer and with it the different LocalSettings loading priority in MW 1.22.

[1] https://bugzilla.wikimedia.org/show_bug.cgi?id=58182

@JeroenDeDauw

So in this case people will be required to first call enableSemantics in LS, and only after that make use of the NS constants?

@mwjames
Owner

Well, yes because only after enableSemantics() is called SMW-NS are specified .

enableSemantics() is the smallest of all "evil" options because making people understand to change their customizing (using delayed loading for non-related SMW customizing like [1] ) because of Composer will be far more difficult as to continue to expect people to insert enableSemantics() which will allow existing settings to continue to work for both MW 1.19 and MW 1.22+.

initCustomNamespace is called with or without enableSemantics() but this function is expected to be included in LocalSettings and exists since SMW 1.5 as customizing therefore nothing would change for people who already use SMW.

[1] $wgContentNamespaces, $wgNamespacesToBeSearchedDefault and $wgNamespaceProtection

mwjames added some commits
@mwjames mwjames (Bug 34383) Canonical namespace names dc5862d
@mwjames mwjames Re-introduce enableSemantics() to avoid Notice: Use of undefined cons…
…tant SMW_NS_PROPERTY

After smwgNamespaceIndex and $smwgNamespace are set enableSemantics() is
called to specify SMW related custom namespaces.

## Example LocalSettings
$smwgNamespaceIndex = 104;
enableSemantics( 'http://example.org/id/';, true );
...
ba30b84
@mwjames mwjames Some minor clean-up da6c3b3
@mwjames
Owner

During testing Composer\Downloader\TransportException occurred, see [1] .

[1] #50

@mwjames mwjames referenced this pull request from a commit
@mwjames mwjames Use --prefer-source because of GitHub quota
[1] showed Composer\Downloader\TransportException during Travis initialization
which according to [2] is because of a GitHub quota

[1] #47

[2] https://github.com/travis-ci/travis-core/issues/186
88f7fba
@mwjames mwjames merged commit 32fe256 into master
@mwjames mwjames deleted the namespaces branch
@JeroenDeDauw

The docs should also be updated (INSTALL.md). And I'm not sure the requirements are the same as with older SMW versions. The location at which the call should be put might be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 11, 2013
  1. @mwjames
  2. @mwjames

    Re-introduce enableSemantics() to avoid Notice: Use of undefined cons…

    mwjames authored
    …tant SMW_NS_PROPERTY
    
    After smwgNamespaceIndex and $smwgNamespace are set enableSemantics() is
    called to specify SMW related custom namespaces.
    
    ## Example LocalSettings
    $smwgNamespaceIndex = 104;
    enableSemantics( 'http://example.org/id/';, true );
    ...
Commits on Dec 12, 2013
  1. @mwjames

    Some minor clean-up

    mwjames authored
This page is out of date. Refresh to see the latest.
View
5 SemanticMediaWiki.php
@@ -3,7 +3,7 @@
use SMW\SimpleDependencyBuilder;
use SMW\SharedDependencyContainer;
use SMW\ExtensionContext;
-use SMW\NamespaceCustomizer;
+use SMW\NamespaceManager;
use SMW\Setup;
/**
@@ -89,6 +89,7 @@ class_alias( 'SMW\AggregatablePrinter', 'SMWAggregatablePrinter' );
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWiki'] = $GLOBALS['smwgIP'] . 'languages/SMW_Messages.php';
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiAlias'] = $GLOBALS['smwgIP'] . 'languages/SMW_Aliases.php';
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiMagic'] = $GLOBALS['smwgIP'] . 'languages/SMW_Magic.php';
+$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiNamespaces'] = $GLOBALS['smwgIP'] . 'languages/SemanticMediaWiki.namespaces.php';
/**
* Setup and initialization
@@ -106,7 +107,7 @@ class_alias( 'SMW\AggregatablePrinter', 'SMWAggregatablePrinter' );
$builder = new SimpleDependencyBuilder( new SharedDependencyContainer() );
$context = new ExtensionContext( $builder );
- $namespace = new NamespaceCustomizer( $GLOBALS, __DIR__ );
+ $namespace = new NamespaceManager( $GLOBALS, __DIR__ );
$namespace->run();
$setup = new Setup( $GLOBALS, __DIR__, $context );
View
10 includes/GlobalFunctions.php
@@ -1,4 +1,7 @@
<?php
+
+use SMW\NamespaceManager;
+
/**
* Global functions specified and used by Semantic MediaWiki. In general, it is
* tried to fit functions in suitable classes as static methods if they clearly
@@ -268,8 +271,6 @@ function smwfGetLinker() {
* This function also sets up all autoloading, such that all SMW classes are
* available as early on. Moreover, jobs and special pages are registered.
*
- * @deprecated since 1.9, just set $smwgNamespace after the inclusion of SemanticMediaWiki.php
- *
* @param mixed $namespace
* @param boolean $complete
*
@@ -280,6 +281,11 @@ function smwfGetLinker() {
function enableSemantics( $namespace = null, $complete = false ) {
global $smwgNamespace;
+ // $GLOBALS ought to be injected from the top-level but that would require
+ // to change the interface which would bring no benefits for the end user
+ // as enableSemantics() is only targeted to be included in LocalSettings
+ NamespaceManager::initCustomNamespace( $GLOBALS );
+
if ( !$complete && ( $smwgNamespace !== '' ) ) {
// The dot tells that the domain is not complete. It will be completed
// in the Export since we do not want to create a title object here when
View
156 includes/NamespaceCustomizer.php → includes/NamespaceManager.php
@@ -8,8 +8,10 @@
* @licence GNU GPL v2+
* @since 1.9
*
+ * @author mwjames
+ * @author others
*/
-final class NamespaceCustomizer {
+final class NamespaceManager {
/** @var array */
protected $globals;
@@ -28,48 +30,95 @@ public function __construct( &$globals, $directory ) {
* @since 1.9
*/
public function run() {
- $this->initNamespaces();
+
+ if ( !defined( 'SMW_NS_PROPERTY' ) ) {
+ $this->initCustomNamespace( $this->globals );
+ }
+
+ if ( empty( $this->globals['smwgContLang'] ) ) {
+ $this->initContentLanguage( $this->globals['wgLanguageCode'] );
+ }
+
+ $this->addNamespaceSettings();
}
/**
+ * Returns canonical names
+ *
+ * @see Hooks:CanonicalNamespaces
+ *
* @since 1.9
+ *
+ * @return array
*/
- protected function initNamespaces() {
+ public static function getCanonicalNames() {
+
+ $canonicalNames = array(
+ SMW_NS_PROPERTY => 'Property',
+ SMW_NS_PROPERTY_TALK => 'Property_talk',
+ SMW_NS_TYPE => 'Type',
+ SMW_NS_TYPE_TALK => 'Type_talk',
+ SMW_NS_CONCEPT => 'Concept',
+ SMW_NS_CONCEPT_TALK => 'Concept_talk'
+ );
- if ( !isset( $this->globals['smwgNamespaceIndex'] ) ) {
- $this->globals['smwgNamespaceIndex'] = 100;
- }
+ return $canonicalNames;
+ }
+
+ /**
+ * @since 1.9
+ *
+ * @param integer offset
+ *
+ * @return array
+ */
+ public static function buildNamespaceIndex( $offset ) {
- /**
- * 100 and 101 used to be occupied by SMW's now obsolete namespaces
- * "Relation" and "Relation_Talk"
- *
- * 106 and 107 are occupied by the Semantic Forms, we define them here
- * to offer some (easy but useful) support to SF
- */
$namespaceIndex = array(
- 'SMW_NS_PROPERTY' => $this->globals['smwgNamespaceIndex'] + 2,
- 'SMW_NS_PROPERTY_TALK' => $this->globals['smwgNamespaceIndex'] + 3,
- 'SMW_NS_TYPE' => $this->globals['smwgNamespaceIndex'] + 4,
- 'SMW_NS_TYPE_TALK' => $this->globals['smwgNamespaceIndex'] + 5,
- 'SF_NS_FORM' => $this->globals['smwgNamespaceIndex'] + 6,
- 'SF_NS_FORM_TALK' => $this->globals['smwgNamespaceIndex'] + 7,
- 'SMW_NS_CONCEPT' => $this->globals['smwgNamespaceIndex'] + 8,
- 'SMW_NS_CONCEPT_TALK' => $this->globals['smwgNamespaceIndex'] + 9,
+ 'SMW_NS_PROPERTY' => $offset + 2,
+ 'SMW_NS_PROPERTY_TALK' => $offset + 3,
+ 'SMW_NS_TYPE' => $offset + 4,
+ 'SMW_NS_TYPE_TALK' => $offset + 5,
+ 'SF_NS_FORM' => $offset + 6,
+ 'SF_NS_FORM_TALK' => $offset + 7,
+ 'SMW_NS_CONCEPT' => $offset + 8,
+ 'SMW_NS_CONCEPT_TALK' => $offset + 9,
);
- foreach ( $namespaceIndex as $ns => $index ) {
- $this->assertIsDefined( $ns, $index );
- }
+ return $namespaceIndex;
+ }
- if ( empty( $this->globals['smwgContLang'] ) ) {
- $this->initContentLanguage( $this->globals['wgLanguageCode'] );
+ /**
+ * 100 and 101 used to be occupied by SMW's now obsolete namespaces
+ * "Relation" and "Relation_Talk"
+ *
+ * 106 and 107 are occupied by the Semantic Forms, we define them here
+ * to offer some (easy but useful) support to SF
+ *
+ * @since 1.9
+ *
+ * @param array $globals
+ */
+ public static function initCustomNamespace( &$globals ) {
+
+ if ( !isset( $globals['smwgNamespaceIndex'] ) ) {
+ $globals['smwgNamespaceIndex'] = 100;
}
- // Register namespace identifiers
- if ( !is_array( $this->globals['wgExtraNamespaces'] ) ) {
- $this->globals['wgExtraNamespaces'] = array();
+ foreach ( self::buildNamespaceIndex( $globals['smwgNamespaceIndex'] ) as $ns => $index ) {
+ if ( !defined( $ns ) ) {
+ define( $ns, $index );
+ };
}
+ }
+
+ /**
+ * @since 1.9
+ */
+ protected function addNamespaceSettings() {
+
+ $this->assertIsArrayOrSetDefault( 'wgExtraNamespaces' );
+ $this->assertIsArrayOrSetDefault( 'wgNamespaceAliases' );
/**
* @var SMWLanguage $smwgContLang
@@ -112,38 +161,55 @@ protected function initNamespaces() {
}
/**
- * @since 1.9
- */
- protected function assertIsDefined( $ns, $index ) {
- return defined( $ns ) ? true : define( $ns, $index );
- }
-
- /**
* Initialise a global language object for content language. This must happen
* early on, even before user language is known, to determine labels for
* additional namespaces. In contrast, messages can be initialised much later
* when they are actually needed.
+ *
* @since 1.9
*/
protected function initContentLanguage( $langcode ) {
Profiler::In();
+ $this->setLanguage( $langcode );
+ $this->assertValidLanguageOrSetFallback( 'en' );
+
+ $this->globals['smwgContLang'] = new $this->globals['smwContLangClass'];
+
+ Profiler::Out();
+ }
+
+ /**
+ * @since 1.9
+ */
+ protected function setLanguage( $langcode ) {
+
$this->globals['smwContLangFile'] = 'SMW_Language' . str_replace( '-', '_', ucfirst( $langcode ) );
$this->globals['smwContLangClass'] = 'SMWLanguage' . str_replace( '-', '_', ucfirst( $langcode ) );
- if ( file_exists( $this->directory . '/' . 'languages/' . $this->globals['smwContLangFile'] . '.php' ) ) {
- include_once( $this->directory . '/' . 'languages/' . $this->globals['smwContLangFile'] . '.php' );
- }
+ $file = $this->directory . '/' . 'languages' . '/' . $this->globals['smwContLangFile'] . '.php';
- // Fallback if language not supported.
- if ( !class_exists( $this->globals['smwContLangClass'] ) ) {
- include_once( $this->directory . '/' . 'languages/SMW_LanguageEn.php' );
- $this->globals['smwContLangClass'] = 'SMWLanguageEn';
+ if ( file_exists( $file ) ) {
+ include_once( $file );
}
+ }
- $this->globals['smwgContLang'] = new $this->globals['smwContLangClass'];
+ /**
+ * @since 1.9
+ */
+ protected function assertIsArrayOrSetDefault( $element ) {
+ if ( !isset( $this->globals[$element] ) || !is_array( $this->globals[$element] ) ) {
+ $this->globals[$element] = array();
+ }
+ }
- Profiler::Out();
+ /**
+ * @since 1.9
+ */
+ protected function assertValidLanguageOrSetFallback( $fallbackLanguageCode ) {
+ if ( !class_exists( $this->globals['smwContLangClass'] ) ) {
+ $this->setLanguage( $fallbackLanguageCode );
+ }
}
}
View
15 includes/Setup.php
@@ -84,6 +84,7 @@ protected function init() {
if ( is_file( $this->directory . "/resources/Resources.php" ) ) {
$this->globals['wgResourceModules'] = array_merge( $this->globals['wgResourceModules'], include( $this->directory . "/resources/Resources.php" ) );
}
+
}
/**
@@ -126,6 +127,7 @@ protected function registerI18n() {
$this->globals['wgExtensionMessagesFiles']['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Messages.php';
$this->globals['wgExtensionMessagesFiles']['SemanticMediaWikiAlias'] = $smwgIP . 'languages/SMW_Aliases.php';
$this->globals['wgExtensionMessagesFiles']['SemanticMediaWikiMagic'] = $smwgIP . 'languages/SMW_Magic.php';
+ $this->globals['wgExtensionMessagesFiles']['SemanticMediaWikiNamespaces'] = $smwgIP . 'languages/SemanticMediaWiki.namespaces.php';
}
@@ -427,6 +429,19 @@ protected function registerFunctionHooks() {
return $functionHook->register( new SpecialStatsAddExtra( $extraStats, $globals['wgVersion'], $globals['wgLang'] ) )->process();
};
+ /**
+ * Hook: For extensions adding their own namespaces or altering the defaults
+ *
+ * @Bug 34383
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/CanonicalNamespaces
+ *
+ * @since 1.9
+ */
+ $this->globals['wgHooks']['CanonicalNamespaces'][] = function ( &$list ) {
+ $list = $list + NamespaceManager::getCanonicalNames();
+ return true;
+ };
+
// Old-style registration
$this->globals['wgHooks']['LoadExtensionSchemaUpdates'][] = 'SMWHooks::onSchemaUpdate';
View
66 languages/SemanticMediaWiki.namespaces.php
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * Internationalisation namespace file for SemanticMedaWiki extension
+ *
+ * @ingroup SMW
+ */
+
+$namespaceNames = array();
+
+$namespaceNames['en'] = array(
+ SMW_NS_PROPERTY => 'Property',
+ SMW_NS_PROPERTY_TALK => 'Property_talk',
+ SMW_NS_TYPE => 'Type',
+ SMW_NS_TYPE_TALK => 'Type_talk',
+ SMW_NS_CONCEPT => 'Concept',
+ SMW_NS_CONCEPT_TALK => 'Concept_talk',
+);
+
+$namespaceNames['de'] = array(
+ SMW_NS_PROPERTY => "Attribut",
+ SMW_NS_PROPERTY_TALK => "Attribut_Diskussion",
+ SMW_NS_TYPE => "Datentyp",
+ SMW_NS_TYPE_TALK => "Datentyp_Diskussion",
+ SMW_NS_CONCEPT => 'Konzept',
+ SMW_NS_CONCEPT_TALK => 'Konzept_Diskussion',
+);
+
+$namespaceNames['zh-cn'] = array(
+ SMW_NS_PROPERTY => '性质', // 'Property',
+ SMW_NS_PROPERTY_TALK => '性质讨论', // 'Property_talk',
+ SMW_NS_TYPE => '型态', // 'Type',
+ SMW_NS_TYPE_TALK => '型态讨论', // 'Type_talk'
+ SMW_NS_CONCEPT => 'Concept', // TODO: translate
+ SMW_NS_CONCEPT_TALK => 'Concept_talk' // TODO: translate
+);
+
+# Namespace aliases
+$namespaceAliases = array();
+
+$namespaceAliases['en'] = array(
+ 'Property' => SMW_NS_PROPERTY,
+ 'Property_talk' => SMW_NS_PROPERTY_TALK,
+ 'Type' => SMW_NS_TYPE,
+ 'Type_talk' => SMW_NS_TYPE_TALK,
+ 'Concept' => SMW_NS_CONCEPT,
+ 'Concept_talk' => SMW_NS_CONCEPT_TALK,
+);
+
+$namespaceAliases['de'] = array(
+ 'Attribut' => SMW_NS_PROPERTY,
+ 'Attribut_Diskussion' => SMW_NS_PROPERTY_TALK,
+ 'Datentyp' => SMW_NS_TYPE,
+ 'Datentyp_Diskussion' => SMW_NS_TYPE_TALK,
+ 'Konzept' => SMW_NS_CONCEPT,
+ 'Konzept_Diskussion' => SMW_NS_CONCEPT_TALK,
+);
+
+$namespaceAliases['zh-cn'] = array(
+ '性质' => SMW_NS_PROPERTY,
+ '性质讨论' => SMW_NS_PROPERTY_TALK,
+ '型态' => SMW_NS_TYPE,
+ '型态讨论' => SMW_NS_TYPE_TALK,
+ 'Concept' => SMW_NS_CONCEPT,
+ 'Concept_talk' => SMW_NS_CONCEPT_TALK
+);
View
70 tests/phpunit/includes/NamespaceCustomizerTest.php
@@ -1,70 +0,0 @@
-<?php
-
-namespace SMW\Test;
-
-use SMW\NamespaceCustomizer;
-use SMW\ExtensionContext;
-
-/**
- * @covers \SMW\NamespaceCustomizer
- *
- * @group SMW
- * @group SMWExtension
- * @group medium
- *
- * @licence GNU GPL v2+
- * @since 1.9
- *
- * @author mwjames
- */
-class NamespaceCustomizerTest extends SemanticMediaWikiTestCase {
-
- /**
- * @return string|false
- */
- public function getClass() {
- return '\SMW\NamespaceCustomizer';
- }
-
- /**
- * @since 1.9
- *
- * @return NamespaceCustomizer
- */
- private function newInstance( &$test = array(), $context = null ) {
-
- $default = array(
- 'smwgNamespacesWithSemanticLinks' => array(),
- 'wgNamespacesWithSubpages' => array(),
- 'wgExtraNamespaces' => array(),
- 'wgNamespaceAliases' => array(),
- 'wgLanguageCode' => 'en'
- );
-
- $test = array_merge( $default, $test );
-
- return new NamespaceCustomizer( $test, '../..' );
- }
-
- /**
- * @since 1.9
- */
- public function testCanConstruct() {
- $this->assertInstanceOf( $this->getClass(), $this->newInstance() );
- }
-
- /**
- * @since 1.9
- */
- public function testExecution() {
-
- $test = array();
-
- $instance = $this->newInstance( $test );
- $instance->run();
-
- $this->assertNotEmpty( $test );
-
- }
-
-}
View
132 tests/phpunit/includes/NamespaceManagerTest.php
@@ -0,0 +1,132 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\NamespaceManager;
+
+/**
+ * @covers \SMW\NamespaceManager
+ *
+ * @group SMW
+ * @group SMWExtension
+ * @group medium
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class NamespaceManagerTest extends SemanticMediaWikiTestCase {
+
+ /**
+ * @return string|false
+ */
+ public function getClass() {
+ return '\SMW\NamespaceManager';
+ }
+
+ /**
+ * @since 1.9
+ *
+ * @return NamespaceManager
+ */
+ private function newInstance( &$test = array(), $langCode = 'en' ) {
+
+ $default = array(
+ 'smwgNamespacesWithSemanticLinks' => array(),
+ 'wgNamespacesWithSubpages' => array(),
+ 'wgExtraNamespaces' => array(),
+ 'wgNamespaceAliases' => array(),
+ 'wgLanguageCode' => $langCode
+ );
+
+ $test = array_merge( $default, $test );
+
+ $smwBasePath = __DIR__ . '../../../..';
+
+ return new NamespaceManager( $test, $smwBasePath );
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function testCanConstruct() {
+ $this->assertInstanceOf( $this->getClass(), $this->newInstance() );
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function testExecution() {
+
+ $test = array();
+
+ $this->newInstance( $test )->run();
+ $this->assertNotEmpty( $test );
+
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function testExecutionWithIncompleteConfiguration() {
+
+ $test = array(
+ 'wgExtraNamespaces' => '',
+ 'wgNamespaceAliases' => ''
+ );
+
+ $this->newInstance( $test )->run();
+ $this->assertNotEmpty( $test );
+
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function testExecutionWithLanguageFallback() {
+
+ $test = array();
+
+ $this->newInstance( $test, 'foo' )->run();
+ $this->assertNotEmpty( $test );
+
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function testGetCanonicalNames() {
+
+ $result = NamespaceManager::getCanonicalNames();
+
+ $this->assertInternalType( 'array', $result );
+ $this->assertCount( 6, $result );
+
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function testBuildNamespaceIndex() {
+ $this->assertInternalType( 'array', NamespaceManager::buildNamespaceIndex( 100 ) );
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function testInitCustomNamespace() {
+
+ $test = array();
+ NamespaceManager::initCustomNamespace( $test );
+
+ $this->assertNotEmpty( $test );
+ $this->assertEquals(
+ 100,
+ $test['smwgNamespaceIndex'],
+ 'Asserts that smwgNamespaceIndex is being set to a default index'
+ );
+
+ }
+
+}
View
228 tests/phpunit/includes/SetupTest.php
@@ -48,24 +48,26 @@ private function newExtensionContext( $store = null ) {
*
* @return Setup
*/
- private function newInstance( &$test = array(), $context = null ) {
-
- $default = array(
- 'wgExtensionAssetsPath' => false,
- 'wgResourceModules' => array(),
- 'wgScriptPath' => '/Foo',
- 'wgServer' => 'http://example.org',
- 'wgVersion' => '1.21',
- 'wgLang' => $this->newMockBuilder()->newObject( 'Language' )
+ private function newInstance( &$config = array(), $basePath = 'Foo' ) {
+
+ $language = $this->newMockBuilder()->newObject( 'Language' );
+
+ $default = array(
+ 'smwgNamespacesWithSemanticLinks' => array(),
+ 'wgNamespacesWithSubpages' => array(),
+ 'wgExtensionAssetsPath' => false,
+ 'wgResourceModules' => array(),
+ 'wgScriptPath' => '/Foo',
+ 'wgServer' => 'http://example.org',
+ 'wgVersion' => '1.21',
+ 'wgLanguageCode' => 'en',
+ 'wgLang' => $language
);
- $test = array_merge( $default, $test );
+ $config = array_merge( $default, $config );
+ $context = $this->newExtensionContext();
- if ( $context === null ) {
- $context = $this->newExtensionContext();
- }
-
- return new Setup( $test, 'Foo', $context );
+ return new Setup( $config, $basePath, $context );
}
/**
@@ -76,23 +78,41 @@ public function testConstructor() {
}
/**
+ * @since 1.9
+ */
+ public function testResourceModules() {
+
+ $test = array();
+ $smwBasePath = __DIR__ . '../../../..';
+
+ $this->newInstance( $test, $smwBasePath )->run();
+
+ // The path creates some issues during Travis run therefore we
+ // cheat a bit
+ if ( realpath( $smwBasePath ) ) {
+ $this->assertNotEmpty( $test['wgResourceModules'] );
+ }
+
+ $this->assertTrue( true );
+ }
+
+ /**
* @dataProvider functionHooksProvider
*
* @since 1.9
*/
- public function testRegisterFunctionHooksWithoutExecution( $hook, $setup ) {
- $this->assertHook( $hook, $setup, 1 );
-
+ public function testRegisterFunctionHooksWithoutInitialization( $hook, $setup ) {
+ $this->assertArrayHookEntry( $hook, $setup, 1 );
}
/**
- * @dataProvider functionHookForExecutionProvider
+ * @dataProvider functionHookForInitializationProvider
*
* @since 1.9
*/
- public function testRegisterFunctionHookWithExecution( $hook, $setup ) {
+ public function testRegisterFunctionHookWithInitialization( $hook, $setup ) {
- $this->assertHook( $hook, $setup, 1 );
+ $this->assertArrayHookEntry( $hook, $setup, 1 );
// Verify that registered closures are executable
$result = $this->executeHookOnMock( $hook, $setup['wgHooks'][$hook][0] );
@@ -106,16 +126,16 @@ public function testRegisterFunctionHookWithExecution( $hook, $setup ) {
}
/**
- * @dataProvider parserHooksProvider
+ * @dataProvider parserHooksForInitializationProvider
*
* @since 1.9
*/
- public function testParserHooksWithExecution( $hook, $setup ) {
+ public function testParserHooksWithInitialization( $hook, $setup ) {
// 4 because of having hooks registered without using a callback, after
// all parser hooks being registered using a callback this can be
// reduced to 1
- $this->assertHook( $hook, $setup, 4 );
+ $this->assertArrayHookEntry( $hook, $setup, 4 );
// Verify that registered closures are executable
$result = $this->executeHookOnMock( $hook, $setup['wgHooks'][$hook][0] );
@@ -129,29 +149,6 @@ public function testParserHooksWithExecution( $hook, $setup ) {
}
/**
- * @since 1.9
- */
- private function assertHook( $hook, &$setup, $count ) {
-
- $instance = $this->newInstance( $setup );
-
- $this->assertCount(
- 0,
- $setup['wgHooks'][$hook],
- 'Asserts that before run() the entry counts 0'
- );
-
- $instance->run();
-
- $this->assertCount(
- $count,
- $setup['wgHooks'][$hook],
- "Asserts that after run() the entry counts {$count}"
- );
-
- }
-
- /**
* Verifies that a registered closure can be executed
*
* @since 1.9
@@ -238,6 +235,9 @@ private function executeHookOnMock( $hook, $object ) {
case 'TitleMoveComplete':
$result = $this->callObject( $object, array( &$title, &$title, &$user, $empty, $empty ) );
break;
+ case 'CanonicalNamespaces':
+ $result = $this->callObject( $object, array( &$emptyArray ) );
+ break;
case 'ArticlePurge':
$result = $this->callObject( $object, array( &$wikiPage ) );
break;
@@ -276,16 +276,8 @@ private function callObject( $object, array $arguments ) {
*
* @since 1.9
*/
- public function testRegisterApiModules( $module, $setup ) {
-
- $instance = $this->newInstance( $setup );
- $this->assertEmpty( $setup['wgAPIModules'][$module] );
-
- $instance->run();
-
- $this->assertNotEmpty( $setup['wgAPIModules'][$module] );
- $this->assertTrue( class_exists( $setup['wgAPIModules'][$module] ) );
-
+ public function testRegisterApiModules( $moduleEntry, $setup ) {
+ $this->assertArrayEntryExists( 'wgAPIModules', $moduleEntry, $setup );
}
/**
@@ -293,16 +285,8 @@ public function testRegisterApiModules( $module, $setup ) {
*
* @since 1.9
*/
- public function testRegisterJobClasses( $job, $setup ) {
-
- $instance = $this->newInstance( $setup );
- $this->assertEmpty( $setup['wgJobClasses'][$job] );
-
- $instance->run();
-
- $this->assertNotEmpty( $setup['wgJobClasses'][$job] );
- $this->assertTrue( class_exists( $setup['wgJobClasses'][$job] ) );
-
+ public function testRegisterJobClasses( $jobEntry, $setup ) {
+ $this->assertArrayEntryExists( 'wgJobClasses', $jobEntry, $setup );
}
/**
@@ -310,16 +294,17 @@ public function testRegisterJobClasses( $job, $setup ) {
*
* @since 1.9
*/
- public function testRegisterMessageFiles( $modules, $setup ) {
-
- $instance = $this->newInstance( $setup );
- $this->assertEmpty( $setup['wgExtensionMessagesFiles'][$modules] );
-
- $instance->run();
-
- $this->assertNotEmpty( $setup['wgExtensionMessagesFiles'][$modules] );
- $this->assertTrue( file_exists( $setup['wgExtensionMessagesFiles'][$modules] ) );
+ public function testRegisterMessageFiles( $moduleEntry, $setup ) {
+ $this->assertArrayEntryExists( 'wgExtensionMessagesFiles', $moduleEntry, $setup, 'file' );
+ }
+ /**
+ * @dataProvider specialPageDataProvider
+ *
+ * @since 1.9
+ */
+ public function testRegisterSpecialPages( $specialEntry, $setup ) {
+ $this->assertArrayEntryExists( 'wgSpecialPages', $specialEntry, $setup );
}
/**
@@ -331,16 +316,14 @@ public function testRegisterRights() {
$setup['wgGroupPermissions']['sysop']['smw-admin'] = '';
$setup['wgGroupPermissions']['smwadministrator']['smw-admin'] = '';
- $instance = $this->newInstance( $setup );
-
- foreach ( $setup['wgAvailableRights'] as $value) {
+ foreach ( $setup['wgAvailableRights'] as $value ) {
$this->assertEmpty( $value );
}
$this->assertEmpty( $setup['wgGroupPermissions']['sysop']['smw-admin'] );
$this->assertEmpty( $setup['wgGroupPermissions']['smwadministrator']['smw-admin'] );
- $instance->run();
+ $this->newInstance( $setup )->run();
$this->assertNotEmpty( $setup['wgAvailableRights'] );
$this->assertNotEmpty( $setup['wgGroupPermissions']['sysop']['smw-admin'] );
@@ -356,12 +339,10 @@ public function testRegisterParamDefinitions() {
$setup['wgParamDefinitions']['smwformat'] = '';
$setup['wgParamDefinitions']['smwsource'] = '';
- $instance = $this->newInstance( $setup );
-
$this->assertEmpty( $setup['wgParamDefinitions']['smwformat'] );
$this->assertEmpty( $setup['wgParamDefinitions']['smwsource'] );
- $instance->run();
+ $this->newInstance( $setup )->run();
$this->assertNotEmpty( $setup['wgParamDefinitions']['smwformat'] );
$this->assertNotEmpty( $setup['wgParamDefinitions']['smwsource'] );
@@ -375,34 +356,12 @@ public function testRegisterFooterIcon() {
$setup['wgFooterIcons']['poweredby']['semanticmediawiki'] = '';
- $instance = $this->newInstance( $setup );
-
- $this->assertEmpty( $setup['wgFooterIcons']['poweredby']['semanticmediawiki'] );
-
- $instance->run();
-
+ $this->newInstance( $setup )->run();
$this->assertNotEmpty( $setup['wgFooterIcons']['poweredby']['semanticmediawiki'] );
}
/**
- * @dataProvider specialPageDataProvider
- *
- * @since 1.9
- */
- public function testRegisterSpecialPages( $special, $setup ) {
-
- $instance = $this->newInstance( $setup );
- $this->assertEmpty( $setup['wgSpecialPages'][$special] );
-
- $instance->run();
-
- $this->assertNotEmpty( $setup['wgSpecialPages'][$special] );
- $this->assertTrue( class_exists( $setup['wgSpecialPages'][$special] ) );
-
- }
-
- /**
* @return array
*/
public function specialPageDataProvider() {
@@ -465,6 +424,7 @@ public function messagesFilesDataProvider() {
'SemanticMediaWiki',
'SemanticMediaWikiAlias',
'SemanticMediaWikiMagic',
+ 'SemanticMediaWikiNamespaces'
);
return $this->buildDataProvider( 'wgExtensionMessagesFiles', $modules, '' );
@@ -497,7 +457,7 @@ public function functionHooksProvider() {
/**
* @return array
*/
- public function functionHookForExecutionProvider() {
+ public function functionHookForInitializationProvider() {
$hooks = array(
'SkinAfterContent',
@@ -511,7 +471,8 @@ public function functionHookForExecutionProvider() {
'ParserAfterTidy',
'LinksUpdateConstructed',
'SpecialStatsAddExtra',
- 'BaseTemplateToolbox'
+ 'BaseTemplateToolbox',
+ 'CanonicalNamespaces'
);
return $this->buildDataProvider( 'wgHooks', $hooks, array() );
@@ -520,7 +481,7 @@ public function functionHookForExecutionProvider() {
/**
* @return array
*/
- public function parserHooksProvider() {
+ public function parserHooksForInitializationProvider() {
$hooks = array(
'ParserFirstCallInit'
@@ -530,9 +491,55 @@ public function parserHooksProvider() {
}
/**
+ * @since 1.9
+ */
+ private function assertArrayHookEntry( $hook, &$setup, $expectedCount ) {
+
+ $this->assertCount(
+ 0,
+ $setup['wgHooks'][$hook],
+ 'Asserts that before run() the entry counts 0'
+ );
+
+ $this->newInstance( $setup )->run();
+
+ $this->assertCount(
+ $expectedCount,
+ $setup['wgHooks'][$hook],
+ "Asserts that after run() the entry counts {$expectedCount}"
+ );
+
+ }
+
+ /**
+ * @since 1.9
+ */
+ private function assertArrayEntryExists( $target, $entry, $setup, $type = 'class' ) {
+
+ $this->assertEmpty(
+ $setup[$target][$entry],
+ "Asserts that {$entry} is empty"
+ );
+
+ $this->newInstance( $setup )->run();
+
+ $this->assertNotEmpty( $setup[$target][$entry] );
+
+ switch ( $type ) {
+ case 'class':
+ $this->assertTrue( class_exists( $setup[$target][$entry] ) );
+ break;
+ case 'file':
+ $this->assertTrue( file_exists( $setup[$target][$entry] ) );
+ break;
+ }
+
+ }
+
+ /**
* @return array
*/
- public function buildDataProvider( $id, $definitions, $default ) {
+ private function buildDataProvider( $id, $definitions, $default ) {
$provider = array();
@@ -566,4 +573,5 @@ public function newMockContent() {
return $content;
}
+
}
View
55 tests/phpunit/integration/MediaWikiNamespaceIntegrationTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\NamespaceManager;
+use SMW\Settings;
+use MWNamespace;
+
+/**
+ * @covers \SMW\NamespaceManager
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class MediaWikiNamespaceIntegrationTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @since 1.9
+ */
+ public function testCanonicalNames() {
+
+ $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 ) {
+ $this->assertEquals( $mwNamespace, $names[$idx] );
+ $count++;
+ }
+
+ }
+
+ $this->assertCount(
+ $count,
+ $names,
+ "Asserts that expected amount of cannonical names have been verified"
+ );
+
+ }
+
+}
Something went wrong with that request. Please try again.