Foxtrott has submitted this change and it was merged.
Change subject: Add simple integration test
......................................................................
Add simple integration test
Change-Id: I6579622bc46f89720b29199401343b07dcfde104
---
M docs/release-notes.md
M extension.json
M src/LingoParser.php
A tests/phpunit/Fixture/articleAnnotation/simple.xml
A tests/phpunit/Integration/ArticleAnnotationTest.php
A tests/phpunit/Util/XmlFileProvider.php
6 files changed, 274 insertions(+), 8 deletions(-)
Approvals:
Foxtrott: Verified; Looks good to me, approved
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 1fe7436..cd9bf44 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -1,5 +1,12 @@
## Release Notes
+### Lingo 2.0.1
+
+Released on tbd
+
+Changes:
+* Improved test coverage
+
### Lingo 2.0.0
Released on 09-Mar-2016
@@ -27,7 +34,7 @@
* Migrate to JSON i18n
* Remove wfMsg / wfMsgForContent usage
* Unstrip strip items of 'general' category
-* Swap SpecialVersionExtensionTypes for ExtensionTypes
+* Use ExtensionFunctions instead of SpecialVersionExtensionTypes
### Lingo 1.1.0
diff --git a/extension.json b/extension.json
index c54831a..33109d2 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
{
"name": "Lingo",
- "version": "2.0.0",
+ "version": "2.0.1-dev",
"author": [
"Barry Coughlan",
"[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]",
@@ -66,7 +66,8 @@
"Lingo\\Element": "/src/Element.php",
"Lingo\\Backend": "/src/Backend.php",
"Lingo\\BasicBackend": "/src/BasicBackend.php",
- "Lingo\\MessageLog": "/src/MessageLog.php"
+ "Lingo\\MessageLog": "/src/MessageLog.php",
+ "Lingo\\Tests\\Util\\XmlFileProvider":
"/tests/phpunit/Util/XmlFileProvider.php"
},
"Hooks": {
"ParserFirstCallInit": [
diff --git a/src/LingoParser.php b/src/LingoParser.php
index 684ed34..524e4e1 100644
--- a/src/LingoParser.php
+++ b/src/LingoParser.php
@@ -60,7 +60,7 @@
public function __construct( MessageLog &$messages = null ) {
global $wgexLingoBackend;
- $this->mLingoBackend = new $wgexLingoBackend( $messages );
+ $this->setBackend( new $wgexLingoBackend( $messages ) );
}
/**
@@ -71,6 +71,16 @@
*/
public static function parse( Parser &$parser, &$text ) {
+ self::getInstance()->realParse( $parser, $text );
+
+ return true;
+ }
+
+ /**
+ * @return LingoParser
+ * @since 2.0.1
+ */
+ public static function getInstance() {
if ( !self::$parserSingleton ) {
self::$parserSingleton = new LingoParser();
@@ -79,9 +89,7 @@
self::$regex = '/' . preg_quote( Parser::MARKER_PREFIX,
'/' ) . '.*?' . preg_quote( Parser::MARKER_SUFFIX, '/' ) .
'|[\p{L}\p{N}]+|[^\p{L}\p{N}]/u';
}
- self::$parserSingleton->realParse( $parser, $text );
-
- return true;
+ return self::$parserSingleton;
}
/**
@@ -297,7 +305,7 @@
}
/**
- * @param $parser
+ * @param Parser $parser
*/
protected function loadModules( &$parser ) {
global $wgOut, $wgScriptPath;
@@ -346,5 +354,13 @@
$cache->delete( wfMemcKey( 'ext', 'lingo', 'lingotree' ) );
}
+
+ /**
+ * @since 2.0.1
+ * @param Backend $backend
+ */
+ public function setBackend( $backend ) {
+ $this->mLingoBackend = $backend;
+ }
}
diff --git a/tests/phpunit/Fixture/articleAnnotation/simple.xml
b/tests/phpunit/Fixture/articleAnnotation/simple.xml
new file mode 100644
index 0000000..d66b9a0
--- /dev/null
+++ b/tests/phpunit/Fixture/articleAnnotation/simple.xml
@@ -0,0 +1,20 @@
+<testcase>
+ <text>
+<![CDATA[
+foo
+]]>
+ </text>
+ <expected>
+<![CDATA[
+<span class="mw-lingo-tooltip "><span
class="mw-lingo-tooltip-abbr">foo</span><span class="mw-lingo-tooltip-tip
"><span class="mw-lingo-tooltip-definition ">bar</span></span></span>
+]]>
+ </expected>
+ <glossary-entry>
+ <term>foo</term>
+ <definition>bar</definition>
+ </glossary-entry>
+ <glossary-entry>
+ <term>baz</term>
+ <definition>quok</definition>
+ </glossary-entry>
+</testcase>
diff --git a/tests/phpunit/Integration/ArticleAnnotationTest.php
b/tests/phpunit/Integration/ArticleAnnotationTest.php
new file mode 100644
index 0000000..b600996
--- /dev/null
+++ b/tests/phpunit/Integration/ArticleAnnotationTest.php
@@ -0,0 +1,133 @@
+<?php
+/**
+ * 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/>.
+ *
+ * @since 2.0.1
+ * @file
+ * @ingroup Lingo
+ */
+
+namespace Lingo\Tests\Integration;
+
+use Lingo\LingoParser;
+use Lingo\Tests\Util\XmlFileProvider;
+
+use Parser;
+use ParserOptions;
+
+use PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls;
+use ReflectionClass;
+
+/**
+ * @group extensions-lingo
+ * @group extensions-lingo-integration
+ * @group mediawiki-databaseless
+ *
+ * @coversNothing
+ *
+ * @ingroup Lingo
+ * @ingroup Test
+ * @since 2.0.1
+ * @author Stephan Gambke
+ */
+class ArticleAnnotationTest extends \PHPUnit_Framework_TestCase {
+
+ public function setup() {
+ }
+
+ public function tearDown() {
+ // reset LingoParser singleton
+ $lingoParser = LingoParser::getInstance();
+ $reflection = new ReflectionClass( $lingoParser );
+ $instance = $reflection->getProperty( 'parserSingleton' );
+ $instance->setAccessible( true );
+ $instance->setValue( null, null );
+ $instance->setAccessible( false );
+ }
+
+ /**
+ * @dataProvider provideData
+ * @param $text
+ * @param $glossaryEntries
+ * @param $expected
+ */
+ public function testArticleAnnotation( $file = null, $text = '',
$glossaryEntries = null, $expected = '' ) {
+
+ $parser = new Parser();
+ $parser->startExternalParse(
+ /* Title */ null,
+ /* ParserOptions */ ParserOptions::newFromAnon(),
+ /* $outputType = */ Parser::OT_HTML,
+ /* $clearState = */ true
+ );
+
+ $backend = $this->getMockForAbstractClass( '\Lingo\Backend' );
+ $backend->expects( $this->any() )
+ ->method( 'next' )
+ ->will( new
PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( $glossaryEntries ) );
+
+
+ $lingoParser = LingoParser::getInstance();
+ $lingoParser->setBackend( $backend );
+
+ LingoParser::parse( $parser, $text );
+
+ $this->assertEquals( $expected, $text );
+
+
+ }
+
+ public function provideData() {
+
+ $data = array();
+
+ $xmlFileProvider = new XmlFileProvider( __DIR__ .
'/../Fixture/articleAnnotation' );
+ $files = $xmlFileProvider->getFiles();
+
+ foreach ( $files as $file ) {
+
+ $xml = simplexml_load_file( $file, "SimpleXMLElement",
LIBXML_NOCDATA );
+ $json = json_encode( $xml );
+ $decoded = json_decode( $json, TRUE );
+
+ \MediaWiki\suppressWarnings();
+ $testCase = array(
+ 0 => substr( $file, strlen( __DIR__ .
'/../Fixture/articleAnnotation' ) ),
+ 1 => $decoded[ 'text' ],
+ 2 => array(),
+ 3 => $decoded[ 'expected' ],
+ );
+
+ if ( array_key_exists( 'term', $decoded[
'glossary-entry' ] ) ) {
+
+ $testCase[ 2 ][] = array( $decoded[
'glossary-entry' ][ 'term' ], $decoded[ 'glossary-entry' ][ 'definition' ],
$decoded[ 'glossary-entry' ][ 'link' ], $decoded[ 'glossary-entry' ][ 'style' ]
);
+
+ } else {
+ foreach ( $decoded[ 'glossary-entry' ] as
$entry ) {
+ $testCase[ 2 ][] = array( $entry[
'term' ], $entry[ 'definition' ], $entry[ 'link' ], $entry[ 'style' ] );
+ }
+ }
+ \MediaWiki\restoreWarnings();
+
+ $data[] = $testCase;
+ }
+
+ return $data;
+ }
+}
diff --git a/tests/phpunit/Util/XmlFileProvider.php
b/tests/phpunit/Util/XmlFileProvider.php
new file mode 100644
index 0000000..b3b4000
--- /dev/null
+++ b/tests/phpunit/Util/XmlFileProvider.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ *
+ * @copyright 2011 - 2016, Stephan Gambke, mwjames
+ *
+ * @license GNU General Public License, version 2 (or any later version)
+ *
+ * This file is part of the MediaWiki extension Lingo.
+ * 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/>.
+ *
+ * @since 2.0.1
+ * @file
+ * @ingroup Lingo
+ * @ingroup Test
+ */
+
+namespace Lingo\Tests\Util;
+
+use RuntimeException;
+
+/**
+ * @group extensions-lingo
+ * @group mediawiki-databaseless
+ *
+ * @since 2.0.1
+ * @author mwjames, Stephan Gambke
+ * @ingroup Lingo
+ * @ingroup Test
+ */
+class XmlFileProvider {
+
+ protected $path = null;
+
+ /**
+ * @param string $path
+ */
+ public function __construct( $path ) {
+ $this->path = $path;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getFiles() {
+ return $this->loadXmlFiles( $this->readDirectory( $this->path )
);
+ }
+
+ /**
+ * @param String $path
+ * @return string
+ */
+ protected function readDirectory( $path ) {
+
+ $path = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR,
$path );
+
+ if ( is_readable( $path ) ) {
+ return $path;
+ }
+
+ throw new RuntimeException( "Expected an accessible {$path}
path" );
+ }
+
+ /**
+ * @param String $path
+ * @return string[]
+ */
+ protected function loadXmlFiles( $path ) {
+
+ $directoryIterator = new \RecursiveDirectoryIterator( $path );
+ $iteratorIterator = new
\RecursiveIteratorIterator($directoryIterator);
+ $regexIterator = new \RegexIterator($iteratorIterator,
'/^.+\.xml$/i', \RecursiveRegexIterator::GET_MATCH);
+
+ $files = call_user_func_array('array_merge', iterator_to_array(
$regexIterator ) );
+
+ return $files;
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/276979
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6579622bc46f89720b29199401343b07dcfde104
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Lingo
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
Gerrit-Reviewer: Foxtrott <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits