summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/tests')
-rw-r--r--MLEB/Translate/tests/phpunit/HookDocTest.php8
-rw-r--r--MLEB/Translate/tests/phpunit/MessageCollectionTest.php9
-rw-r--r--MLEB/Translate/tests/phpunit/MessageGroupStatesUpdaterJobTest.php4
-rw-r--r--MLEB/Translate/tests/phpunit/MessageGroupsTest.php2
-rw-r--r--MLEB/Translate/tests/phpunit/MessageIndexRebuildJobTest.php2
-rw-r--r--MLEB/Translate/tests/phpunit/MockSuperUser.php24
-rw-r--r--MLEB/Translate/tests/phpunit/PageTranslationTaggingTest.php4
-rw-r--r--MLEB/Translate/tests/phpunit/SolrTTMServerTest.php2
-rw-r--r--MLEB/Translate/tests/phpunit/SpecialPagesTest.php4
-rw-r--r--MLEB/Translate/tests/phpunit/TranslateHooksTest.php4
-rw-r--r--MLEB/Translate/tests/phpunit/TranslationFuzzyUpdaterTest.php2
-rw-r--r--MLEB/Translate/tests/phpunit/api/ApiQueryMessageGroupsTest.php2
-rw-r--r--MLEB/Translate/tests/phpunit/api/ApiTranslationReviewTest.php16
-rw-r--r--MLEB/Translate/tests/phpunit/tag/PageTranslationHooksTest.php4
-rw-r--r--MLEB/Translate/tests/qunit/.eslintrc.json6
-rw-r--r--MLEB/Translate/tests/qunit/ext.translate.parsers.test.js10
-rw-r--r--MLEB/Translate/tests/qunit/ext.translate.special.pagemigration.test.js16
17 files changed, 51 insertions, 68 deletions
diff --git a/MLEB/Translate/tests/phpunit/HookDocTest.php b/MLEB/Translate/tests/phpunit/HookDocTest.php
index d2cb6aaa..616a6a53 100644
--- a/MLEB/Translate/tests/phpunit/HookDocTest.php
+++ b/MLEB/Translate/tests/phpunit/HookDocTest.php
@@ -73,9 +73,9 @@ class HookDocTest extends MediaWikiTestCase {
protected static function getJSHooksFromFile( $file ) {
$content = file_get_contents( $file );
$m = [];
- preg_match_all( '/(?:mw\.translateHooks\.run)\(\s*([\'"])(.*?)\1/', $content, $m );
+ preg_match_all( '/\bmw\.translateHooks\.run\(\s*[\'"]([^\'"]+)/', $content, $m );
$hooks = [];
- foreach ( $m[2] as $hook ) {
+ foreach ( $m[1] as $hook ) {
$hooks[$hook] = [];
}
@@ -85,9 +85,9 @@ class HookDocTest extends MediaWikiTestCase {
protected static function getPHPHooksFromFile( $file ) {
$content = file_get_contents( $file );
$m = [];
- preg_match_all( '/(?:wfRunHooks|Hooks\:\:run)\(\s*([\'"])(.*?)\1/', $content, $m );
+ preg_match_all( '/\bHooks::run\(\s*[\'"]([^\'"]+)/', $content, $m );
$hooks = [];
- foreach ( $m[2] as $hook ) {
+ foreach ( $m[1] as $hook ) {
$hooks[$hook] = [];
}
diff --git a/MLEB/Translate/tests/phpunit/MessageCollectionTest.php b/MLEB/Translate/tests/phpunit/MessageCollectionTest.php
index e73eb4ff..4d819377 100644
--- a/MLEB/Translate/tests/phpunit/MessageCollectionTest.php
+++ b/MLEB/Translate/tests/phpunit/MessageCollectionTest.php
@@ -23,7 +23,7 @@ class MessageCollectionTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ [ $this, 'getTestGroups' ] ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
@@ -41,8 +41,7 @@ class MessageCollectionTest extends MediaWikiTestCase {
}
public function testMessage() {
- $user = new MockSuperUser();
- $user->setId( 123 );
+ $user = $this->getTestSysop()->getUser();
$title = Title::newFromText( 'MediaWiki:translated/fi' );
$page = WikiPage::factory( $title );
$content = ContentHandler::makeContent( 'pupuliini', $title );
@@ -63,8 +62,8 @@ class MessageCollectionTest extends MediaWikiTestCase {
$this->assertEquals( 'translated', $translated->key() );
$this->assertEquals( 'bunny', $translated->definition() );
$this->assertEquals( 'pupuliini', $translated->translation() );
- $this->assertEquals( 'SuperUser', $translated->getProperty( 'last-translator-text' ) );
- $this->assertEquals( 123, $translated->getProperty( 'last-translator-id' ) );
+ $this->assertEquals( $user->getName(), $translated->getProperty( 'last-translator-text' ) );
+ $this->assertEquals( $user->getId(), $translated->getProperty( 'last-translator-id' ) );
$this->assertEquals(
'translated',
$translated->getProperty( 'status' ),
diff --git a/MLEB/Translate/tests/phpunit/MessageGroupStatesUpdaterJobTest.php b/MLEB/Translate/tests/phpunit/MessageGroupStatesUpdaterJobTest.php
index 078868ce..e96e8bee 100644
--- a/MLEB/Translate/tests/phpunit/MessageGroupStatesUpdaterJobTest.php
+++ b/MLEB/Translate/tests/phpunit/MessageGroupStatesUpdaterJobTest.php
@@ -17,7 +17,7 @@ class MessageGroupStatesUpdaterJobTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ [ $this, 'getTestGroups' ] ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
}
@@ -110,7 +110,7 @@ class MessageGroupStatesUpdaterJobTest extends MediaWikiTestCase {
* This tests fails regularly on WMF CI but haven't been able to reproduce locally.
*/
public function testHooks() {
- $user = new MockSuperUser();
+ $user = $this->getTestSysop()->getUser();
$group = MessageGroups::getGroup( 'group-trans' );
// In the beginning...
diff --git a/MLEB/Translate/tests/phpunit/MessageGroupsTest.php b/MLEB/Translate/tests/phpunit/MessageGroupsTest.php
index 1ab9fad5..2770683c 100644
--- a/MLEB/Translate/tests/phpunit/MessageGroupsTest.php
+++ b/MLEB/Translate/tests/phpunit/MessageGroupsTest.php
@@ -29,7 +29,7 @@ class MessageGroupsTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ 'MessageGroups::getConfiguredGroups' ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
diff --git a/MLEB/Translate/tests/phpunit/MessageIndexRebuildJobTest.php b/MLEB/Translate/tests/phpunit/MessageIndexRebuildJobTest.php
index a756c069..7b77723e 100644
--- a/MLEB/Translate/tests/phpunit/MessageIndexRebuildJobTest.php
+++ b/MLEB/Translate/tests/phpunit/MessageIndexRebuildJobTest.php
@@ -27,7 +27,7 @@ class MessageIndexRebuildJobTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
diff --git a/MLEB/Translate/tests/phpunit/MockSuperUser.php b/MLEB/Translate/tests/phpunit/MockSuperUser.php
deleted file mode 100644
index 0ebe1356..00000000
--- a/MLEB/Translate/tests/phpunit/MockSuperUser.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-
-/**
- * Just call SuperUser when you need to be able to do everything.
- */
-class MockSuperUser extends User {
- protected $id = 666;
-
- public function setId( $id ) {
- $this->id = $id;
- }
-
- public function getId() {
- return $this->id;
- }
-
- public function getName() {
- return 'SuperUser';
- }
-
- public function isAllowed( $right = '' ) {
- return true;
- }
-}
diff --git a/MLEB/Translate/tests/phpunit/PageTranslationTaggingTest.php b/MLEB/Translate/tests/phpunit/PageTranslationTaggingTest.php
index 2e2a6c20..e457aa70 100644
--- a/MLEB/Translate/tests/phpunit/PageTranslationTaggingTest.php
+++ b/MLEB/Translate/tests/phpunit/PageTranslationTaggingTest.php
@@ -18,7 +18,7 @@ class PageTranslationTaggingTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ 'MessageGroups::getTranslatablePages' ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
@@ -95,7 +95,7 @@ class PageTranslationTaggingTest extends MediaWikiTestCase {
}
public function testTranslationPageRestrictions() {
- $superUser = new MockSuperUser();
+ $superUser = $this->getTestSysop()->getUser();
$title = Title::newFromText( 'Translatable page' );
$page = WikiPage::factory( $title );
$content = ContentHandler::makeContent( '<translate>Hello</translate>', $title );
diff --git a/MLEB/Translate/tests/phpunit/SolrTTMServerTest.php b/MLEB/Translate/tests/phpunit/SolrTTMServerTest.php
index ac0a19d6..dbd22df6 100644
--- a/MLEB/Translate/tests/phpunit/SolrTTMServerTest.php
+++ b/MLEB/Translate/tests/phpunit/SolrTTMServerTest.php
@@ -30,7 +30,7 @@ class SolrTTMServerTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ [ $this, 'addGroups' ] ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
diff --git a/MLEB/Translate/tests/phpunit/SpecialPagesTest.php b/MLEB/Translate/tests/phpunit/SpecialPagesTest.php
index 4a412da8..e4bf26ef 100644
--- a/MLEB/Translate/tests/phpunit/SpecialPagesTest.php
+++ b/MLEB/Translate/tests/phpunit/SpecialPagesTest.php
@@ -26,7 +26,7 @@ class SpecialPagesTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
@@ -69,7 +69,7 @@ class SpecialPagesTest extends MediaWikiTestCase {
$this->assertTrue( true, "Special page $name was executed successfully with anon user" );
- $user = new MockSuperUser();
+ $user = $this->getTestSysop()->getUser();
$context->setUser( $user );
$page->setContext( $context );
diff --git a/MLEB/Translate/tests/phpunit/TranslateHooksTest.php b/MLEB/Translate/tests/phpunit/TranslateHooksTest.php
index e591fc81..c711c557 100644
--- a/MLEB/Translate/tests/phpunit/TranslateHooksTest.php
+++ b/MLEB/Translate/tests/phpunit/TranslateHooksTest.php
@@ -25,7 +25,7 @@ class TranslateHooksTest extends MediaWikiLangTestCase {
$wgHooks['TranslatePostInitGroups'] = [ [ $this, 'getTestGroups' ] ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
@@ -44,7 +44,7 @@ class TranslateHooksTest extends MediaWikiLangTestCase {
}
public function testPreventCategorization() {
- $user = new MockSuperUser();
+ $user = $this->getTestSysop()->getUser();
$title = Title::makeTitle( NS_MEDIAWIKI, 'ugakey1/fi' );
$wikipage = WikiPage::factory( $title );
$content = ContentHandler::makeContent( '[[Category:Shouldnotbe]]', $title );
diff --git a/MLEB/Translate/tests/phpunit/TranslationFuzzyUpdaterTest.php b/MLEB/Translate/tests/phpunit/TranslationFuzzyUpdaterTest.php
index ec4368e2..5bf8eff5 100644
--- a/MLEB/Translate/tests/phpunit/TranslationFuzzyUpdaterTest.php
+++ b/MLEB/Translate/tests/phpunit/TranslationFuzzyUpdaterTest.php
@@ -24,7 +24,7 @@ class TranslationFuzzyUpdaterTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ [ $this, 'getTestGroups' ] ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
diff --git a/MLEB/Translate/tests/phpunit/api/ApiQueryMessageGroupsTest.php b/MLEB/Translate/tests/phpunit/api/ApiQueryMessageGroupsTest.php
index 670c2def..4ce7eebe 100644
--- a/MLEB/Translate/tests/phpunit/api/ApiQueryMessageGroupsTest.php
+++ b/MLEB/Translate/tests/phpunit/api/ApiQueryMessageGroupsTest.php
@@ -24,7 +24,7 @@ class ApiQueryMessageGroupsTest extends ApiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ [ $this, 'getTestGroups' ] ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
}
diff --git a/MLEB/Translate/tests/phpunit/api/ApiTranslationReviewTest.php b/MLEB/Translate/tests/phpunit/api/ApiTranslationReviewTest.php
index 8266c0d4..930dad0e 100644
--- a/MLEB/Translate/tests/phpunit/api/ApiTranslationReviewTest.php
+++ b/MLEB/Translate/tests/phpunit/api/ApiTranslationReviewTest.php
@@ -16,12 +16,16 @@ class ApiTranslationReviewTest extends MediaWikiTestCase {
global $wgHooks;
$this->setMwGlobals( [
'wgHooks' => $wgHooks,
- 'wgGroupPermissions' => [],
+ 'wgGroupPermissions' => [
+ 'sysop' => [
+ 'translate-messagereview' => true,
+ ],
+ ],
'wgTranslateMessageNamespaces' => [ NS_MEDIAWIKI ],
] );
$wgHooks['TranslatePostInitGroups'] = [ [ $this, 'getTestGroups' ] ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
@@ -40,13 +44,11 @@ class ApiTranslationReviewTest extends MediaWikiTestCase {
}
public function testgetReviewBlockers() {
- $superUser1 = new MockSuperUser();
- $superUser1->setId( 1 );
+ $superUser1 = $this->getMutableTestUser( [ 'sysop', 'bureaucrat' ] )->getUser();
- $superUser2 = new MockSuperUser();
- $superUser2->setId( 2 );
+ $superUser2 = $this->getMutableTestUser( [ 'sysop', 'bureaucrat' ] )->getUser();
- $plainUser = User::newFromName( 'PlainUser' );
+ $plainUser = $this->getMutableTestUser()->getUser();
$title = Title::makeTitle( NS_MEDIAWIKI, 'Ugakey1/fi' );
$content = ContentHandler::makeContent( 'trans1', $title );
diff --git a/MLEB/Translate/tests/phpunit/tag/PageTranslationHooksTest.php b/MLEB/Translate/tests/phpunit/tag/PageTranslationHooksTest.php
index 375458b0..5aca5862 100644
--- a/MLEB/Translate/tests/phpunit/tag/PageTranslationHooksTest.php
+++ b/MLEB/Translate/tests/phpunit/tag/PageTranslationHooksTest.php
@@ -25,7 +25,7 @@ class PageTranslationHooksTest extends MediaWikiTestCase {
$wgHooks['TranslatePostInitGroups'] = [ 'MessageGroups::getTranslatablePages' ];
$mg = MessageGroups::singleton();
- $mg->setCache( wfGetCache( 'hash' ) );
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
@@ -36,7 +36,7 @@ class PageTranslationHooksTest extends MediaWikiTestCase {
global $wgParser;
// Setup objects
- $superUser = new MockSuperUser();
+ $superUser = $this->getTestSysop()->getUser();
$translatablePageTitle = Title::newFromText( 'Vuosaari' );
$page = WikiPage::factory( $translatablePageTitle );
$text = '<translate>pupu</translate>';
diff --git a/MLEB/Translate/tests/qunit/.eslintrc.json b/MLEB/Translate/tests/qunit/.eslintrc.json
new file mode 100644
index 00000000..348a1b7f
--- /dev/null
+++ b/MLEB/Translate/tests/qunit/.eslintrc.json
@@ -0,0 +1,6 @@
+{
+ "extends": [
+ "wikimedia/qunit",
+ "../../.eslintrc.json"
+ ]
+}
diff --git a/MLEB/Translate/tests/qunit/ext.translate.parsers.test.js b/MLEB/Translate/tests/qunit/ext.translate.parsers.test.js
index 004d7dff..cc86ed1f 100644
--- a/MLEB/Translate/tests/qunit/ext.translate.parsers.test.js
+++ b/MLEB/Translate/tests/qunit/ext.translate.parsers.test.js
@@ -4,7 +4,7 @@
* @license GPL-2.0-or-later
*/
-( function ( $, mw ) {
+( function () {
'use strict';
QUnit.module( 'ext.translate.parsers', QUnit.newMwEnvironment() );
@@ -13,21 +13,21 @@
mw.config.set( 'wgArticlePath', '/wiki/$1' );
assert.strictEqual(
- 'This page is [in English]',
mw.translate.formatMessageGently( 'This page is [in English]' ),
+ 'This page is [in English]',
'Brackets without protocol doesn\'t make a link'
);
assert.strictEqual(
- 'This page has <a href="https://www.mediawiki.org">a link</a>',
mw.translate.formatMessageGently( 'This page has [https://www.mediawiki.org a link]' ),
+ 'This page has <a href="https://www.mediawiki.org">a link</a>',
'Brackets with https:// protocol creates a link'
);
assert.strictEqual(
- 'No kun <a href="/wiki/m:MassMessage">m:MassMessage</a> ja plum <a href="/wiki/m:">Meta-Wiki</a>.',
mw.translate.formatMessageGently( 'No kun [[m:MassMessage]] ja plum [[m:|Meta-Wiki]].' ),
+ 'No kun <a href="/wiki/m:MassMessage">m:MassMessage</a> ja plum <a href="/wiki/m:">Meta-Wiki</a>.',
'Link parsing is non-greedy'
);
} );
-}( jQuery, mediaWiki ) );
+}() );
diff --git a/MLEB/Translate/tests/qunit/ext.translate.special.pagemigration.test.js b/MLEB/Translate/tests/qunit/ext.translate.special.pagemigration.test.js
index e5c97ae5..f2218ba2 100644
--- a/MLEB/Translate/tests/qunit/ext.translate.special.pagemigration.test.js
+++ b/MLEB/Translate/tests/qunit/ext.translate.special.pagemigration.test.js
@@ -4,7 +4,7 @@
* @license GPL-2.0-or-later
*/
-( function ( $, mw ) {
+( function () {
'use strict';
QUnit.module( 'ext.translate.special.pagemigration', QUnit.newMwEnvironment( {
@@ -20,7 +20,7 @@
done = assert.async();
mw.translate.getSourceUnits( 'Help:Special pages' ).done( function ( sourceUnits ) {
- assert.strictEqual( 1, sourceUnits.length, 'Source units retrieved' );
+ assert.strictEqual( sourceUnits.length, 1, 'Source units retrieved' );
done();
} );
@@ -34,7 +34,7 @@
done = assert.async();
mw.translate.getFuzzyTimestamp( 'ugagagagagaga/uga' ).fail( function ( timestamp ) {
- assert.strictEqual( undefined, timestamp, 'Page does not exist' );
+ assert.strictEqual( timestamp, undefined, 'Page does not exist' );
done();
} );
@@ -49,7 +49,7 @@
done = assert.async();
mw.translate.getFuzzyTimestamp( 'Help:Special pages/fr' ).done( function ( timestamp ) {
- assert.strictEqual( '2014-02-18T20:59:57.000Z', timestamp, 'Fuzzy timestamp retrieved' );
+ assert.strictEqual( timestamp, '2014-02-18T20:59:57.000Z', 'Fuzzy timestamp retrieved' );
done();
} );
@@ -65,7 +65,7 @@
done = assert.async();
mw.translate.splitTranslationPage( '2014-02-18T20:59:57.000Z', 'Help:Special pages/fr' )
.done( function ( translationUnits ) {
- assert.strictEqual( 3, translationUnits.length, 'Translation page split into units' );
+ assert.strictEqual( translationUnits.length, 3, 'Translation page split into units' );
done();
} );
@@ -91,9 +91,9 @@
result2 = [ 'abc\nlmn\n', '==123==', 'pqr', '', '', '==456==' ];
translationUnits1 = mw.translate.alignHeaders( sourceUnits, translationUnits1 );
- assert.deepEqual( translationUnits1, result1, 'h2 headers aligned without merging' );
+ assert.deepEqual( result1, translationUnits1, 'h2 headers aligned without merging' );
translationUnits2 = mw.translate.alignHeaders( sourceUnits, translationUnits2 );
- assert.deepEqual( translationUnits2, result2, 'h2 headers aligned with merging' );
+ assert.deepEqual( result2, translationUnits2, 'h2 headers aligned with merging' );
} );
-}( jQuery, mediaWiki ) );
+}() );