Jarry1250 has submitted this change and it was merged.

Change subject: Start PHPUnit testing framework
......................................................................


Start PHPUnit testing framework

* Create TranslateSvgTestCase to handle shared content
* Use TranslateSvgTestCase to handle global assignation
* Start SVGMessageGroup and SVGFormatReader tests
* Register hooks for Jenkins

Change-Id: I3495d8f719616d60f8193bac8a54dbe98722ea17
---
M TranslateSvg.php
M TranslateSvgHooks.php
A phpunit.xml.dist
A tests/data/Speech_bubbles.svg
A tests/phpunit/SVGFormatReaderTest.php
A tests/phpunit/SVGMessageGroupTest.php
A tests/phpunit/TranslateSvgTestCase.php
A tests/phpunit/bootstrap.php
8 files changed, 501 insertions(+), 0 deletions(-)

Approvals:
  Jarry1250: Verified; Looks good to me, approved



diff --git a/TranslateSvg.php b/TranslateSvg.php
index 0c134fa..8bcc020 100644
--- a/TranslateSvg.php
+++ b/TranslateSvg.php
@@ -25,6 +25,12 @@
 $wgAutoloadClasses['TranslateSvgHooks'] = $dir . 'TranslateSvgHooks.php';
 $wgAutoloadClasses['ExportSVGMessagesTask'] = $dir . 'TranslateSvgTasks.php';
 $wgAutoloadClasses['TranslateSvgUpload'] = $dir . 'SVGFormatWriter.php';
+
+if( defined( 'MW_PHPUNIT_TEST' ) ) {
+       define( 'MW_PHPUNIT_USE_AUTOLOAD', true );
+       require_once $dir . 'tests/phpunit/bootstrap.php';
+}
+
 $wgMessagesDirs['TranslateSvg'] = __DIR__ . '/i18n';
 $wgExtensionMessagesFiles['TranslateSvg'] = $dir . 'TranslateSvg.i18n.php';
 $wgExtensionMessagesFiles['TranslateSvgAlias'] = $dir . 
'TranslateSvg.alias.php';
@@ -91,6 +97,7 @@
 $wgHooks['TranslateGetAPIMessageGroupsParameterList'][] = 
'TranslateSvgHooks::addAPIParams';
 $wgHooks['TranslatePostInitGroups'][] = 'TranslateSvgHooks::loadSVGGroups';
 $wgHooks['TranslateProcessAPIMessageGroupsProperties'][] = 
'TranslateSvgHooks::processAPIProperties';
+$wgHooks['UnitTestsList'][] = 'TranslateSvgHooks::onUnitTestsList';
 
 $wgSpecialPages['TranslateNewSVG'] = 'SpecialTranslateNewSVG';
 $wgSpecialPageGroups['TranslateNewSVG'] = 'wiki';
diff --git a/TranslateSvgHooks.php b/TranslateSvgHooks.php
index a8cbfb0..92bae4b 100644
--- a/TranslateSvgHooks.php
+++ b/TranslateSvgHooks.php
@@ -450,4 +450,15 @@
                $vars['wgFileTranslationStarted'] = true;
                return true;
        }
+
+       /**
+        * Register our unit tests so Jenkins can run them
+        *
+        * @param &$files \array Array of tests (test files) to be run
+        * @return \bool True
+        */
+       public static function onUnitTestsList( &$files ) {
+               $files = array_merge( $files, glob( __DIR__ . 
'/tests/phpunit/*Test.php' ) );
+               return true;
+       }
 }
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..40d2720
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Colors don't work on Windows!
+phpunit.php enables colors for other OSs at runtime
+-->
+<phpunit bootstrap="tests/phpunit/bootstrap.php"
+         colors="false"
+         backupGlobals="false"
+         convertErrorsToExceptions="true"
+         convertNoticesToExceptions="true"
+         convertWarningsToExceptions="true"
+         forceCoversAnnotation="true"
+         stopOnFailure="false"
+         timeoutForSmallTests="10"
+         timeoutForMediumTests="30"
+         timeoutForLargeTests="60"
+         strict="true"
+         verbose="true">
+    <testsuites>
+        <testsuite name="all">
+            <directory>tests/phpunit/</directory>
+        </testsuite>
+    </testsuites>
+</phpunit>
diff --git a/tests/data/Speech_bubbles.svg b/tests/data/Speech_bubbles.svg
new file mode 100644
index 0000000..6b1ef7a
--- /dev/null
+++ b/tests/data/Speech_bubbles.svg
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:cc="http://creativecommons.org/ns#"; 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 
xmlns:svg="http://www.w3.org/2000/svg"; xmlns="http://www.w3.org/2000/svg"; 
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"; 
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"; width="17.7cm" 
height="13cm" id="svg2" version="1.1" inkscape:version="0.48.2 r9819" 
sodipodi:docname="New document 1">
+  <defs id="defs4"/>
+  <sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" 
borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" 
inkscape:zoom="0.7" inkscape:cx="296.43458" inkscape:cy="130.17435" 
inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" 
fit-margin-top="0" fit-margin-left="0" fit-margin-right="0" 
fit-margin-bottom="0" inkscape:window-width="1366" inkscape:window-height="706" 
inkscape:window-x="-8" inkscape:window-y="-8" inkscape:window-maximized="1"/>
+  <g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" 
transform="translate(-0.28125,-1.21875)">
+    <switch 
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"><text
 xml:space="preserve" x="90" y="108.07646" id="text2985-de" 
sodipodi:linespacing="125%" systemLanguage="de"><tspan text-decoration="normal" 
font-style="normal" font-weight="normal" 
id="tspan2987-de">Hallo!</tspan></text><text xml:space="preserve" x="90" 
y="108.07646" id="text2985-fr" sodipodi:linespacing="125%" 
systemLanguage="fr"><tspan x="80" y="108.07646" text-decoration="normal" 
font-style="normal" font-weight="normal" 
id="tspan2987-fr">Bonjour</tspan></text><text xml:space="preserve" x="90" 
y="108.07646" id="text2985-nl" sodipodi:linespacing="125%" systemLanguage="nl, 
tlh-ca"><tspan x="90" y="108.07646" text-decoration="normal" 
font-style="normal" font-weight="normal" 
id="tspan2987-nl">Hallo!</tspan></text><text xml:space="preserve" x="90" 
y="108.07646" id="text2985" sodipodi:linespacing="125%"><tspan x="90" 
y="108.07646" text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2987" sodipodi:role="line">Hello!</tspan></text></switch>
+    <switch 
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"><text
 xml:space="preserve" x="330" y="188.07648" id="text2989-de" 
sodipodi:linespacing="125%" systemLanguage="de"><tspan x="323" y="188.07648" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2991-de">Hallo! Wie</tspan><tspan x="350" y="238.07648" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2993-de" sodipodi:role="line">geht's?</tspan></text><text 
xml:space="preserve" x="330" y="188.07648" id="text2989-fr" 
sodipodi:linespacing="125%" systemLanguage="fr"><tspan x="335" y="188.07648" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2991-fr">Bonjour,</tspan><tspan x="350" y="238.07648" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2993-fr">ça va?</tspan></text><text xml:space="preserve" x="330" 
y="188.07648" id="text2989-nl" sodipodi:linespacing="125%" systemLanguage="nl, 
tlh-ca"><tspan x="310" y="188.07648" text-decoration="normal" 
font-style="normal" font-weight="normal" id="tspan2991-nl">Hallo! 
Hoe</tspan><tspan x="330" y="238.07648" text-decoration="normal" 
font-style="normal" font-weight="normal" id="tspan2993-nl">gaat 
het?</tspan></text><text xml:space="preserve" x="330" y="188.07648" 
id="text2989" sodipodi:linespacing="125%"><tspan x="330" y="188.07648" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2991" sodipodi:role="line">Hello! How</tspan><tspan x="330" 
y="238.07648" text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2993" sodipodi:role="line">are you?</tspan></text></switch>
+    <switch 
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"><text
 xml:space="preserve" x="101.42857" y="318.64789" id="text2995-fr" 
sodipodi:linespacing="125%" systemLanguage="fr"><tspan x="82" y="323" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2997-fr">Ça va bien,</tspan><tspan x="117.42857" y="368.64789" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2999-fr">et toi?</tspan></text><text xml:space="preserve" 
x="101.42857" y="318.64789" id="text2995-nl" sodipodi:linespacing="125%" 
systemLanguage="nl, tlh-ca"><tspan x="101.42857" y="318.64789" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2997-nl">Goed,</tspan><tspan x="101.42857" y="368.64789" 
font-size="90%" text-decoration="normal" font-style="normal" 
font-weight="normal" id="tspan2999-nl">met jou?</tspan></text><text 
xml:space="preserve" x="101.42857" y="318.64789" id="text2995" 
sodipodi:linespacing="125%"><tspan x="101.42857" y="318.64789" 
text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2997" sodipodi:role="line">I'm well,</tspan><tspan x="101.42857" 
y="368.64789" text-decoration="normal" font-style="normal" font-weight="normal" 
id="tspan2999" sodipodi:role="line">   you?</tspan></text></switch>
+    <path 
style="color:#000000;fill:none;stroke:#808080;stroke-width:8.19999980999999960;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
 d="m 145.41518,24.660714 c -54.439497,0 -98.562501,30.043022 -98.562501,67.125 
0,9.936246 3.188468,19.358966 8.875,27.843746 -3.477405,24.25473 -24,58.71875 
-24,58.71875 0,0 55.316401,-29.49598 68.544641,-28.55804 2.17169,0.15398 
-0.660951,4.01645 -2.044641,0.93304 14.019951,5.22007 30.083661,8.21875 
47.187501,8.21875 54.4395,0 98.59375,-30.07427 98.59375,-67.156246 0,-37.081978 
-44.15425,-67.125 -98.59375,-67.125 z" id="path3769" 
inkscape:connector-curvature="0" sodipodi:nodetypes="ssccscsss"/>
+    <path 
style="color:#000000;fill:none;stroke:#808080;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
 d="m 416.54255,99.214524 c 73.5252,0 133.11712,43.566276 133.11712,97.339926 
0,14.40884 -4.3063,28.073 -11.98645,40.37703 4.69653,35.1725 32.41406,85.14978 
32.41406,85.14978 0,0 -74.70955,-42.77297 -92.57542,-41.41284 -2.93306,0.22328 
0.89266,5.82436 2.76145,1.35303 -18.93514,7.56977 -40.63057,11.91824 
-63.73076,11.91824 -73.52523,0 -133.15935,-43.61157 -133.15935,-97.38524 
0,-53.77365 59.63412,-97.339926 133.15935,-97.339926 z" id="path3769-1" 
inkscape:connector-curvature="0" sodipodi:nodetypes="ssccscsss"/>
+    <path 
style="color:#000000;fill:none;stroke:#808080;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
 d="m 173.1621,250.34923 c -64.02996,0 -115.926026,34.29807 
-115.926026,76.63201 0,11.34353 3.750173,22.1008 10.438488,31.7873 
-4.090007,27.68997 -28.228023,67.03517 -28.228023,67.03517 0,0 
65.061361,-33.67353 80.619991,-32.60275 2.55427,0.17578 -0.77738,4.5853 
-2.40483,1.06519 16.4898,5.95939 35.38343,9.38278 55.5004,9.38278 64.02999,0 
115.96279,-34.33373 115.96279,-76.66769 0,-42.33394 -51.9328,-76.63201 
-115.96279,-76.63201 z" id="path3769-1-7" inkscape:connector-curvature="0" 
sodipodi:nodetypes="ssccscsss"/>
+  </g>
+</svg>
diff --git a/tests/phpunit/SVGFormatReaderTest.php 
b/tests/phpunit/SVGFormatReaderTest.php
new file mode 100644
index 0000000..76e8e96
--- /dev/null
+++ b/tests/phpunit/SVGFormatReaderTest.php
@@ -0,0 +1,259 @@
+<?php
+/**
+ * Unit tests.
+ *
+ * @file
+ * @author Harry Burt
+ * @copyright Copyright © 2014, Harry Burt
+ * @license GPL-2.0+
+ * @group database
+ */
+
+/**
+ * Unit tests for SVGFormatReader class.
+ * @covers SVGFormatReader
+ */
+class SVGFormatReaderTest extends TranslateSvgTestCase {
+
+       /**
+        * @var SVGFormatReader
+        */
+       private $reader;
+
+       public static function setUpBeforeClass() {
+               parent::setUpBeforeClass();
+               self::prepareFile( __DIR__ . '/../data/Speech_bubbles.svg' );
+       }
+
+       public function setUp() {
+               parent::setUp();
+               $this->reader = new SVGFormatReader( $this->messageGroup );
+       }
+
+       public function testGetInFileTranslations() {
+               $expected = array (
+                       'tspan2987' =>
+                               array (
+                                       'de' =>
+                                               array (
+                                                       'text' => 'Hallo!',
+                                                       'id' => 'tspan2987-de',
+                                                       'data-parent' => 
'text2985',
+                                               ),
+                                       'fr' =>
+                                               array (
+                                                       'text' => 'Bonjour',
+                                                       'x' => '80',
+                                                       'y' => '108.07646',
+                                                       'id' => 'tspan2987-fr',
+                                                       'data-parent' => 
'text2985',
+                                               ),
+                                       'nl' =>
+                                               array (
+                                                       'text' => 'Hallo!',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'tspan2987-nl',
+                                                       'data-parent' => 
'text2985',
+                                               ),
+                                       'tlh-ca' =>
+                                               array (
+                                                       'text' => 'Hallo!',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'tspan2987-nl',
+                                                       'data-parent' => 
'text2985',
+                                               ),
+                                       'fallback' =>
+                                               array (
+                                                       'text' => 'Hello!',
+                                                       'x' => '90',
+                                                       'y' => '108.07646',
+                                                       'id' => 'tspan2987',
+                                                       'sodipodi:role' => 
'line',
+                                                       'data-parent' => 
'text2985',
+                                               ),
+                               ),
+                       'tspan2991' =>
+                               array (
+                                       'de' =>
+                                               array (
+                                                       'text' => 'Hallo! Wie',
+                                                       'x' => '323',
+                                                       'y' => '188.07648',
+                                                       'id' => 'tspan2991-de',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'fr' =>
+                                               array (
+                                                       'text' => 'Bonjour,',
+                                                       'x' => '335',
+                                                       'y' => '188.07648',
+                                                       'id' => 'tspan2991-fr',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'nl' =>
+                                               array (
+                                                       'text' => 'Hallo! Hoe',
+                                                       'x' => '310',
+                                                       'y' => '188.07648',
+                                                       'id' => 'tspan2991-nl',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'tlh-ca' =>
+                                               array (
+                                                       'text' => 'Hallo! Hoe',
+                                                       'x' => '310',
+                                                       'y' => '188.07648',
+                                                       'id' => 'tspan2991-nl',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'fallback' =>
+                                               array (
+                                                       'text' => 'Hello! How',
+                                                       'x' => '330',
+                                                       'y' => '188.07648',
+                                                       'id' => 'tspan2991',
+                                                       'sodipodi:role' => 
'line',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                               ),
+                       'tspan2993' =>
+                               array (
+                                       'de' =>
+                                               array (
+                                                       'text' => 'geht\'s?',
+                                                       'x' => '350',
+                                                       'y' => '238.07648',
+                                                       'id' => 'tspan2993-de',
+                                                       'sodipodi:role' => 
'line',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'fr' =>
+                                               array (
+                                                       'text' => 'ça va?',
+                                                       'x' => '350',
+                                                       'y' => '238.07648',
+                                                       'id' => 'tspan2993-fr',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'nl' =>
+                                               array (
+                                                       'text' => 'gaat het?',
+                                                       'x' => '330',
+                                                       'y' => '238.07648',
+                                                       'id' => 'tspan2993-nl',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'tlh-ca' =>
+                                               array (
+                                                       'text' => 'gaat het?',
+                                                       'x' => '330',
+                                                       'y' => '238.07648',
+                                                       'id' => 'tspan2993-nl',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                                       'fallback' =>
+                                               array (
+                                                       'text' => 'are you?',
+                                                       'x' => '330',
+                                                       'y' => '238.07648',
+                                                       'id' => 'tspan2993',
+                                                       'sodipodi:role' => 
'line',
+                                                       'data-parent' => 
'text2989',
+                                               ),
+                               ),
+                       'tspan2997' =>
+                               array (
+                                       'fr' =>
+                                               array (
+                                                       'text' => 'Ça va bien,',
+                                                       'x' => '82',
+                                                       'y' => '323',
+                                                       'id' => 'tspan2997-fr',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                                       'nl' =>
+                                               array (
+                                                       'text' => 'Goed,',
+                                                       'x' => '101.42857',
+                                                       'y' => '318.64789',
+                                                       'id' => 'tspan2997-nl',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                                       'tlh-ca' =>
+                                               array (
+                                                       'text' => 'Goed,',
+                                                       'x' => '101.42857',
+                                                       'y' => '318.64789',
+                                                       'id' => 'tspan2997-nl',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                                       'fallback' =>
+                                               array (
+                                                       'text' => 'I\'m well,',
+                                                       'x' => '101.42857',
+                                                       'y' => '318.64789',
+                                                       'id' => 'tspan2997',
+                                                       'sodipodi:role' => 
'line',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                               ),
+                       'tspan2999' =>
+                               array (
+                                       'fr' =>
+                                               array (
+                                                       'text' => 'et toi?',
+                                                       'x' => '117.42857',
+                                                       'y' => '368.64789',
+                                                       'id' => 'tspan2999-fr',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                                       'nl' =>
+                                               array (
+                                                       'text' => 'met jou?',
+                                                       'x' => '101.42857',
+                                                       'y' => '368.64789',
+                                                       'font-size' => '90%',
+                                                       'id' => 'tspan2999-nl',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                                       'tlh-ca' =>
+                                               array (
+                                                       'text' => 'met jou?',
+                                                       'x' => '101.42857',
+                                                       'y' => '368.64789',
+                                                       'font-size' => '90%',
+                                                       'id' => 'tspan2999-nl',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                                       'fallback' =>
+                                               array (
+                                                       'text' => '   you?',
+                                                       'x' => '101.42857',
+                                                       'y' => '368.64789',
+                                                       'id' => 'tspan2999',
+                                                       'sodipodi:role' => 
'line',
+                                                       'data-parent' => 
'text2995',
+                                               ),
+                               )
+               );
+               $this->assertEquals( $expected, 
$this->reader->getInFileTranslations() );
+       }
+
+       public function testGetSavedLanguages() {
+               $expected = array(
+                       'de', 'fr', 'nl', 'tlh-ca', 'en'
+               );
+               $this->assertEquals( $expected, 
$this->reader->getSavedLanguages() );
+       }
+
+       public function testGetSavedLanguagesFiltered() {
+               $expected = array(
+                       'full' => array( 'fr', 'nl', 'tlh-ca', 'en' ),
+                       'partial' => array( 'de' )
+               );
+               $this->assertEquals( $expected, 
$this->reader->getSavedLanguagesFiltered() );
+       }
+
+}
\ No newline at end of file
diff --git a/tests/phpunit/SVGMessageGroupTest.php 
b/tests/phpunit/SVGMessageGroupTest.php
new file mode 100644
index 0000000..cf31fa5
--- /dev/null
+++ b/tests/phpunit/SVGMessageGroupTest.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Unit tests.
+ *
+ * @file
+ * @author Harry Burt
+ * @copyright Copyright © 2014, Harry Burt
+ * @license GPL-2.0+
+ */
+
+/**
+ * Unit tests for SVGMessageGroup class.
+ * @covers SVGMessageGroup
+ */
+class SVGMessageGroupTest extends TranslateSvgTestCase {
+       public static function setUpBeforeClass() {
+               parent::setUpBeforeClass();
+               self::prepareFile( __DIR__ . '/../data/Speech_bubbles.svg' );
+       }
+
+       public function testGetSourceLanguage() {
+               $this->assertEquals(
+                       'en',
+                       $this->messageGroup->getSourceLanguage(),
+                       'No source language has been set, en should be used as 
the default'
+               );
+       }
+
+       /**
+        * @dataProvider provideSetSourceLanguage
+        */
+       public function testSetSourceLanguage( $to ) {
+               $this->messageGroup->setSourceLanguage( $to );
+               $this->assertEquals( $to, 
$this->messageGroup->getSourceLanguage() );
+       }
+
+       public function provideSetSourceLanguage() {
+               return array( array( 'de' ), array( 'en' ) );
+       }
+
+       public function testGetId() {
+               // Should be normalised to spaces
+               $name = str_replace( '_', ' ', self::$name );
+               $this->assertEquals( $name, $this->messageGroup->getId() );
+       }
+
+       public function testGetLabel() {
+               // Should be normalised to spaces
+               $name = str_replace( '_', ' ', self::$name );
+               $this->assertEquals( $name, $this->messageGroup->getLabel() );
+       }
+
+       public function testGetNamespace() {
+               $this->assertEquals( NS_FILE, 
$this->messageGroup->getNamespace() );
+       }
+}
\ No newline at end of file
diff --git a/tests/phpunit/TranslateSvgTestCase.php 
b/tests/phpunit/TranslateSvgTestCase.php
new file mode 100644
index 0000000..88f70bb
--- /dev/null
+++ b/tests/phpunit/TranslateSvgTestCase.php
@@ -0,0 +1,116 @@
+<?php
+
+class TranslateSvgUpload extends UploadBase {
+       public function initializeFromRequest( &$request ) { }
+}
+class TranslateSvgTestCase extends MediaWikiTestCase {
+
+       /**
+        * @var string
+        */
+       protected static $name;
+
+       /**
+        * @var SVGMessageGroup
+        */
+       protected $messageGroup;
+
+       protected static function prepareFile( $path ) {
+               $tempName = tempnam( wfTempDir(), 'test' );
+               copy( $path, $tempName );
+
+               $name = substr( basename( $path ), 0, -4 ) . '_' . date( 'His' 
) . '.svg';
+               $title = Title::makeTitle( NS_FILE, $name );
+               if( $title->exists()  ) {
+                       $wikiPage = new WikiPage( $title );
+                       $wikiPage->doDeleteArticle( 'resetting' );
+                       $subpages = $title->getSubpages();
+                       foreach ( $subpages as $subpage ) {
+                               /** @var Title $subpage */
+                               $wikiPage = new WikiPage( $subpage );
+                               $wikiPage->doDeleteArticle( 'resetting' );
+                       }
+               }
+
+               // Prepare upload
+               $uploader = new TranslateSvgUpload();
+               $uploader->initializePathInfo( $name, $tempName, filesize( 
$tempName ), true );
+
+               // Actually perform upload
+               $bot = User::newFromName( 'TranslateSvg unit tests', false );
+               $status = $uploader->performUpload( 'testing', 'Created during 
testing', false, $bot );
+               if ( !$status->isGood() ) {
+                       die( 'Could not upload test file ' . $name );
+               }
+
+               $dbw = wfGetDB( DB_MASTER );
+               $table = 'translate_svg';
+               $row = array( 'ts_page_id' => $title->getArticleId() );
+               $dbw->insert( $table, $row, __METHOD__, array( 'IGNORE' ) );
+               MessageGroups::clearCache();
+               MessageIndex::singleton()->rebuild();
+
+               self::$name = $name;
+       }
+
+       public static function setUpBeforeClass() {
+
+               // Preserve the syntax of $this->setMwGlobals for future use
+               // but we can't use it te way it's written at the moment since 
we're static
+               $pairs = array(
+                       // Add .svg to list of supported file extensions
+                       'wgFileExtensions' => array( 'png', 'gif', 'jpg', 
'jpeg', 'svg' ),
+
+                       // Bot (who won't be a registered users) needs to be 
able to create pages
+                       'wgGroupPermissions' => array(
+                               '*' => array(
+                                       'createpage' => true,
+                                       'read' => true,
+                                       'edit' => true,
+                               )
+                       ),
+
+                       // Need to enable subpages in the File: namespace
+                       'wgNamespacesWithSubpages' => array( NS_FILE => true )
+               );
+
+               foreach ( $pairs as $key => $value ) {
+                       $GLOBALS[$key] = $value;
+               }
+       }
+
+       public function setUp() {
+               parent::setUp();
+               if( isset( self::$name ) ) {
+                       $this->messageGroup = new SVGMessageGroup( self::$name 
);
+               }
+       }
+
+       public function tearDown() {
+               parent::tearDown();
+               $this->messageGroup = null;
+       }
+
+       public static function tearDownAfterClass() {
+               parent::tearDownAfterClass();
+
+               $title = Title::makeTitle( NS_FILE, self::$name );
+               if( $title->exists()  ) {
+                       $wikiPage = new WikiPage( $title );
+                       $wikiPage->doDeleteArticle( 'resetting' );
+                       $subpages = $title->getSubpages();
+                       foreach ( $subpages as $subpage ) {
+                               /** @var Title $subpage */
+                               $wikiPage = new WikiPage( $subpage );
+                               $wikiPage->doDeleteArticle( 'resetting' );
+                       }
+               }
+
+               $dbw = wfGetDB( DB_MASTER );
+               $row = array( 'ts_page_id' => $title->getArticleID() );
+               $dbw->delete( 'translate_svg', $row, __METHOD__ );
+               $conds = array( 'tmd_group' => str_replace( '_', ' ', 
self::$name ) );
+               $dbw->delete( 'translate_metadata', $conds, __METHOD__ );
+               $dbw->commit( __METHOD__, 'flush' );
+       }
+}
\ No newline at end of file
diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php
new file mode 100644
index 0000000..e022105
--- /dev/null
+++ b/tests/phpunit/bootstrap.php
@@ -0,0 +1,13 @@
+<?php
+
+       // Load required classes
+       $testsDir = __DIR__ . '/';
+
+       if( defined( 'MW_PHPUNIT_USE_AUTOLOAD' ) ) {
+               // Jenkins run: use Autoload
+               $wgAutoloadClasses['TranslateSvgUpload'] = $testsDir . 
'TranslateSvgTestCase.php';
+               $wgAutoloadClasses['TranslateSvgTestCase'] = $testsDir . 
'TranslateSvgTestCase.php';
+       } else {
+               // Manual invocation: we just need require_once
+               require_once( $testsDir . 'TranslateSvgTestCase.php' );
+       }
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3495d8f719616d60f8193bac8a54dbe98722ea17
Gerrit-PatchSet: 28
Gerrit-Project: mediawiki/extensions/TranslateSvg
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <jarry1...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Hashar <has...@free.fr>
Gerrit-Reviewer: Jarry1250 <jarry1...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to