Jarry1250 has uploaded a new change for review.

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

Change subject: Add extra parser tests for SVGMessageGroup and SVGFile classes
......................................................................

Add extra parser tests for SVGMessageGroup and SVGFile classes

Change-Id: Ibc0a4c37afbaa82d296d5bd964e12c119e7e1b87
---
M tests/phpunit/SVGFileTest.php
M tests/phpunit/SVGMessageGroupTest.php
2 files changed, 157 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslateSvg 
refs/changes/34/156134/1

diff --git a/tests/phpunit/SVGFileTest.php b/tests/phpunit/SVGFileTest.php
index ec83b0c..5843f77 100644
--- a/tests/phpunit/SVGFileTest.php
+++ b/tests/phpunit/SVGFileTest.php
@@ -294,4 +294,145 @@
                $this->assertEquals( $expected, 
$this->svg->getSavedLanguagesFiltered() );
        }
 
+       public function testGetFilteredTextNodes() {
+
+               // The important things here are:
+               //  * array length. One of the three sets has non-zero text 
content, so should not be filtered
+               //  * text. Since they are filtered, all should contain nothing 
but $ references.
+               //  * data-children. Each should have as many children as there 
are $ references.
+
+               $expected = array(
+                       'text2985' =>
+                               array(
+                                       'de' =>
+                                               array(
+                                                       'text' => '$1',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'text2985-de',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2987',
+                                               ),
+                                       'fr' =>
+                                               array(
+                                                       'text' => '$1',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'text2985-fr',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2987',
+                                               ),
+                                       'nl' =>
+                                               array(
+                                                       'text' => '$1',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'text2985-nl',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2987',
+                                               ),
+                                       'tlh-ca' =>
+                                               array(
+                                                       'text' => '$1',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'text2985-nl',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2987',
+                                               ),
+                                       'fallback' =>
+                                               array(
+                                                       'text' => '$1',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'text2985',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2987',
+                                               ),
+                               ),
+                       'text2989' =>
+                               array(
+                                       'de' =>
+                                               array(
+                                                       'text' => '$1$2',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '330',
+                                                       'y' => '188.07648',
+                                                       'id' => 'text2989-de',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2991|tspan2993',
+                                               ),
+                                       'fr' =>
+                                               array(
+                                                       'text' => '$1$2',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '330',
+                                                       'y' => '188.07648',
+                                                       'id' => 'text2989-fr',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2991|tspan2993',
+                                               ),
+                                       'nl' =>
+                                               array(
+                                                       'text' => '$1$2',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '330',
+                                                       'y' => '188.07648',
+                                                       'id' => 'text2989-nl',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2991|tspan2993',
+                                               ),
+                                       'tlh-ca' =>
+                                               array(
+                                                       'text' => '$1$2',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '330',
+                                                       'y' => '188.07648',
+                                                       'id' => 'text2989-nl',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2991|tspan2993',
+                                               ),
+                                       'fallback' =>
+                                               array(
+                                                       'text' => '$1$2',
+                                                       'xml:space' => 
'preserve',
+                                                       'x' => '330',
+                                                       'y' => '188.07648',
+                                                       'id' => 'text2989',
+                                                       'sodipodi:linespacing' 
=> '125%',
+                                                       'data-children' => 
'tspan2991|tspan2993',
+                                               ),
+                               ),
+               );
+               $this->assertArrayEquals( $expected, 
$this->svg->getFilteredTextNodes() );
+       }
+
+       public function testSwitchTranslationSetRoundtrip() {
+               // Functions already tested above
+               $current = $this->svg->getInFileTranslations();
+               $filteredTextNodes = $this->svg->getFilteredTextNodes();
+               $ret = $this->svg->switchToTranslationSet( array_merge( 
$current, $filteredTextNodes ) );
+
+               $this->assertArrayEquals( $current, 
$this->svg->getInFileTranslations() );
+               $this->assertArrayEquals( $filteredTextNodes, 
$this->svg->getFilteredTextNodes() );
+               $this->assertArrayEquals( array( 'started' => array(), 
'expanded' => array() ), $ret );
+       }
+
+       public function testSaveToString() {
+               // Check that we are not actually destroying the XML file
+               $this->assertGreaterThan( 1500, strlen( 
$this->svg->saveToString() ) );
+       }
+
+       public function testSaveToPath() {
+               $tempPath = tempnam( wfTempDir(), 'test' );
+               $this->svg->saveToPath( $tempPath );
+
+               // Check that we are not actually destroying the XML file
+               $this->assertGreaterThan( 1500, strlen( file_get_contents( 
$tempPath ) ) );
+       }
 }
\ No newline at end of file
diff --git a/tests/phpunit/SVGMessageGroupTest.php 
b/tests/phpunit/SVGMessageGroupTest.php
index 2329825..b6ec8c4 100644
--- a/tests/phpunit/SVGMessageGroupTest.php
+++ b/tests/phpunit/SVGMessageGroupTest.php
@@ -18,6 +18,14 @@
                self::prepareFile( __DIR__ . '/../data/Speech_bubbles.svg' );
        }
 
+       /**
+        * @expectedException MWException
+        * @expectedExceptionMessage File not found
+        */
+       public function testConstructorFileNotFound() {
+               $group = new SVGMessageGroup( 'DoesNotExist.svg' );
+       }
+
        public function testRegistration() {
                // In order that a lot of the tests function, prepareFile() 
calls register()
                // but we should check now that it's worked
@@ -66,4 +74,12 @@
        public function testGetNamespace() {
                $this->assertEquals( NS_FILE, 
$this->messageGroup->getNamespace() );
        }
+
+       public function testGetDescription() {
+               // Should be normalised to spaces
+               $name = str_replace( '_', ' ', self::$name );
+               $expected = "[[File:$name|thumb|right|upright|275x275px]]
+<div style=\"overflow:auto; padding:2px;\">Created during testing</div>";
+               $this->assertEquals( $expected, 
$this->messageGroup->getDescription() );
+       }
 }
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc0a4c37afbaa82d296d5bd964e12c119e7e1b87
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TranslateSvg
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <jarry1...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to