Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/191789

Change subject: Revert "Revert "Make tests work when $wgLanguageCode != 'en'""
......................................................................

Revert "Revert "Make tests work when $wgLanguageCode != 'en'""

Should be good to apply now after Wikibase has been adopted to
this.

Bug: T69483
This reverts commit 06f03fe09b53bf24b3af4e172c6d14380bedd033.

Change-Id: I28073a891b8847fc6aa5ad026bf702e4015f7d4a
---
M engines/LuaCommon/SiteLibrary.php
M tests/engines/LuaCommon/LuaEngineTestBase.php
M tests/engines/LuaCommon/LuaInterpreterTest.php
M tests/engines/LuaStandalone/LuaStandaloneInterpreterTest.php
4 files changed, 20 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto 
refs/changes/89/191789/1

diff --git a/engines/LuaCommon/SiteLibrary.php 
b/engines/LuaCommon/SiteLibrary.php
index b43dd90..c14bb22 100644
--- a/engines/LuaCommon/SiteLibrary.php
+++ b/engines/LuaCommon/SiteLibrary.php
@@ -1,6 +1,7 @@
 <?php
 
 class Scribunto_LuaSiteLibrary extends Scribunto_LuaLibraryBase {
+       private static $namespacesCacheLang = null;
        private static $namespacesCache = null;
        private static $interwikiMapCache = array();
        private $pagesInCategoryCache = array();
@@ -23,7 +24,7 @@
                        'currentVersion' => SpecialVersion::getVersion(),
                );
 
-               if ( !self::$namespacesCache ) {
+               if ( !self::$namespacesCache || self::$namespacesCacheLang !== 
$wgContLang->getCode() ) {
                        $namespaces = array();
                        $namespacesByName = array();
                        foreach ( $wgContLang->getFormattedNamespaces() as $ns 
=> $title ) {
@@ -68,6 +69,7 @@
                        $namespaces[NS_MAIN]['displayName'] = wfMessage( 
'blanknamespace' )->inContentLanguage()->text();
 
                        self::$namespacesCache = $namespaces;
+                       self::$namespacesCacheLang = $wgContLang->getCode();
                }
                $info['namespaces'] = self::$namespacesCache;
 
diff --git a/tests/engines/LuaCommon/LuaEngineTestBase.php 
b/tests/engines/LuaCommon/LuaEngineTestBase.php
index 4454b57..4d7817c 100644
--- a/tests/engines/LuaCommon/LuaEngineTestBase.php
+++ b/tests/engines/LuaCommon/LuaEngineTestBase.php
@@ -9,7 +9,7 @@
  * - getTestModules(): Add a mapping from $moduleName to the file containing
  *   the code.
  */
-abstract class Scribunto_LuaEngineTestBase extends MediaWikiTestCase {
+abstract class Scribunto_LuaEngineTestBase extends MediaWikiLangTestCase {
        private static $engineConfigurations = array(
                'LuaSandbox' => array(
                        'memoryLimit' => 50000000,
diff --git a/tests/engines/LuaCommon/LuaInterpreterTest.php 
b/tests/engines/LuaCommon/LuaInterpreterTest.php
index 57ea5b6..7b4bf20 100644
--- a/tests/engines/LuaCommon/LuaInterpreterTest.php
+++ b/tests/engines/LuaCommon/LuaInterpreterTest.php
@@ -111,10 +111,6 @@
                );
        }
 
-       /**
-        * @expectedException ScribuntoException
-        * @expectedExceptionMessage The time allocated for running scripts has 
expired.
-        */
        public function testTimeLimit() {
                if( php_uname( 's' ) === 'Darwin' ) {
                        $this->markTestSkipped( "Darwin is lacking POSIX timer, 
skipping CPU time limiting test." );
@@ -122,13 +118,14 @@
 
                $interpreter = $this->newInterpreter( array( 'cpuLimit' => 1 ) 
);
                $chunk = $this->getBusyLoop( $interpreter );
-               $interpreter->callFunction( $chunk, 1e9 );
+               try {
+                       $interpreter->callFunction( $chunk, 1e9 );
+                       $this->fail( "Expected ScribuntoException was not 
thrown" );
+               } catch ( ScribuntoException $ex ) {
+                       $this->assertSame( 'scribunto-common-timeout', 
$ex->messageName );
+               }
        }
 
-       /**
-        * @expectedException ScribuntoException
-        * @expectedExceptionMessage Lua error: not enough memory
-        */
        public function testTestMemoryLimit() {
                $interpreter = $this->newInterpreter( array( 'memoryLimit' => 
20 * 1e6 ) );
                $chunk = $interpreter->loadString( '
@@ -138,7 +135,13 @@
                        end
                        ',
                        'memoryLimit' );
-               $interpreter->callFunction( $chunk );
+               try {
+                       $interpreter->callFunction( $chunk );
+                       $this->fail( "Expected ScribuntoException was not 
thrown" );
+               } catch ( ScribuntoException $ex ) {
+                       $this->assertSame( 'scribunto-lua-error', 
$ex->messageName );
+                       $this->assertSame( 'not enough memory', 
$ex->messageArgs[1] );
+               }
        }
 
        public function testWrapPHPFunction() {
diff --git a/tests/engines/LuaStandalone/LuaStandaloneInterpreterTest.php 
b/tests/engines/LuaStandalone/LuaStandaloneInterpreterTest.php
index a10af30..76231c5 100644
--- a/tests/engines/LuaStandalone/LuaStandaloneInterpreterTest.php
+++ b/tests/engines/LuaStandalone/LuaStandaloneInterpreterTest.php
@@ -73,7 +73,7 @@
                        $this->fail( "Expected exception because function #1 
should have been freed" );
                } catch ( Scribunto_LuaError $e ) {
                        $this->assertEquals(
-                               "Lua error: function id $id does not exist.", 
$e->getMessage(),
+                               "function id $id does not exist", 
$e->messageArgs[1],
                                'Testing for expected error when calling a 
freed function #1'
                        );
                }
@@ -98,7 +98,7 @@
                        $this->fail( "Expected exception because function #2 
should have been freed" );
                } catch ( Scribunto_LuaError $e ) {
                        $this->assertEquals(
-                               "Lua error: function id $id does not exist.", 
$e->getMessage(),
+                               "function id $id does not exist", 
$e->messageArgs[1],
                                'Testing for expected error when calling a 
freed function #2'
                        );
                }
@@ -123,7 +123,7 @@
                        $this->fail( "Expected exception because function #3 
should have been freed" );
                } catch ( Scribunto_LuaError $e ) {
                        $this->assertEquals(
-                               "Lua error: function id $id does not exist.", 
$e->getMessage(),
+                               "function id $id does not exist", 
$e->messageArgs[1],
                                'Testing for expected error when calling a 
freed function #3'
                        );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/191789
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I28073a891b8847fc6aa5ad026bf702e4015f7d4a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to