Merge "Add unit tests for mw.format()"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.test.js
index 111d85b..ed3f2cd 100644 (file)
                this.restoreWarnings();
        } );
 
+       QUnit.test( 'mw.format', 2, function ( assert ) {
+               assert.equal(
+                       mw.format( 'Format $1 $2', 'foo', 'bar' ),
+                       'Format foo bar',
+                       'Simple parameters'
+               );
+               assert.equal(
+                       mw.format( 'Format $1 $2' ),
+                       'Format $1 $2',
+                       'Missing parameters'
+               );
+       } );
+
        QUnit.test( 'mw.Map', 35, function ( assert ) {
                var arry, conf, funky, globalConf, nummy, someValues;
 
 
                hello = mw.message( 'hello' );
 
-               // https://bugzilla.wikimedia.org/show_bug.cgi?id=44459
+               // https://phabricator.wikimedia.org/T46459
                assert.equal( hello.format, 'text', 'Message property "format" defaults to "text"' );
 
                assert.strictEqual( hello.map, mw.messages, 'Message property "map" defaults to the global instance in mw.messages' );
                assert.equal( hello.key, 'hello', 'Message property "key" (currect key)' );
                assert.deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array' );
 
-               // Todo
+               // TODO
                assert.ok( hello.params, 'Message prototype "params"' );
 
                hello.format = 'plain';
                } );
        } );
 
-       QUnit.asyncTest( 'mw.loader.using( .. ).promise', 2, function ( assert ) {
+       QUnit.asyncTest( 'mw.loader.using( .. ) Promise', 2, function ( assert ) {
                var isAwesomeDone;
 
                mw.loader.testCallback = function () {
        } );
 
        // @import (bug 31676)
-       QUnit.asyncTest( 'mw.loader.implement( styles has @import)', 7, function ( assert ) {
+       QUnit.asyncTest( 'mw.loader.implement( styles has @import )', 7, function ( assert ) {
                var isJsExecuted, $element;
 
                mw.loader.implement(
                } );
        } );
 
-       QUnit.test( 'mw.loader erroneous indirect dependency', 4, function ( assert ) {
+       QUnit.test( 'mw.loader with broken indirect dependency', 4, function ( assert ) {
                // don't emit an error event
                this.sandbox.stub( mw, 'track' );
 
                assert.strictEqual( mw.track.callCount, 1 );
        } );
 
+       QUnit.test( 'mw.loader with circular dependency', 1, function ( assert ) {
+               mw.loader.register( [
+                       [ 'test.circle1', '0', [ 'test.circle2' ] ],
+                       [ 'test.circle2', '0', [ 'test.circle3' ] ],
+                       [ 'test.circle3', '0', [ 'test.circle1' ] ]
+               ] );
+               assert.throws( function () {
+                       mw.loader.using( 'test.circle3' );
+               }, /Circular/, 'Detect circular dependency' );
+       } );
+
        QUnit.test( 'mw.loader out-of-order implementation', 9, function ( assert ) {
                mw.loader.register( [
                        [ 'test.module4', '0' ],
                } ).always( QUnit.start );
        } );
 
-       QUnit.test( 'mw.html', 13, function ( assert ) {
-               assert.throws( function () {
-                       mw.html.escape();
-               }, TypeError, 'html.escape throws a TypeError if argument given is not a string' );
-
-               assert.equal( mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
-                       '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;', 'escape() escapes special characters to html entities' );
-
-               assert.equal( mw.html.element(),
-                       '<undefined/>', 'element() always returns a valid html string (even without arguments)' );
-
-               assert.equal( mw.html.element( 'div' ), '<div/>', 'element() Plain DIV (simple)' );
-
-               assert.equal( mw.html.element( 'div', {}, '' ), '<div></div>', 'element() Basic DIV (simple)' );
-
-               assert.equal(
-                       mw.html.element(
-                               'div', {
-                                       id: 'foobar'
-                               }
-                       ),
-                       '<div id="foobar"/>',
-                       'html.element DIV (attribs)' );
-
-               assert.equal( mw.html.element( 'p', null, 12 ), '<p>12</p>', 'Numbers are valid content and should be casted to a string' );
-
-               assert.equal( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'Numbers are valid attribute values' );
-
-               // Example from https://www.mediawiki.org/wiki/ResourceLoader/Default_modules#mediaWiki.html
-               assert.equal(
-                       mw.html.element(
-                               'div',
-                               {},
-                               new mw.html.Raw(
-                                       mw.html.element( 'img', { src: '<' } )
-                               )
-                       ),
-                       '<div><img src="&lt;"/></div>',
-                       'Raw inclusion of another element'
-               );
-
-               assert.equal(
-                       mw.html.element(
-                               'option', {
-                                       selected: true
-                               }, 'Foo'
-                       ),
-                       '<option selected="selected">Foo</option>',
-                       'Attributes may have boolean values. True copies the attribute name to the value.'
-               );
-
-               assert.equal(
-                       mw.html.element(
-                               'option', {
-                                       value: 'foo',
-                                       selected: false
-                               }, 'Foo'
-                       ),
-                       '<option value="foo">Foo</option>',
-                       'Attributes may have boolean values. False keeps the attribute from output.'
-               );
-
-               assert.equal( mw.html.element( 'div',
-                       null, 'a' ),
-                       '<div>a</div>',
-                       'html.element DIV (content)' );
-
-               assert.equal( mw.html.element( 'a',
-                       { href: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ),
-                       '<a href="http://mediawiki.org/w/index.php?title=RL&amp;action=history">a</a>',
-                       'html.element DIV (attribs + content)' );
-
-       } );
-
        QUnit.test( 'mw.hook', 13, function ( assert ) {
                var hook, add, fire, chars, callback;