From d417de70fcf39e0a7a15ba780b597914d16ca0f7 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 12 Mar 2014 18:12:23 +0100 Subject: Update to MediaWiki 1.22.4 --- tests/qunit/data/callMwLoaderTestCallback.js | 1 - tests/qunit/data/generateJqueryMsgData.php | 150 -------- tests/qunit/data/load.mock.php | 59 ---- tests/qunit/data/mediawiki.jqueryMsg.data.js | 492 --------------------------- tests/qunit/data/qunitOkCall.js | 2 - tests/qunit/data/styleTest.css.php | 61 ---- tests/qunit/data/testrunner.js | 431 ----------------------- 7 files changed, 1196 deletions(-) delete mode 100644 tests/qunit/data/callMwLoaderTestCallback.js delete mode 100644 tests/qunit/data/generateJqueryMsgData.php delete mode 100644 tests/qunit/data/load.mock.php delete mode 100644 tests/qunit/data/mediawiki.jqueryMsg.data.js delete mode 100644 tests/qunit/data/qunitOkCall.js delete mode 100644 tests/qunit/data/styleTest.css.php delete mode 100644 tests/qunit/data/testrunner.js (limited to 'tests/qunit/data') diff --git a/tests/qunit/data/callMwLoaderTestCallback.js b/tests/qunit/data/callMwLoaderTestCallback.js deleted file mode 100644 index dd034115..00000000 --- a/tests/qunit/data/callMwLoaderTestCallback.js +++ /dev/null @@ -1 +0,0 @@ -mediaWiki.loader.testCallback(); diff --git a/tests/qunit/data/generateJqueryMsgData.php b/tests/qunit/data/generateJqueryMsgData.php deleted file mode 100644 index 12e5a2dc..00000000 --- a/tests/qunit/data/generateJqueryMsgData.php +++ /dev/null @@ -1,150 +0,0 @@ - - QUnit.test( 'Output matches PHP parser', mw.libs.phpParserData.tests.length, function ( assert ) { - mw.messages.set( mw.libs.phpParserData.messages ); - $.each( mw.libs.phpParserData.tests, function ( i, test ) { - QUnit.stop(); - getMwLanguage( test.lang, function ( langClass ) { - var parser = new mw.jqueryMsg.parser( { language: langClass } ); - assert.equal( - parser.parse( test.key, test.args ).html(), - test.result, - test.name - ); - QUnit.start(); - } ); - } ); - }); - * - * - * @example Jasmine - * - describe( 'match output to output from PHP parser', function () { - mw.messages.set( mw.libs.phpParserData.messages ); - $.each( mw.libs.phpParserData.tests, function ( i, test ) { - it( 'should parse ' + test.name, function () { - var langClass; - runs( function () { - getMwLanguage( test.lang, function ( gotIt ) { - langClass = gotIt; - }); - }); - waitsFor( function () { - return langClass !== undefined; - }, 'Language class should be loaded', 1000 ); - runs( function () { - console.log( test.lang, 'running tests' ); - var parser = new mw.jqueryMsg.parser( { language: langClass } ); - expect( - parser.parse( test.key, test.args ).html() - ).toEqual( test.result ); - } ); - } ); - } ); - } ); - * - */ - -require __DIR__ . '/../../../maintenance/Maintenance.php'; - -class GenerateJqueryMsgData extends Maintenance { - - static $keyToTestArgs = array( - 'undelete_short' => array( - array( 0 ), - array( 1 ), - array( 2 ), - array( 5 ), - array( 21 ), - array( 101 ) - ), - 'category-subcat-count' => array( - array( 0, 10 ), - array( 1, 1 ), - array( 1, 2 ), - array( 3, 30 ) - ) - ); - - public function __construct() { - parent::__construct(); - $this->mDescription = 'Create a specification for message parsing ini JSON format'; - // add any other options here - } - - public function execute() { - list( $messages, $tests ) = $this->getMessagesAndTests(); - $this->writeJavascriptFile( $messages, $tests, __DIR__ . '/mediawiki.jqueryMsg.data.js' ); - } - - private function getMessagesAndTests() { - $messages = array(); - $tests = array(); - foreach ( array( 'en', 'fr', 'ar', 'jp', 'zh' ) as $languageCode ) { - foreach ( self::$keyToTestArgs as $key => $testArgs ) { - foreach ( $testArgs as $args ) { - // Get the raw message, without any transformations. - $template = wfMessage( $key )->inLanguage( $languageCode )->plain(); - - // Get the magic-parsed version with args. - $result = wfMessage( $key, $args )->inLanguage( $languageCode )->text(); - - // Record the template, args, language, and expected result - // fake multiple languages by flattening them together. - $langKey = $languageCode . '_' . $key; - $messages[$langKey] = $template; - $tests[] = array( - 'name' => $languageCode . ' ' . $key . ' ' . join( ',', $args ), - 'key' => $langKey, - 'args' => $args, - 'result' => $result, - 'lang' => $languageCode - ); - } - } - } - return array( $messages, $tests ); - } - - private function writeJavascriptFile( $messages, $tests, $dataSpecFile ) { - $phpParserData = array( - 'messages' => $messages, - 'tests' => $tests, - ); - - $output = - "// This file stores the output from the PHP parser for various messages, arguments,\n" - . "// languages, and parser modes. Intended for use by a unit test framework by looping\n" - . "// through the object and comparing its parser return value with the 'result' property.\n" - . '// Last generated with ' . basename( __FILE__ ) . ' at ' . gmdate( 'r' ) . "\n" - // This file will contain unquoted JSON strings as javascript native object literals, - // flip the quotemark convention for this file. - . "/*jshint quotmark: double */\n" - . "\n" - . 'mediaWiki.libs.phpParserData = ' . FormatJson::encode( $phpParserData, true ) . ";\n"; - - $fp = file_put_contents( $dataSpecFile, $output ); - if ( $fp === false ) { - die( "Couldn't write to $dataSpecFile." ); - } - } -} - -$maintClass = "GenerateJqueryMsgData"; -require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/tests/qunit/data/load.mock.php b/tests/qunit/data/load.mock.php deleted file mode 100644 index f6eff77a..00000000 --- a/tests/qunit/data/load.mock.php +++ /dev/null @@ -1,59 +0,0 @@ - " -mw.loader.implement( 'testUsesMissing', function () { - QUnit.ok( false, 'Module test.usesMissing script should not run.'); - QUnit.start(); -}, {}, {}); -", - - 'testUsesNestedMissing' => " -mw.loader.implement( 'testUsesNestedMissing', function () { - QUnit.ok( false, 'Module testUsesNestedMissing script should not run.'); -}, {}, {}); -", -); - -$response = ''; - -// Only support for non-encoded module names, full module names expected -if ( isset( $_GET['modules'] ) ) { - $modules = explode( ',', $_GET['modules'] ); - foreach ( $modules as $module ) { - if ( isset( $moduleImplementations[$module] ) ) { - $response .= $moduleImplementations[$module]; - } else { - $response .= Xml::encodeJsCall( 'mw.loader.state', array( $module, 'missing' ), true ); - } - } -} - -echo $response; diff --git a/tests/qunit/data/mediawiki.jqueryMsg.data.js b/tests/qunit/data/mediawiki.jqueryMsg.data.js deleted file mode 100644 index 776ee24f..00000000 --- a/tests/qunit/data/mediawiki.jqueryMsg.data.js +++ /dev/null @@ -1,492 +0,0 @@ -// This file stores the output from the PHP parser for various messages, arguments, -// languages, and parser modes. Intended for use by a unit test framework by looping -// through the object and comparing its parser return value with the 'result' property. -// Last generated with generateJqueryMsgData.php at Sat, 03 Nov 2012 21:32:01 +0000 -/*jshint quotmark: double */ - -mediaWiki.libs.phpParserData = { - "messages": { - "en_undelete_short": "Undelete {{PLURAL:$1|one edit|$1 edits}}", - "en_category-subcat-count": "{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}", - "fr_undelete_short": "Restaurer $1 modification{{PLURAL:$1||s}}", - "fr_category-subcat-count": "Cette cat\u00e9gorie comprend {{PLURAL:$2|la sous-cat\u00e9gorie|$2 sous-cat\u00e9gories, dont {{PLURAL:$1|celle|les $1}}}} ci-dessous.", - "ar_undelete_short": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 {{PLURAL:$1|\u062a\u0639\u062f\u064a\u0644 \u0648\u0627\u062d\u062f|\u062a\u0639\u062f\u064a\u0644\u064a\u0646|$1 \u062a\u0639\u062f\u064a\u0644\u0627\u062a|$1 \u062a\u0639\u062f\u064a\u0644|$1 \u062a\u0639\u062f\u064a\u0644\u0627}}", - "ar_category-subcat-count": "{{PLURAL:$2|\u0644\u0627 \u062a\u0635\u0627\u0646\u064a\u0641 \u0641\u0631\u0639\u064a\u0629 \u0641\u064a \u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641|\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a \u0627\u0644\u062a\u0627\u0644\u064a \u0641\u0642\u0637.|\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 {{PLURAL:$1||\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a|\u0647\u0630\u064a\u0646 \u0627\u0644\u062a\u0635\u0646\u064a\u0641\u064a\u0646 \u0627\u0644\u0641\u0631\u0639\u064a\u064a\u0646|\u0647\u0630\u0647 \u0627\u0644$1 \u062a\u0635\u0627\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a\u0629|\u0647\u0630\u0647 \u0627\u0644$1 \u062a\u0635\u0646\u064a\u0641\u0627 \u0641\u0631\u0639\u064a\u0627|\u0647\u0630\u0647 \u0627\u0644$1 \u062a\u0635\u0646\u064a\u0641 \u0641\u0631\u0639\u064a}}\u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a $2.}}", - "jp_undelete_short": "Undelete {{PLURAL:$1|one edit|$1 edits}}", - "jp_category-subcat-count": "{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}", - "zh_undelete_short": "\u6062\u590d$1\u4e2a\u88ab\u5220\u9664\u7684\u7f16\u8f91", - "zh_category-subcat-count": "{{PLURAL:$2|\u672c\u5206\u7c7b\u53ea\u6709\u4e0b\u5217\u4e00\u4e2a\u5b50\u5206\u7c7b\u3002|\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u5217$1\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171$2\u4e2a\u5b50\u5206\u7c7b\u3002}}" - }, - "tests": [ - { - "name": "en undelete_short 0", - "key": "en_undelete_short", - "args": [ - 0 - ], - "result": "Undelete 0 edits", - "lang": "en" - }, - { - "name": "en undelete_short 1", - "key": "en_undelete_short", - "args": [ - 1 - ], - "result": "Undelete one edit", - "lang": "en" - }, - { - "name": "en undelete_short 2", - "key": "en_undelete_short", - "args": [ - 2 - ], - "result": "Undelete 2 edits", - "lang": "en" - }, - { - "name": "en undelete_short 5", - "key": "en_undelete_short", - "args": [ - 5 - ], - "result": "Undelete 5 edits", - "lang": "en" - }, - { - "name": "en undelete_short 21", - "key": "en_undelete_short", - "args": [ - 21 - ], - "result": "Undelete 21 edits", - "lang": "en" - }, - { - "name": "en undelete_short 101", - "key": "en_undelete_short", - "args": [ - 101 - ], - "result": "Undelete 101 edits", - "lang": "en" - }, - { - "name": "en category-subcat-count 0,10", - "key": "en_category-subcat-count", - "args": [ - 0, - 10 - ], - "result": "This category has the following 0 subcategories, out of 10 total.", - "lang": "en" - }, - { - "name": "en category-subcat-count 1,1", - "key": "en_category-subcat-count", - "args": [ - 1, - 1 - ], - "result": "This category has only the following subcategory.", - "lang": "en" - }, - { - "name": "en category-subcat-count 1,2", - "key": "en_category-subcat-count", - "args": [ - 1, - 2 - ], - "result": "This category has the following subcategory, out of 2 total.", - "lang": "en" - }, - { - "name": "en category-subcat-count 3,30", - "key": "en_category-subcat-count", - "args": [ - 3, - 30 - ], - "result": "This category has the following 3 subcategories, out of 30 total.", - "lang": "en" - }, - { - "name": "fr undelete_short 0", - "key": "fr_undelete_short", - "args": [ - 0 - ], - "result": "Restaurer 0 modification", - "lang": "fr" - }, - { - "name": "fr undelete_short 1", - "key": "fr_undelete_short", - "args": [ - 1 - ], - "result": "Restaurer 1 modification", - "lang": "fr" - }, - { - "name": "fr undelete_short 2", - "key": "fr_undelete_short", - "args": [ - 2 - ], - "result": "Restaurer 2 modifications", - "lang": "fr" - }, - { - "name": "fr undelete_short 5", - "key": "fr_undelete_short", - "args": [ - 5 - ], - "result": "Restaurer 5 modifications", - "lang": "fr" - }, - { - "name": "fr undelete_short 21", - "key": "fr_undelete_short", - "args": [ - 21 - ], - "result": "Restaurer 21 modifications", - "lang": "fr" - }, - { - "name": "fr undelete_short 101", - "key": "fr_undelete_short", - "args": [ - 101 - ], - "result": "Restaurer 101 modifications", - "lang": "fr" - }, - { - "name": "fr category-subcat-count 0,10", - "key": "fr_category-subcat-count", - "args": [ - 0, - 10 - ], - "result": "Cette cat\u00e9gorie comprend 10 sous-cat\u00e9gories, dont celle ci-dessous.", - "lang": "fr" - }, - { - "name": "fr category-subcat-count 1,1", - "key": "fr_category-subcat-count", - "args": [ - 1, - 1 - ], - "result": "Cette cat\u00e9gorie comprend la sous-cat\u00e9gorie ci-dessous.", - "lang": "fr" - }, - { - "name": "fr category-subcat-count 1,2", - "key": "fr_category-subcat-count", - "args": [ - 1, - 2 - ], - "result": "Cette cat\u00e9gorie comprend 2 sous-cat\u00e9gories, dont celle ci-dessous.", - "lang": "fr" - }, - { - "name": "fr category-subcat-count 3,30", - "key": "fr_category-subcat-count", - "args": [ - 3, - 30 - ], - "result": "Cette cat\u00e9gorie comprend 30 sous-cat\u00e9gories, dont les 3 ci-dessous.", - "lang": "fr" - }, - { - "name": "ar undelete_short 0", - "key": "ar_undelete_short", - "args": [ - 0 - ], - "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 \u062a\u0639\u062f\u064a\u0644 \u0648\u0627\u062d\u062f", - "lang": "ar" - }, - { - "name": "ar undelete_short 1", - "key": "ar_undelete_short", - "args": [ - 1 - ], - "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 \u062a\u0639\u062f\u064a\u0644\u064a\u0646", - "lang": "ar" - }, - { - "name": "ar undelete_short 2", - "key": "ar_undelete_short", - "args": [ - 2 - ], - "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 2 \u062a\u0639\u062f\u064a\u0644\u0627\u062a", - "lang": "ar" - }, - { - "name": "ar undelete_short 5", - "key": "ar_undelete_short", - "args": [ - 5 - ], - "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 5 \u062a\u0639\u062f\u064a\u0644", - "lang": "ar" - }, - { - "name": "ar undelete_short 21", - "key": "ar_undelete_short", - "args": [ - 21 - ], - "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 21 \u062a\u0639\u062f\u064a\u0644\u0627", - "lang": "ar" - }, - { - "name": "ar undelete_short 101", - "key": "ar_undelete_short", - "args": [ - 101 - ], - "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 101 \u062a\u0639\u062f\u064a\u0644\u0627", - "lang": "ar" - }, - { - "name": "ar category-subcat-count 0,10", - "key": "ar_category-subcat-count", - "args": [ - 0, - 10 - ], - "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a 10.", - "lang": "ar" - }, - { - "name": "ar category-subcat-count 1,1", - "key": "ar_category-subcat-count", - "args": [ - 1, - 1 - ], - "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a \u0627\u0644\u062a\u0627\u0644\u064a \u0641\u0642\u0637.", - "lang": "ar" - }, - { - "name": "ar category-subcat-count 1,2", - "key": "ar_category-subcat-count", - "args": [ - 1, - 2 - ], - "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a\u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a 2.", - "lang": "ar" - }, - { - "name": "ar category-subcat-count 3,30", - "key": "ar_category-subcat-count", - "args": [ - 3, - 30 - ], - "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0647\u0630\u0647 \u0627\u06443 \u062a\u0635\u0627\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a\u0629\u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a 30.", - "lang": "ar" - }, - { - "name": "jp undelete_short 0", - "key": "jp_undelete_short", - "args": [ - 0 - ], - "result": "Undelete 0 edits", - "lang": "jp" - }, - { - "name": "jp undelete_short 1", - "key": "jp_undelete_short", - "args": [ - 1 - ], - "result": "Undelete one edit", - "lang": "jp" - }, - { - "name": "jp undelete_short 2", - "key": "jp_undelete_short", - "args": [ - 2 - ], - "result": "Undelete 2 edits", - "lang": "jp" - }, - { - "name": "jp undelete_short 5", - "key": "jp_undelete_short", - "args": [ - 5 - ], - "result": "Undelete 5 edits", - "lang": "jp" - }, - { - "name": "jp undelete_short 21", - "key": "jp_undelete_short", - "args": [ - 21 - ], - "result": "Undelete 21 edits", - "lang": "jp" - }, - { - "name": "jp undelete_short 101", - "key": "jp_undelete_short", - "args": [ - 101 - ], - "result": "Undelete 101 edits", - "lang": "jp" - }, - { - "name": "jp category-subcat-count 0,10", - "key": "jp_category-subcat-count", - "args": [ - 0, - 10 - ], - "result": "This category has the following 0 subcategories, out of 10 total.", - "lang": "jp" - }, - { - "name": "jp category-subcat-count 1,1", - "key": "jp_category-subcat-count", - "args": [ - 1, - 1 - ], - "result": "This category has only the following subcategory.", - "lang": "jp" - }, - { - "name": "jp category-subcat-count 1,2", - "key": "jp_category-subcat-count", - "args": [ - 1, - 2 - ], - "result": "This category has the following subcategory, out of 2 total.", - "lang": "jp" - }, - { - "name": "jp category-subcat-count 3,30", - "key": "jp_category-subcat-count", - "args": [ - 3, - 30 - ], - "result": "This category has the following 3 subcategories, out of 30 total.", - "lang": "jp" - }, - { - "name": "zh undelete_short 0", - "key": "zh_undelete_short", - "args": [ - 0 - ], - "result": "\u6062\u590d0\u4e2a\u88ab\u5220\u9664\u7684\u7f16\u8f91", - "lang": "zh" - }, - { - "name": "zh undelete_short 1", - "key": "zh_undelete_short", - "args": [ - 1 - ], - "result": "\u6062\u590d1\u4e2a\u88ab\u5220\u9664\u7684\u7f16\u8f91", - "lang": "zh" - }, - { - "name": "zh undelete_short 2", - "key": "zh_undelete_short", - "args": [ - 2 - ], - "result": "\u6062\u590d2\u4e2a\u88ab\u5220\u9664\u7684\u7f16\u8f91", - "lang": "zh" - }, - { - "name": "zh undelete_short 5", - "key": "zh_undelete_short", - "args": [ - 5 - ], - "result": "\u6062\u590d5\u4e2a\u88ab\u5220\u9664\u7684\u7f16\u8f91", - "lang": "zh" - }, - { - "name": "zh undelete_short 21", - "key": "zh_undelete_short", - "args": [ - 21 - ], - "result": "\u6062\u590d21\u4e2a\u88ab\u5220\u9664\u7684\u7f16\u8f91", - "lang": "zh" - }, - { - "name": "zh undelete_short 101", - "key": "zh_undelete_short", - "args": [ - 101 - ], - "result": "\u6062\u590d101\u4e2a\u88ab\u5220\u9664\u7684\u7f16\u8f91", - "lang": "zh" - }, - { - "name": "zh category-subcat-count 0,10", - "key": "zh_category-subcat-count", - "args": [ - 0, - 10 - ], - "result": "\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52170\u4e2a\u5b50\u5206\u7c7b\uff0c\u517110\u4e2a\u5b50\u5206\u7c7b\u3002", - "lang": "zh" - }, - { - "name": "zh category-subcat-count 1,1", - "key": "zh_category-subcat-count", - "args": [ - 1, - 1 - ], - "result": "\u672c\u5206\u7c7b\u53ea\u6709\u4e0b\u5217\u4e00\u4e2a\u5b50\u5206\u7c7b\u3002", - "lang": "zh" - }, - { - "name": "zh category-subcat-count 1,2", - "key": "zh_category-subcat-count", - "args": [ - 1, - 2 - ], - "result": "\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52171\u4e2a\u5b50\u5206\u7c7b\uff0c\u51712\u4e2a\u5b50\u5206\u7c7b\u3002", - "lang": "zh" - }, - { - "name": "zh category-subcat-count 3,30", - "key": "zh_category-subcat-count", - "args": [ - 3, - 30 - ], - "result": "\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52173\u4e2a\u5b50\u5206\u7c7b\uff0c\u517130\u4e2a\u5b50\u5206\u7c7b\u3002", - "lang": "zh" - } - ] -}; diff --git a/tests/qunit/data/qunitOkCall.js b/tests/qunit/data/qunitOkCall.js deleted file mode 100644 index 3ed5514e..00000000 --- a/tests/qunit/data/qunitOkCall.js +++ /dev/null @@ -1,2 +0,0 @@ -QUnit.start(); -QUnit.assert.ok( true, 'Successfully loaded!' ); diff --git a/tests/qunit/data/styleTest.css.php b/tests/qunit/data/styleTest.css.php deleted file mode 100644 index 0e845811..00000000 --- a/tests/qunit/data/styleTest.css.php +++ /dev/null @@ -1,61 +0,0 @@ - - */ - QUnit.newMwEnvironment = ( function () { - var log, liveConfig, liveMessages; - - liveConfig = mw.config.values; - liveMessages = mw.messages.values; - - function freshConfigCopy( custom ) { - // Tests should mock all factors that directly influence the tested code. - // For backwards compatibility though we set mw.config to a copy of the live config - // and extend it with the (optionally) given custom settings for this test - // (instead of starting blank with only the given custmo settings). - // This is a shallow copy, so we don't end up with settings taking an array value - // extended with the custom settings - setting a config property means you override it, - // not extend it. - return $.extend( {}, liveConfig, custom ); - } - - function freshMessagesCopy( custom ) { - return $.extend( /*deep=*/true, {}, liveMessages, custom ); - } - - log = QUnit.urlParams.mwlogenv ? mw.log : function () {}; - - return function ( localEnv ) { - localEnv = $.extend( { - // QUnit - setup: $.noop, - teardown: $.noop, - // MediaWiki - config: {}, - messages: {} - }, localEnv ); - - return { - setup: function () { - log( 'MwEnvironment> SETUP for "' + QUnit.config.current.module - + ': ' + QUnit.config.current.testName + '"' ); - - // Greetings, mock environment! - mw.config.values = freshConfigCopy( localEnv.config ); - mw.messages.values = freshMessagesCopy( localEnv.messages ); - - localEnv.setup(); - }, - - teardown: function () { - log( 'MwEnvironment> TEARDOWN for "' + QUnit.config.current.module - + ': ' + QUnit.config.current.testName + '"' ); - - localEnv.teardown(); - - // Farewell, mock environment! - mw.config.values = liveConfig; - mw.messages.values = liveMessages; - } - }; - }; - }() ); - - // $.when stops as soon as one fails, which makes sense in most - // practical scenarios, but not in a unit test where we really do - // need to wait until all of them are finished. - QUnit.whenPromisesComplete = function () { - var altPromises = []; - - $.each( arguments, function ( i, arg ) { - var alt = $.Deferred(); - altPromises.push( alt ); - - // Whether this one fails or not, forwards it to - // the 'done' (resolve) callback of the alternative promise. - arg.always( alt.resolve ); - } ); - - return $.when.apply( $, altPromises ); - }; - - /** - * Recursively convert a node to a plain object representing its structure. - * Only considers attributes and contents (elements and text nodes). - * Attribute values are compared strictly and not normalised. - * - * @param {Node} node - * @return {Object|string} Plain JavaScript value representing the node. - */ - function getDomStructure( node ) { - var $node, children, processedChildren, i, len, el; - $node = $( node ); - if ( node.nodeType === ELEMENT_NODE ) { - children = $node.contents(); - processedChildren = []; - for ( i = 0, len = children.length; i < len; i++ ) { - el = children[i]; - if ( el.nodeType === ELEMENT_NODE || el.nodeType === TEXT_NODE ) { - processedChildren.push( getDomStructure( el ) ); - } - } - - return { - tagName: node.tagName, - attributes: $node.getAttrs(), - contents: processedChildren - }; - } else { - // Should be text node - return $node.text(); - } - } - - /** - * Gets structure of node for this HTML. - * - * @param {string} html HTML markup for one or more nodes. - */ - function getHtmlStructure( html ) { - var el = $( '
' ).append( html )[0]; - return getDomStructure( el ); - } - - /** - * Add-on assertion helpers - */ - // Define the add-ons - addons = { - - // Expect boolean true - assertTrue: function ( actual, message ) { - QUnit.push( actual === true, actual, true, message ); - }, - - // Expect boolean false - assertFalse: function ( actual, message ) { - QUnit.push( actual === false, actual, false, message ); - }, - - // Expect numerical value less than X - lt: function ( actual, expected, message ) { - QUnit.push( actual < expected, actual, 'less than ' + expected, message ); - }, - - // Expect numerical value less than or equal to X - ltOrEq: function ( actual, expected, message ) { - QUnit.push( actual <= expected, actual, 'less than or equal to ' + expected, message ); - }, - - // Expect numerical value greater than X - gt: function ( actual, expected, message ) { - QUnit.push( actual > expected, actual, 'greater than ' + expected, message ); - }, - - // Expect numerical value greater than or equal to X - gtOrEq: function ( actual, expected, message ) { - QUnit.push( actual >= expected, actual, 'greater than or equal to ' + expected, message ); - }, - - /** - * Asserts that two HTML strings are structurally equivalent. - * - * @param {string} actualHtml Actual HTML markup. - * @param {string} expectedHtml Expected HTML markup - * @param {string} message Assertion message. - */ - htmlEqual: function ( actualHtml, expectedHtml, message ) { - var actual = getHtmlStructure( actualHtml ), - expected = getHtmlStructure( expectedHtml ); - - QUnit.push( - QUnit.equiv( - actual, - expected - ), - actual, - expected, - message - ); - }, - - /** - * Asserts that two HTML strings are not structurally equivalent. - * - * @param {string} actualHtml Actual HTML markup. - * @param {string} expectedHtml Expected HTML markup. - * @param {string} message Assertion message. - */ - notHtmlEqual: function ( actualHtml, expectedHtml, message ) { - var actual = getHtmlStructure( actualHtml ), - expected = getHtmlStructure( expectedHtml ); - - QUnit.push( - !QUnit.equiv( - actual, - expected - ), - actual, - expected, - message - ); - } - }; - - $.extend( QUnit.assert, addons ); - - /** - * Small test suite to confirm proper functionality of the utilities and - * initializations defined above in this file. - */ - envExecCount = 0; - QUnit.module( 'mediawiki.tests.qunit.testrunner', QUnit.newMwEnvironment( { - setup: function () { - envExecCount += 1; - this.mwHtmlLive = mw.html; - mw.html = { - escape: function () { - return 'mocked-' + envExecCount; - } - }; - }, - teardown: function () { - mw.html = this.mwHtmlLive; - }, - config: { - testVar: 'foo' - }, - messages: { - testMsg: 'Foo.' - } - } ) ); - - QUnit.test( 'Setup', 3, function ( assert ) { - assert.equal( mw.html.escape( 'foo' ), 'mocked-1', 'extra setup() callback was ran.' ); - assert.equal( mw.config.get( 'testVar' ), 'foo', 'config object applied' ); - assert.equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object applied' ); - - mw.config.set( 'testVar', 'bar' ); - mw.messages.set( 'testMsg', 'Bar.' ); - } ); - - QUnit.test( 'Teardown', 3, function ( assert ) { - assert.equal( mw.html.escape( 'foo' ), 'mocked-2', 'extra setup() callback was re-ran.' ); - assert.equal( mw.config.get( 'testVar' ), 'foo', 'config object restored and re-applied after test()' ); - assert.equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object restored and re-applied after test()' ); - } ); - - QUnit.test( 'Loader status', 2, function ( assert ) { - var i, len, state, - modules = mw.loader.getModuleNames(), - error = [], - missing = []; - - for ( i = 0, len = modules.length; i < len; i++ ) { - state = mw.loader.getState( modules[i] ); - if ( state === 'error' ) { - error.push( modules[i] ); - } else if ( state === 'missing' ) { - missing.push( modules[i] ); - } - } - - assert.deepEqual( error, [], 'Modules in error state' ); - assert.deepEqual( missing, [], 'Modules in missing state' ); - } ); - - QUnit.test( 'htmlEqual', 8, function ( assert ) { - assert.htmlEqual( - '

Child paragraph with A link

Regular textA span
', - '

Child paragraph with A link

Regular textA span
', - 'Attribute order, spacing and quotation marks (equal)' - ); - - assert.notHtmlEqual( - '

Child paragraph with A link

Regular textA span
', - '

Child paragraph with A link

Regular textA span
', - 'Attribute order, spacing and quotation marks (not equal)' - ); - - assert.htmlEqual( - '', - '', - 'Multiple root nodes (equal)' - ); - - assert.notHtmlEqual( - '', - '', - 'Multiple root nodes (not equal, last label node is different)' - ); - - assert.htmlEqual( - 'fo"o
b>ar', - 'fo"o
b>ar', - 'Extra escaping is equal' - ); - assert.notHtmlEqual( - 'foo<br/>bar', - 'foo
bar', - 'Text escaping (not equal)' - ); - - assert.htmlEqual( - 'fooexamplebar', - 'fooexamplebar', - 'Outer text nodes are compared (equal)' - ); - - assert.notHtmlEqual( - 'fooexamplebar', - 'fooexamplequux', - 'Outer text nodes are compared (last text node different)' - ); - - } ); - - QUnit.module( 'mediawiki.tests.qunit.testrunner-after', QUnit.newMwEnvironment() ); - - QUnit.test( 'Teardown', 3, function ( assert ) { - assert.equal( mw.html.escape( '<' ), '<', 'extra teardown() callback was ran.' ); - assert.equal( mw.config.get( 'testVar' ), null, 'config object restored to live in next module()' ); - assert.equal( mw.messages.get( 'testMsg' ), null, 'messages object restored to live in next module()' ); - } ); - -}( jQuery, mediaWiki, QUnit ) ); -- cgit v1.2.3-54-g00ecf