From 4790826b970ff8c369d553e29cd20f40680dc1d8 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sat, 21 Jan 2012 22:26:14 +0000 Subject: [PATCH] [Unit testing] Add unit tests for Xml::namespaceSelector * Making Language::namespaceNames explicitly public. It already was but since is being used as such outside the class --- languages/Language.php | 4 +- tests/phpunit/includes/XmlTest.php | 74 ++++++++++++++++++- .../mediawiki/mediawiki.util.test.js | 14 ++-- 3 files changed, 82 insertions(+), 10 deletions(-) diff --git a/languages/Language.php b/languages/Language.php index 7fcce65e2a..7b08891de7 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -63,10 +63,12 @@ class Language { var $mMagicExtensions = array(), $mMagicHookDone = false; private $mHtmlCode = null; - var $mNamespaceIds, $namespaceNames, $namespaceAliases; + var $mNamespaceIds, $namespaceAliases; var $dateFormatStrings = array(); var $mExtendedSpecialPageAliases; + public $namespaceNames; + /** * ReplacementArray object caches */ diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index f722dfc54a..ce1724d248 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -2,17 +2,42 @@ class XmlTest extends MediaWikiTestCase { private static $oldLang; + private static $oldNamespaces; public function setUp() { - global $wgLang; + global $wgLang, $wgContLang; self::$oldLang = $wgLang; $wgLang = Language::factory( 'en' ); + + // Hardcode namespaces during test runs, + // so that html output based on existing namespaces + // can be properly evaluated. + self::$oldNamespaces = $wgContLang->namespaceNames; + $wgContLang->namespaceNames = array( + -2 => 'Media', + -1 => 'Special', + 0 => '', + 1 => 'Talk', + 2 => 'User', + 3 => 'User_talk', + 4 => 'MyWiki', + 5 => 'MyWiki_Talk', + 6 => 'File', + 7 => 'File_talk', + 8 => 'MediaWiki', + 9 => 'MediaWiki_talk', + 10 => 'Template', + 11 => 'Template_talk', + 100 => 'Custom', + 101 => 'Custom_talk', + ); } public function tearDown() { - global $wgLang; + global $wgLang, $wgContLang; $wgLang = self::$oldLang; + $wgContLang->namespaceNames = self::$oldNamespaces; } public function testExpandAttributes() { @@ -167,6 +192,51 @@ class XmlTest extends MediaWikiTestCase { ); } + function testNamespaceSelector() { + $this->assertEquals( + '', + Xml::namespaceSelector(), + 'Basic namespace selector without custom options' + ); + $this->assertEquals( + ' ', + Xml::namespaceSelector( $selected = '2', $all = 'all', $element_name = 'myname', $label = 'Select a namespace:' ), + 'Basic namespace selector with custom values' + ); + } + + # # textarea # diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index 445f82cb86..c60a3ef2c1 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -108,18 +108,18 @@ test( 'toggleToc', function() { test( 'getParamValue', function() { expect(5); - var url1 = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad'; + var url1 = 'http://example.org/?foo=wrong&foo=right#&foo=bad'; equal( mw.util.getParamValue( 'foo', url1 ), 'right', 'Use latest one, ignore hash' ); strictEqual( mw.util.getParamValue( 'bar', url1 ), null, 'Return null when not found' ); - var url2 = 'http://mediawiki.org/#&foo=bad'; + var url2 = 'http://example.org/#&foo=bad'; strictEqual( mw.util.getParamValue( 'foo', url2 ), null, 'Ignore hash if param is not in querystring but in hash (bug 27427)' ); - var url3 = 'example.com?' + $.param({ 'TEST': 'a b+c' }); + var url3 = 'example.org?' + $.param({ 'TEST': 'a b+c' }); strictEqual( mw.util.getParamValue( 'TEST', url3 ), 'a b+c', 'Bug 30441: getParamValue must understand "+" encoding of space' ); - var url4 = 'example.com?' + $.param({ 'TEST': 'a b+c d' }); // check for sloppy code from r95332 :) + var url4 = 'example.org?' + $.param({ 'TEST': 'a b+c d' }); // check for sloppy code from r95332 :) strictEqual( mw.util.getParamValue( 'TEST', url4 ), 'a b+c d', 'Bug 30441: getParamValue must understand "+" encoding of space (multiple spaces)' ); }); @@ -161,12 +161,12 @@ test( 'addPortletLink', function() { $mwPanel = $(mwPanel).appendTo( 'body' ), $vectorTabs = $(vectorTabs).appendTo( 'body' ); - var tbRL = mw.util.addPortletLink( 'p-test-tb', 'http://mediawiki.org/wiki/ResourceLoader', + var tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader', 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' ); ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' ); - var tbMW = mw.util.addPortletLink( 'p-test-tb', 'http://mediawiki.org/', + var tbMW = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/', 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL ), $tbMW = $( tbMW ); @@ -175,7 +175,7 @@ test( 'addPortletLink', function() { equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' ); equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' ); - var tbRLDM = mw.util.addPortletLink( 'p-test-tb', 'http://mediawiki.org/wiki/RL/DM', + var tbRLDM = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM', 'Default modules', 't-rldm', 'List of all default modules ', 'd', '#t-rl' ); equal( $( tbRLDM ).next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing CSS selector)' ); -- 2.20.1