Foxtrott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277111
Change subject: Rework and testing of Backends; move hooks back to php
......................................................................
Rework and testing of Backends; move hooks back to php
* rework BasicBackend
* minor rework Backend
* minor rework LingoParser
* generally replace static methods
* improve testing of Backends
* put hook registration back into php
* no registration of hooks when not necessary (e.g. BasicBackend not used)
* introduce class Lingo for extension initialisation
Change-Id: I69c84dd442a448c4a7d56a878d6a3e29ddda5f05
---
M extension.json
M src/Backend.php
M src/BasicBackend.php
M src/Hooks.php
A src/Lingo.php
M src/LingoParser.php
M src/Tree.php
M tests/phpunit/Integration/ArticleAnnotationTest.php
M tests/phpunit/Unit/BackendTest.php
M tests/phpunit/Unit/BasicBackendTest.php
10 files changed, 337 insertions(+), 161 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Lingo
refs/changes/11/277111/1
diff --git a/extension.json b/extension.json
index 99b1e47..3b5923b 100644
--- a/extension.json
+++ b/extension.json
@@ -60,6 +60,7 @@
"LingoMagic": "src/Lingo.i18n.magic.php"
},
"AutoloadClasses": {
+ "Lingo\\Lingo": "/src/Lingo.php",
"Lingo\\Hooks": "/src/Hooks.php",
"Lingo\\LingoParser": "/src/LingoParser.php",
"Lingo\\Tree": "/src/Tree.php",
@@ -69,22 +70,6 @@
"Lingo\\MessageLog": "/src/MessageLog.php",
"Lingo\\Tests\\Util\\XmlFileProvider":
"/tests/phpunit/Util/XmlFileProvider.php"
},
- "Hooks": {
- "ParserFirstCallInit": [
- "Lingo\\Hooks::registerTags"
- ],
- "ArticlePurge": [
- "Lingo\\BasicBackend::purgeCache"
- ],
- "ArticleSave": [
- "Lingo\\BasicBackend::purgeCache"
- ],
- "ParserAfterParse": [
- "Lingo\\Hooks::parse"
- ]
- },
- "ExtensionFunctions": [
- "Lingo\\Hooks::initExtension"
- ],
+ "callback": "Lingo\\Lingo::initExtension",
"manifest_version": 1
}
diff --git a/src/Backend.php b/src/Backend.php
index e2ece01..d49851c 100644
--- a/src/Backend.php
+++ b/src/Backend.php
@@ -36,6 +36,7 @@
abstract class Backend {
protected $mMessageLog;
+ protected $mLingoParser;
/**
* Lingo\Backend constructor.
@@ -43,21 +44,41 @@
*/
public function __construct( MessageLog &$messages = null ) {
- if ( !$messages ) {
- $this->mMessageLog = new MessageLog();
- } else {
- $this->mMessageLog = $messages;
- }
+ $this->mMessageLog = $messages;
}
/**
* @return MessageLog
*/
public function getMessageLog() {
+
+ if ( !$this->mMessageLog ) {
+ $this->mMessageLog = new MessageLog();
+ }
+
return $this->mMessageLog;
}
/**
+ * @return LingoParser
+ */
+ public function getLingoParser() {
+
+ if ( !$this->mLingoParser ) {
+ $this->mLingoParser = LingoParser::getInstance();
+ }
+
+ return $this->mLingoParser;
+ }
+
+ /**
+ * @param LingoParser $mLingoParser
+ */
+ public function setLingoParser( LingoParser $mLingoParser ) {
+ $this->mLingoParser = $mLingoParser;
+ }
+
+ /**
* This function returns true if the backend is cache-enabled.
*
* Actual caching is done by the parser, but to be cache-enabled the
backend
diff --git a/src/BasicBackend.php b/src/BasicBackend.php
index d7fa827..9ea5343 100644
--- a/src/BasicBackend.php
+++ b/src/BasicBackend.php
@@ -29,12 +29,14 @@
use ApprovedRevs;
use ContentHandler;
+use Hooks;
use Page;
use Parser;
use ParserOptions;
use Revision;
use Title;
use User;
+use WikiPage;
/**
* The Lingo\BasicBackend class.
@@ -48,59 +50,26 @@
/**
* Lingo\BasicBackend constructor.
* @param MessageLog|null $messages
+ * @param LingoParser $lingoParser
*/
public function __construct( MessageLog &$messages = null ) {
- global $wgRequest;
-
- $page = self::getLingoPage();
-
parent::__construct( $messages );
- // Get Terminology page
- $title = Title::newFromText( $page );
- if ( $title->getInterwiki() ) {
- $this->getMessageLog()->addError( wfMessage(
'lingo-terminologypagenotlocal', $page )->inContentLanguage()->text() );
- return;
- }
+ $this->registerHooks();
- // This is a hack special-casing the submitting of the
terminology
- // page itself. In this case the Revision is not up to date
when we get
- // here, i.e. $rev->getText() would return outdated Text.
- // This hack takes the text directly out of the data from the
web request.
- if ( $wgRequest->getVal( 'action', 'view' ) === 'submit'
- && Title::newFromText( $wgRequest->getVal( 'title' )
)->getArticleID() === $title->getArticleID()
- ) {
+ }
- $content = $wgRequest->getVal( 'wpTextbox1' );
-
- } else {
- $rev = $this->getRevision( $title );
- if ( !$rev ) {
- $this->getMessageLog()->addWarning( wfMessage(
'lingo-noterminologypage', $page )->inContentLanguage()->text() );
- return;
- }
-
- $content = ContentHandler::getContentText(
$rev->getContent() );
-
- }
-
- $parser = new Parser;
- // expand templates and variables in the text, producing valid,
static
- // wikitext have to use a new anonymous user to avoid any
leakage as
- // Lingo is caching only one user-independent glossary
- $content = $parser->preprocess( $content, $title, new
ParserOptions( new User() ) );
-
- $this->mArticleLines = array_reverse( explode( "\n", $content )
);
+ protected function registerHooks() {
+ Hooks::register( 'ArticlePurge', array( $this, 'purgeCache' ) );
+ Hooks::register( 'ArticleSave', array( $this, 'purgeCache' ) );
}
/**
- * @param $wgexLingoPage
* @return string
*/
- private static function getLingoPage() {
+ private function getLingoPage() {
global $wgexLingoPage;
-
return $wgexLingoPage ? $wgexLingoPage : wfMessage(
'lingo-terminologypagename' )->inContentLanguage()->text();
}
@@ -117,6 +86,8 @@
static $term = null;
static $definitions = array();
static $ret = array();
+
+ $this->setArticleLines();
// find next valid line (yes, the assignation is intended)
while ( ( count( $ret ) == 0 ) && ( $entry = each(
$this->mArticleLines ) ) ) {
@@ -184,16 +155,16 @@
/**
* Initiates the purging of the cache when the Terminology page was
saved or purged.
*
- * @param Page $wikipage
+ * @param WikiPage $wikipage
* @return Bool
*/
- public static function purgeCache( &$wikipage ) {
+ public function purgeCache( WikiPage &$wikipage ) {
- $page = self::getLingoPage();
+ $page = $this->getLingoPage();
if ( !is_null( $wikipage ) && (
$wikipage->getTitle()->getText() === $page ) ) {
- LingoParser::purgeCache();
+ $this->getLingoParser()->purgeGlossaryFromCache();
}
return true;
@@ -210,4 +181,53 @@
public function useCache() {
return true;
}
+
+ /**
+ * @throws \MWException
+ */
+ private function setArticleLines() {
+ global $wgRequest;
+
+ if ( $this->mArticleLines ) {
+ return;
+ }
+
+ $page = $this->getLingoPage();
+
+ // Get Terminology page
+ $title = Title::newFromText( $page );
+ if ( $title->getInterwiki() ) {
+ $this->getMessageLog()->addError( wfMessage(
'lingo-terminologypagenotlocal', $page )->inContentLanguage()->text() );
+ return;
+ }
+
+ // This is a hack special-casing the submitting of the
terminology
+ // page itself. In this case the Revision is not up to date
when we get
+ // here, i.e. $rev->getText() would return outdated Text.
+ // This hack takes the text directly out of the data from the
web request.
+ if ( $wgRequest->getVal( 'action', 'view' ) === 'submit'
+ && Title::newFromText( $wgRequest->getVal( 'title' )
)->getArticleID() === $title->getArticleID()
+ ) {
+
+ $content = $wgRequest->getVal( 'wpTextbox1' );
+
+ } else {
+ $rev = $this->getRevision( $title );
+ if ( !$rev ) {
+ $this->getMessageLog()->addWarning( wfMessage(
'lingo-noterminologypage', $page )->inContentLanguage()->text() );
+ return;
+ }
+
+ $content = ContentHandler::getContentText(
$rev->getContent() );
+
+ }
+
+ $parser = new Parser;
+ // expand templates and variables in the text, producing valid,
static
+ // wikitext have to use a new anonymous user to avoid any
leakage as
+ // Lingo is caching only one user-independent glossary
+ $content = $parser->preprocess( $content, $title, new
ParserOptions( new User() ) );
+
+ $this->mArticleLines = array_reverse( explode( "\n", $content )
);
+ }
}
diff --git a/src/Hooks.php b/src/Hooks.php
index aa9c70a..e00f846 100644
--- a/src/Hooks.php
+++ b/src/Hooks.php
@@ -39,75 +39,5 @@
* @ingroup Lingo
*/
class Hooks {
-
- /**
- * Hooks into ParserAfterParse.
- *
- * @param Parser $parser
- * @param String $text
- * @return Boolean
- */
- public static function parse( &$parser, &$text ) {
-
- global $wgexLingoUseNamespaces;
-
- $title = $parser->getTitle();
-
- // parse if
- if ( !isset( $parser->mDoubleUnderscores[ 'noglossary' ] ) &&
// __NOGLOSSARY__ not present and
- (
- !$title || // title not set or
- !isset( $wgexLingoUseNamespaces[
$title->getNamespace() ] ) || // namespace not explicitly forbidden (i.e. not
in list of namespaces and set to false) or
- $wgexLingoUseNamespaces[ $title->getNamespace()
] // namespace explicitly allowed
- )
- ) {
-
- // unstrip strip items of the 'general' group
- // this will be done again by parse when this hook
returns, but it should not hurt to do this twice
- // Only problem is with other hook handlers that might
not expect strip items to be unstripped already
- $text = $parser->mStripState->unstripGeneral( $text );
- LingoParser::parse( $parser, $text );
- }
-
- return true;
- }
-
- /**
- * Creates tag hook(s)
- */
- public static function registerTags( Parser $parser ) {
- $parser->setHook( 'noglossary',
'Lingo\Hooks::noglossaryTagRenderer' );
- return true;
- }
-
- /**
- * Sets hook on 'noglossary' tag
- * @static
- * @param $input
- * @param array $args
- * @param Parser $parser
- * @param PPFrame $frame
- * @return string
- */
- public static function noglossaryTagRenderer( $input, array $args,
Parser $parser, PPFrame $frame ) {
- $output = $parser->recursiveTagParse( $input, $frame );
- return '<span class="noglossary">' . $output . '</span>';
- }
-
- /**
- * Deferred settings
- * - registration of _NOGLOSSARY_ magic word
- * - extension description shown on Special:Version
- */
- public static function initExtension() {
- MagicWord::$mDoubleUnderscoreIDs[] = 'noglossary';
-
- foreach ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ] as
$index => $description ) {
- if ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ][
$index ][ 'name' ] === 'Lingo' ) {
- $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook'
][ $index ][ 'description' ] =
- wfMessage( 'lingo-desc', $GLOBALS[
'wgexLingoPage' ] ? $GLOBALS[ 'wgexLingoPage' ] : wfMessage(
'lingo-terminologypagename' )->inContentLanguage()->text() )->text();
- }
- }
- }
}
diff --git a/src/Lingo.php b/src/Lingo.php
new file mode 100644
index 0000000..acd4a06
--- /dev/null
+++ b/src/Lingo.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * File containing the Lingo class
+ *
+ * This file is part of the MediaWiki extension Lingo.
+ *
+ * @copyright 2011 - 2016, Stephan Gambke
+ * @license GNU General Public License, version 2 (or any later version)
+ *
+ * The Lingo extension is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
Free
+ * Software Foundation; either version 2 of the License, or (at your option)
any
+ * later version.
+ *
+ * The Lingo extension is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @file
+ * @ingroup Lingo
+ */
+
+namespace Lingo;
+use MagicWord;
+
+/**
+ * Class Lingo
+ *
+ * @package Lingo
+ * @ingroup Skins
+ */
+class Lingo {
+
+ /**
+ * Deferred settings
+ * - registration of _NOGLOSSARY_ magic word
+ * - extension description shown on Special:Version
+ *
+ * @since 2.0.2
+ */
+ public static function initExtension() {
+
+ $GLOBALS[ 'wgExtensionFunctions' ][] = function () {
+
+ $parser = LingoParser::getInstance();
+
+ $backend = new $GLOBALS[ 'wgexLingoBackend' ]();
+
+ $parser->setBackend( $backend );
+
+ \Hooks::register( 'ParserAfterParse', array( $parser,
'parse' ) );
+
+ \Hooks::register( 'ParserFirstCallInit', function (
\Parser $parser ) {
+
+ $parser->setHook( 'noglossary', function (
$input, array $args, Parser $parser, PPFrame $frame ) {
+ $output = $parser->recursiveTagParse(
$input, $frame );
+ return '<span class="noglossary">' .
$output . '</span>';
+ } );
+
+ return true;
+ } );
+
+ MagicWord::$mDoubleUnderscoreIDs[] = 'noglossary';
+
+ foreach ( $GLOBALS[ 'wgExtensionCredits' ][
'parserhook' ] as $index => $description ) {
+
+ if ( $GLOBALS[ 'wgExtensionCredits' ][
'parserhook' ][ $index ][ 'name' ] === 'Lingo' ) {
+
+ $lingoPageName = $GLOBALS[
'wgexLingoPage' ] ? $GLOBALS[ 'wgexLingoPage' ] : wfMessage(
'lingo-terminologypagename' )->inContentLanguage()->text();
+ $GLOBALS[ 'wgExtensionCredits' ][
'parserhook' ][ $index ][ 'description' ] = wfMessage( 'lingo-desc',
$lingoPageName )->text();
+
+ break;
+ }
+
+ }
+
+// $hookRegistry = new HookRegistry(
+// ApplicationFactory::getInstance()->getStore()
+// );
+//
+// $hookRegistry->register();
+ };
+ }
+
+
+}
diff --git a/src/LingoParser.php b/src/LingoParser.php
index 8b5dc2e..6d4b5ce 100644
--- a/src/LingoParser.php
+++ b/src/LingoParser.php
@@ -51,16 +51,16 @@
private static $parserSingleton = null;
// The RegEx to split a chunk of text into words
- public static $regex = null;
+ public $regex = null;
/**
* Lingo\LingoParser constructor.
* @param MessageLog|null $messages
*/
public function __construct( MessageLog &$messages = null ) {
- global $wgexLingoBackend;
-
- $this->setBackend( new $wgexLingoBackend( $messages ) );
+ // The RegEx to split a chunk of text into words
+ // Words are: placeholders for stripped items, sequences of
letters and numbers, single characters that are neither letter nor number
+ $this->regex = '/' . preg_quote( Parser::MARKER_PREFIX, '/' ) .
'.*?' . preg_quote( Parser::MARKER_SUFFIX, '/' ) .
'|[\p{L}\p{N}]+|[^\p{L}\p{N}]/u';
}
/**
@@ -69,9 +69,28 @@
* @param string $text
* @return Boolean
*/
- public static function parse( Parser &$parser, &$text ) {
+ public function parse( Parser &$parser, &$text ) {
- self::getInstance()->realParse( $parser, $text );
+ global $wgexLingoUseNamespaces;
+
+ $title = $parser->getTitle();
+
+ // parse if
+ if ( !isset( $parser->mDoubleUnderscores[ 'noglossary' ] ) &&
// __NOGLOSSARY__ not present and
+ (
+ !$title || // title not set or
+ !isset( $wgexLingoUseNamespaces[
$title->getNamespace() ] ) || // namespace not explicitly forbidden (i.e. not
in list of namespaces and set to false) or
+ $wgexLingoUseNamespaces[ $title->getNamespace()
] // namespace explicitly allowed
+ )
+ ) {
+
+ // unstrip strip items of the 'general' group
+ // this will be done again by parse when this hook
returns, but it should not hurt to do this twice
+ // Only problem is with other hook handlers that might
not expect strip items to be unstripped already
+ $text = $parser->mStripState->unstripGeneral( $text );
+ $this->realParse( $parser, $text );
+ }
+
return true;
}
@@ -84,9 +103,6 @@
if ( !self::$parserSingleton ) {
self::$parserSingleton = new LingoParser();
- // The RegEx to split a chunk of text into words
- // Words are: placeholders for stripped items,
sequences of letters and numbers, single characters that are neither letter nor
number
- self::$regex = '/' . preg_quote( Parser::MARKER_PREFIX,
'/' ) . '.*?' . preg_quote( Parser::MARKER_SUFFIX, '/' ) .
'|[\p{L}\p{N}]+|[^\p{L}\p{N}]/u';
}
return self::$parserSingleton;
@@ -96,14 +112,19 @@
* @return string
*/
private static function getCacheKey() {
- return wfMemcKey( 'ext', 'lingo', 'lingotree',
Tree::TREE_VERSION );
+ return wfMemcKey( 'ext', 'lingo', 'lingotree',
Tree::TREE_VERSION, get_class( self::getInstance()->getBackend() ) );
}
/**
- *
* @return Backend the backend used by the parser
+ * @throws \MWException
*/
public function getBackend() {
+
+ if ( $this->mLingoBackend === null ) {
+ throw new \MWException( 'No Lingo backend available!' );
+ }
+
return $this->mLingoBackend;
}
@@ -138,7 +159,7 @@
// Try cache first
global $wgexLingoCacheType;
$cache = ( $wgexLingoCacheType !== null ) ?
wfGetCache( $wgexLingoCacheType ) : wfGetMainCache();
- $cachekey = self::getCacheKey();
+ $cachekey = $this->getCacheKey();
$cachedLingoTree = $cache->get( $cachekey );
// cache hit?
@@ -244,7 +265,7 @@
$matches = array();
preg_match_all(
- self::$regex,
+ $this->regex,
$el->nodeValue,
$matches,
PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER
@@ -342,21 +363,33 @@
/**
* Purges the lingo tree from the cache.
+ *
+ * @deprecated 2.0.2
*/
public static function purgeCache() {
+
+ self::getInstance()->purgeGlossaryFromCache();
+ }
+
+ /**
+ * Purges the lingo tree from the cache.
+ *
+ * @since 2.0.2
+ */
+ public function purgeGlossaryFromCache() {
global $wgexLingoCacheType;
$cache = ( $wgexLingoCacheType !== null ) ? wfGetCache(
$wgexLingoCacheType ) : wfGetMainCache();
$cache->delete( self::getCacheKey() );
-
}
/**
* @since 2.0.1
* @param Backend $backend
*/
- public function setBackend( $backend ) {
+ public function setBackend( Backend $backend ) {
$this->mLingoBackend = $backend;
+ $backend->setLingoParser( $this );
}
}
diff --git a/src/Tree.php b/src/Tree.php
index 4021e3c..e33f506 100644
--- a/src/Tree.php
+++ b/src/Tree.php
@@ -70,7 +70,7 @@
} else {
$matches = array();
- preg_match_all( LingoParser::$regex, $term, $matches );
+ preg_match_all( LingoParser::getInstance()->regex,
$term, $matches );
$elt = $this->addElement( $matches[ 0 ], $term,
$definition );
$this->mList[ $term ] = &$elt[ -1 ];
diff --git a/tests/phpunit/Integration/ArticleAnnotationTest.php
b/tests/phpunit/Integration/ArticleAnnotationTest.php
index 6526897..0be4f46 100644
--- a/tests/phpunit/Integration/ArticleAnnotationTest.php
+++ b/tests/phpunit/Integration/ArticleAnnotationTest.php
@@ -90,7 +90,7 @@
$lingoParser = LingoParser::getInstance();
$lingoParser->setBackend( $backend );
- LingoParser::parse( $parser, $text );
+ $lingoParser->parse( $parser, $text );
$this->assertEquals( $expected, $text );
diff --git a/tests/phpunit/Unit/BackendTest.php
b/tests/phpunit/Unit/BackendTest.php
index 04e1672..2d06d78 100644
--- a/tests/phpunit/Unit/BackendTest.php
+++ b/tests/phpunit/Unit/BackendTest.php
@@ -40,14 +40,11 @@
*/
class BackendTest extends \PHPUnit_Framework_TestCase {
- public function testUseCache() {
-
- $stub = $this->getMockForAbstractClass( '\Lingo\Backend' );
-
- $this->assertFalse( $stub->useCache() );
- }
-
- public function testGetMessageLog() {
+ /**
+ * @covers ::__construct
+ * @covers ::getMessageLog
+ */
+ public function testGetMessageLog_withLogGivenToConstructor() {
$log = $this->getMock( '\Lingo\MessageLog' );
$logRef = &$log;
@@ -63,4 +60,51 @@
$this->assertEquals( $log, $stub->getMessageLog() );
}
+ /**
+ * @covers ::__construct
+ * @covers ::getMessageLog
+ */
+ public function testGetMessageLog_withoutLogGivenToConstructor() {
+
+ $stub = $this->getMockBuilder( '\Lingo\Backend' )
+ ->disableOriginalConstructor()
+ ->getMockForAbstractClass();
+
+ $reflected = new \ReflectionClass( '\Lingo\Backend' );
+ $constructor = $reflected->getConstructor();
+ $constructor->invoke( $stub );
+
+ $this->assertInstanceOf( '\Lingo\MessageLog',
$stub->getMessageLog() );
+ }
+
+ /**
+ * @covers ::useCache
+ */
+ public function testUseCache() {
+
+ $stub = $this->getMockForAbstractClass( '\Lingo\Backend' );
+
+ $this->assertFalse( $stub->useCache() );
+ }
+
+ /**
+ * @covers ::setLingoParser
+ * @covers ::getLingoParser
+ */
+ public function testSetGetLingoParser() {
+ $stub = $this->getMockForAbstractClass( '\Lingo\Backend' );
+ $parserMock = $this->getMock( '\Lingo\LingoParser' );
+
+ $stub->setLingoParser( $parserMock );
+ $this->assertEquals( $parserMock, $stub->getLingoParser() );
+ }
+
+ /**
+ * @covers ::setLingoParser
+ * @covers ::getLingoParser
+ */
+ public function testGetLingoParser_withoutParserGiven() {
+ $stub = $this->getMockForAbstractClass( '\Lingo\Backend' );
+ $this->assertInstanceOf( '\Lingo\LingoParser',
$stub->getLingoParser() );
+ }
}
diff --git a/tests/phpunit/Unit/BasicBackendTest.php
b/tests/phpunit/Unit/BasicBackendTest.php
index 37edd18..368575e 100644
--- a/tests/phpunit/Unit/BasicBackendTest.php
+++ b/tests/phpunit/Unit/BasicBackendTest.php
@@ -26,6 +26,8 @@
namespace Lingo\Tests\Unit;
+use Lingo\BasicBackend;
+
/**
* @group extensions-lingo
* @group extensions-lingo-unit
@@ -51,4 +53,55 @@
);
}
+ /**
+ * @covers ::purgeCache
+ */
+ public function testPurgeCache() {
+
+ $GLOBALS[ 'wgexLingoPage' ] = 'SomePage';
+
+ $title = $this->getMock( 'Title' );
+
+ $wikiPage = $this->getMockBuilder( 'WikiPage')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $lingoParser = $this->getMock( 'Lingo\LingoParser');
+
+ $testObject = $this->getMockBuilder( 'Lingo\BasicBackend' )
+ ->setMethods( array( 'getLingoParser') )
+ ->getMock();
+
+
+ // Assert that the wikipage is tested against the wgexLingoPage:
+ // $wikipage->getTitle()->getText() === $page
+
+ $wikiPage->expects( $this->once() )
+ ->method( 'getTitle' )
+ ->willReturn( $title );
+
+ $title->expects( $this->once() )
+ -> method( 'getText' )
+ -> willReturn( 'SomePage' );
+
+ // Assert that purgeGlossaryFromCache is called
+ $lingoParser->expects( $this->once() )
+ ->method( 'purgeGlossaryFromCache' );
+
+
+ $testObject->expects( $this->once() )
+ -> method( 'getLingoParser' )
+ -> willReturn( $lingoParser );
+
+ $this->assertTrue( $testObject->purgeCache( $wikiPage ) );
+ }
+
+ /**
+ * @covers ::useCache
+ */
+ public function testUseCache() {
+ $backend = new BasicBackend();
+ $this->assertTrue( $backend->useCache() );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/277111
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I69c84dd442a448c4a7d56a878d6a3e29ddda5f05
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Lingo
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits