r110118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110117‎ | r110118 | r110119 >
Date:13:00, 27 January 2012
Author:demon
Status:ok
Tags:
Comment:
Fixup r109698, add setter for $namespaceNames and use proper accessors in the tests.

Since we're here: nothing uses $namespaceNames, $mNamespaceIds or $namespaceAliases
outside of this class (core or extensions) so lets make it protected.
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/HtmlTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/XmlTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/XmlTest.php
@@ -13,8 +13,8 @@
1414 // Hardcode namespaces during test runs,
1515 // so that html output based on existing namespaces
1616 // can be properly evaluated.
17 - self::$oldNamespaces = $wgContLang->namespaceNames;
18 - $wgContLang->namespaceNames = array(
 17+ self::$oldNamespaces = $wgContLang->getNamespaces();
 18+ $wgContLang->setNamespaces( array(
1919 -2 => 'Media',
2020 -1 => 'Special',
2121 0 => '',
@@ -31,13 +31,14 @@
3232 11 => 'Template_talk',
3333 100 => 'Custom',
3434 101 => 'Custom_talk',
35 - );
 35+ ) );
3636 }
3737
3838 public function tearDown() {
3939 global $wgLang, $wgContLang;
4040 $wgLang = self::$oldLang;
41 - $wgContLang->namespaceNames = self::$oldNamespaces;
 41+
 42+ $wgContLang->setNamespaces( self::$oldNamespaces );
4243 }
4344
4445 public function testExpandAttributes() {
Index: trunk/phase3/tests/phpunit/includes/HtmlTest.php
@@ -12,7 +12,7 @@
1313
1414 self::$oldLang = $wgLang;
1515 self::$oldContLang = $wgContLang;
16 - self::$oldNamespaces = $wgContLang->namespaceNames;
 16+ self::$oldNamespaces = $wgContLang->getNamespaces();
1717 self::$oldLanguageCode = $wgLanguageCode;
1818
1919 $wgLanguageCode = 'en';
@@ -21,7 +21,7 @@
2222 // Hardcode namespaces during test runs,
2323 // so that html output based on existing namespaces
2424 // can be properly evaluated.
25 - $wgContLang->namespaceNames = array(
 25+ $wgContLang->setNamespaces( array(
2626 -2 => 'Media',
2727 -1 => 'Special',
2828 0 => '',
@@ -38,13 +38,13 @@
3939 11 => 'Template_talk',
4040 100 => 'Custom',
4141 101 => 'Custom_talk',
42 - );
 42+ ) );
4343 }
4444
4545 public function tearDown() {
4646 global $wgLang, $wgContLang, $wgLanguageCode;
4747
48 - $wgContLang->namespaceNames = self::$oldNamespaces;
 48+ $wgContLang->setNamespaces( self::$oldNamespaces );
4949 $wgLang = self::$oldLang;
5050 $wgContLang = self::$oldContLang;
5151 $wgLanguageCode = self::$oldLanguageCode;
Index: trunk/phase3/languages/Language.php
@@ -63,11 +63,10 @@
6464 var $mMagicExtensions = array(), $mMagicHookDone = false;
6565 private $mHtmlCode = null;
6666
67 - var $mNamespaceIds, $namespaceAliases;
6867 var $dateFormatStrings = array();
6968 var $mExtendedSpecialPageAliases;
7069
71 - public $namespaceNames;
 70+ protected $namespaceNames, $mNamespaceIds, $namespaceAliases;
7271
7372 /**
7473 * ReplacementArray object caches
@@ -331,7 +330,7 @@
332331 /**
333332 * @return array
334333 */
335 - function getNamespaces() {
 334+ public function getNamespaces() {
336335 if ( is_null( $this->namespaceNames ) ) {
337336 global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces;
338337
@@ -364,6 +363,14 @@
365364 }
366365 return $this->namespaceNames;
367366 }
 367+
 368+ /**
 369+ * Arbitrarily set all of the namespace names at once. Mainly used for testing
 370+ * @param $namespaces Array of namespaces (id => name)
 371+ */
 372+ public function setNamespaces( array $namespaces ) {
 373+ $this->namespaceNames = $namespaces;
 374+ }
368375
369376 /**
370377 * A convenience function that returns the same thing as

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109698[Unit testing] Add unit tests for Xml::namespaceSelector...krinkle22:26, 21 January 2012
r109994Fix broken unit test...krinkle03:45, 25 January 2012

Status & tagging log