From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- vendor/oojs/oojs-ui/tests/Element.test.js | 52 ++++++ vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js | 61 +++++++ vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js | 55 +++++++ vendor/oojs/oojs-ui/tests/Process.test.js | 179 +++++++++++++++++++++ .../oojs-ui/tests/QUnit.assert.equalDomElement.js | 113 +++++++++++++ .../oojs-ui/tests/elements/FlaggedElement.test.js | 64 ++++++++ vendor/oojs/oojs-ui/tests/index.php | 77 +++++++++ 7 files changed, 601 insertions(+) create mode 100644 vendor/oojs/oojs-ui/tests/Element.test.js create mode 100644 vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js create mode 100644 vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js create mode 100644 vendor/oojs/oojs-ui/tests/Process.test.js create mode 100644 vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js create mode 100644 vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js create mode 100644 vendor/oojs/oojs-ui/tests/index.php (limited to 'vendor/oojs/oojs-ui/tests') diff --git a/vendor/oojs/oojs-ui/tests/Element.test.js b/vendor/oojs/oojs-ui/tests/Element.test.js new file mode 100644 index 00000000..b37d8e35 --- /dev/null +++ b/vendor/oojs/oojs-ui/tests/Element.test.js @@ -0,0 +1,52 @@ +QUnit.module( 'Element', { + setup: function () { + this.fixture = document.createElement( 'div' ); + document.body.appendChild( this.fixture ); + + this.makeFrame = function () { + var frame = document.createElement( 'iframe' ); + this.fixture.appendChild( frame ); + return ( frame.contentWindow && frame.contentWindow.document ) || frame.contentDocument; + }; + }, + teardown: function () { + this.fixture.parentNode.removeChild( this.fixture ); + this.fixture = null; + } +} ); + +QUnit.test( 'static.getDocument', 10, function ( assert ) { + var frameDoc, frameEl, frameDiv, + el = this.fixture, + div = document.createElement( 'div' ), + $el = $( this.fixture ), + $div = $( '
' ), + win = window, + doc = document; + + frameDoc = this.makeFrame(); + frameEl = frameDoc.createElement( 'span' ); + frameDoc.documentElement.appendChild( frameEl ); + frameDiv = frameDoc.createElement( 'div' ); + + assert.strictEqual( OO.ui.Element.static.getDocument( $el ), doc, 'jQuery' ); + assert.strictEqual( OO.ui.Element.static.getDocument( $div ), doc, 'jQuery (detached)' ); + assert.strictEqual( OO.ui.Element.static.getDocument( el ), doc, 'HTMLElement' ); + assert.strictEqual( OO.ui.Element.static.getDocument( div ), doc, 'HTMLElement (detached)' ); + assert.strictEqual( OO.ui.Element.static.getDocument( win ), doc, 'Window' ); + assert.strictEqual( OO.ui.Element.static.getDocument( doc ), doc, 'HTMLDocument' ); + + assert.strictEqual( OO.ui.Element.static.getDocument( frameEl ), frameDoc, 'HTMLElement (framed)' ); + assert.strictEqual( OO.ui.Element.static.getDocument( frameDiv ), frameDoc, 'HTMLElement (framed, detached)' ); + assert.strictEqual( OO.ui.Element.static.getDocument( frameDoc ), frameDoc, 'HTMLDocument (framed)' ); + + assert.strictEqual( OO.ui.Element.static.getDocument( {} ), null, 'Invalid' ); +} ); + +QUnit.test( 'getElementDocument', 1, function ( assert ) { + var el, doc; + + doc = document; + el = new OO.ui.Element(); + assert.strictEqual( el.getElementDocument(), doc ); +} ); diff --git a/vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js b/vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js new file mode 100644 index 00000000..1a1473c1 --- /dev/null +++ b/vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js @@ -0,0 +1,61 @@ +QUnit.module( 'JSPHP' ); + +( function () { + // Generate some tests based on the test suite data and HTML from PHP version. + var theme, klassName, + themes = { + ApexTheme: new OO.ui.ApexTheme(), + MediaWikiTheme: new OO.ui.MediaWikiTheme() + }; + + function unstub( value ) { + var config; + if ( typeof value === 'string' && value.substr( 0, 13 ) === '_placeholder_' ) { + value = JSON.parse( value.substr( 13 ) ); + config = OO.copy( value.config, null, unstub ); + return new OO.ui[ value.class ]( config ); + } + } + + function makeTest( theme, klassName, tests, output ) { + QUnit.test( theme + ': ' + klassName, tests.length * 2, function ( assert ) { + var test, config, instance, infused, $fromPhp, i, testName; + OO.ui.theme = themes[ theme ]; + for ( i = 0; i < tests.length; i++ ) { + test = tests[ i ]; + // Unstub placeholders + config = OO.copy( test.config, null, unstub ); + + instance = new OO.ui[ test.class ]( config ); + $fromPhp = $( $.parseHTML( output[ i ] ) ); + + $( 'body' ).append( instance.$element, $fromPhp ); + + // Updating theme classes is normally debounced, we need to do it immediately + instance.debouncedUpdateThemeClasses(); + + testName = JSON.stringify( test.config ); + assert.equalDomElement( instance.$element[ 0 ], $fromPhp[ 0 ], testName, true ); + + infused = OO.ui.infuse( $fromPhp[ 0 ] ); + infused.debouncedUpdateThemeClasses(); + + assert.equalDomElement( instance.$element[ 0 ], infused.$element[ 0 ], testName + ' (infuse)' ); + instance.$element.add( infused.$element ).detach(); + } + } ); + } + + /*global testSuiteConfigs, testSuitePHPOutput */ + for ( klassName in testSuiteConfigs ) { + for ( theme in themes ) { + makeTest( + theme, + klassName, + testSuiteConfigs[ klassName ], + testSuitePHPOutput[ theme ][ klassName ] + ); + } + } + +} )(); diff --git a/vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js b/vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js new file mode 100644 index 00000000..1cbebc3a --- /dev/null +++ b/vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js @@ -0,0 +1,55 @@ +QUnit.module( 'JSPHP' ); + +( function () { + // Generate some tests based on the test suite data and HTML from PHP version. + var theme, klassName, + themes = { + ApexTheme: new OO.ui.ApexTheme(), + MediaWikiTheme: new OO.ui.MediaWikiTheme() + }; + + function unstub( value ) { + var config; + if ( typeof value === 'string' && value.substr( 0, 13 ) === '_placeholder_' ) { + value = JSON.parse( value.substr( 13 ) ); + config = OO.copy( value.config, null, unstub ); + return new OO.ui[ value.class ]( config ); + } + } + + function makeTest( theme, klassName, tests ) { + QUnit.test( theme + ': ' + klassName, tests.length * 2, function ( assert ) { + var test, config, instance, infused, id, fromPhp, i, testName; + OO.ui.theme = themes[ theme ]; + for ( i = 0; i < tests.length; i++ ) { + test = tests[ i ]; + // Unstub placeholders + config = OO.copy( test.config, null, unstub ); + + instance = new OO.ui[ test.class ]( config ); + + id = 'JSPHPTestSuite_' + theme + klassName + i; + fromPhp = document.getElementById( id ).firstChild; + instance.$element.insertBefore( fromPhp ); + + // Updating theme classes is normally debounced, we need to do it immediately + instance.debouncedUpdateThemeClasses(); + + testName = JSON.stringify( test.config ); + assert.equalDomElement( instance.$element[ 0 ], fromPhp, testName ); + + infused = OO.ui.infuse( fromPhp ); + infused.debouncedUpdateThemeClasses(); + + assert.equalDomElement( instance.$element[ 0 ], infused.$element[ 0 ], testName + ' (infuse)' ); + } + } ); + } + + for ( klassName in OO.ui.JSPHPTestSuite ) { + for ( theme in themes ) { + makeTest( theme, klassName, OO.ui.JSPHPTestSuite[ klassName ] ); + } + } + +} )(); diff --git a/vendor/oojs/oojs-ui/tests/Process.test.js b/vendor/oojs/oojs-ui/tests/Process.test.js new file mode 100644 index 00000000..3f036407 --- /dev/null +++ b/vendor/oojs/oojs-ui/tests/Process.test.js @@ -0,0 +1,179 @@ +QUnit.module( 'OO.ui.Process' ); + +/* Tests */ + +QUnit.test( 'next', 1, function ( assert ) { + var process = new OO.ui.Process(), + result = []; + + process + .next( function () { + result.push( 0 ); + } ) + .next( function () { + result.push( 1 ); + } ) + .next( function () { + result.push( 2 ); + } ) + .execute(); + + assert.deepEqual( result, [ 0, 1, 2 ], 'Steps can be added at the end' ); +} ); + +QUnit.test( 'first', 1, function ( assert ) { + var process = new OO.ui.Process(), + result = []; + + process + .first( function () { + result.push( 0 ); + } ) + .first( function () { + result.push( 1 ); + } ) + .first( function () { + result.push( 2 ); + } ) + .execute(); + + assert.deepEqual( result, [ 2, 1, 0 ], 'Steps can be added at the beginning' ); +} ); + +QUnit.asyncTest( 'execute (async)', 1, function ( assert ) { + // Async + var process = new OO.ui.Process(), + result = []; + + process + .next( function () { + var deferred = $.Deferred(); + + setTimeout( function () { + result.push( 1 ); + deferred.resolve(); + }, 10 ); + + return deferred.promise(); + } ) + .first( function () { + var deferred = $.Deferred(); + + setTimeout( function () { + result.push( 0 ); + deferred.resolve(); + }, 10 ); + + return deferred.promise(); + } ) + .next( function () { + result.push( 2 ); + } ); + + process.execute().done( function () { + assert.deepEqual( + result, + [ 0, 1, 2 ], + 'Synchronous and asynchronous steps are executed in the correct order' + ); + QUnit.start(); + } ); +} ); + +QUnit.asyncTest( 'execute (return false)', 1, function ( assert ) { + var process = new OO.ui.Process(), + result = []; + + process + .next( function () { + var deferred = $.Deferred(); + + setTimeout( function () { + result.push( 0 ); + deferred.resolve(); + }, 10 ); + + return deferred.promise(); + } ) + .next( function () { + result.push( 1 ); + return false; + } ) + .next( function () { + // Should never be run because previous step is rejected + result.push( 2 ); + } ); + + process.execute().fail( function () { + assert.deepEqual( + result, + [ 0, 1 ], + 'Process is stopped when a step returns false' + ); + QUnit.start(); + } ); +} ); + +QUnit.asyncTest( 'execute (async reject)', 1, function ( assert ) { + var process = new OO.ui.Process(), + result = []; + + process + .next( function () { + result.push( 0 ); + } ) + .next( function () { + var deferred = $.Deferred(); + + setTimeout( function () { + result.push( 1 ); + deferred.reject(); + }, 10 ); + + return deferred.promise(); + } ) + .next( function () { + // Should never be run because previous step is rejected + result.push( 2 ); + } ); + + process.execute().fail( function () { + assert.deepEqual( + result, + [ 0, 1 ], + 'Process is stopped when a step returns a promise that is then rejected' + ); + QUnit.start(); + } ); +} ); + +QUnit.asyncTest( 'execute (wait)', 1, function ( assert ) { + var process = new OO.ui.Process(), + result = []; + + process + .next( function () { + result.push( 'A' ); + return 10; + } ) + .next( function () { + result.push( 'B' ); + } ); + + // Steps defined above don't run until execute() + result.push( 'before' ); + + // Process yields between step A and B + setTimeout( function () { + result.push( 'yield' ); + } ); + + process.execute().done( function () { + assert.deepEqual( + result, + [ 'before', 'A', 'yield', 'B' ], + 'Process is stopped when a step returns a promise that is then rejected' + ); + QUnit.start(); + } ); +} ); diff --git a/vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js b/vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js new file mode 100644 index 00000000..f041c258 --- /dev/null +++ b/vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js @@ -0,0 +1,113 @@ +/*! + * A QUnit assertion to compare DOM node trees. + * + * Adapted from VisualEditor plugin for QUnit. Additionally supports comparing properties to + * attributes (for dynamically generated nodes) and order-insensitive comparison of classes on DOM + * nodes. + * + * @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org + * @copyright 2011-2015 OOjs Team and other contributors + */ + +( function ( QUnit ) { + + /** + * Build a summary of an HTML element. + * + * Summaries include node name, text, attributes and recursive summaries of children. + * Used for serializing or comparing HTML elements. + * + * @private + * @param {HTMLElement} element Element to summarize + * @param {boolean} [includeHtml=false] Include an HTML summary for element nodes + * @return {Object} Summary of element. + */ + function getDomElementSummary( element, includeHtml ) { + var i, name, + summary = { + type: element.nodeName.toLowerCase(), + // $( '
' )[0].textContent === 'Foo', which breaks + // comparisons :( childNodes are summarized anyway, this would just be a nicety + // text: element.textContent, + attributes: {}, + children: [] + }; + + if ( includeHtml && element.nodeType === Node.ELEMENT_NODE ) { + summary.html = element.outerHTML; + } + + // Gather attributes + if ( element.attributes ) { + for ( i = 0; i < element.attributes.length; i++ ) { + name = element.attributes[ i ].name; + if ( name.substr( 0, 5 ) !== 'data-' && name !== 'id' ) { + summary.attributes[ name ] = element.attributes[ i ].value; + } + } + } + + // Sort classes + if ( summary.attributes.class ) { + summary.attributes.class = summary.attributes.class.split( ' ' ).sort().join( ' ' ); + } + + // Gather certain properties and pretend they are attributes. + // Take note of casing differences. + if ( element.value !== undefined ) { + summary.attributes.value = element.value; + } + if ( element.readOnly !== undefined ) { + summary.attributes.readonly = element.readOnly; + } + if ( element.checked !== undefined ) { + summary.attributes.checked = element.checked; + } + if ( element.disabled !== undefined ) { + summary.attributes.disabled = element.disabled; + } + if ( element.tabIndex !== undefined ) { + summary.attributes.tabindex = element.tabIndex; + } + + // Summarize children + if ( element.childNodes ) { + for ( i = 0; i < element.childNodes.length; i++ ) { + summary.children.push( getDomElementSummary( element.childNodes[ i ], includeHtml ) ); + } + } + + // Special handling for textareas, where we only want to account for the content as the 'value' + // property, never as childNodes or textContent + if ( summary.type === 'textarea' ) { + // summary.text = ''; + summary.children = []; + } + + return summary; + } + + /** + * @method + * @static + */ + QUnit.assert.equalDomElement = function ( actual, expected, message, stringify ) { + var actualSummary = getDomElementSummary( actual ), + expectedSummary = getDomElementSummary( expected ), + actualSummaryHtml = getDomElementSummary( actual, true ), + expectedSummaryHtml = getDomElementSummary( expected, true ); + + // When running with Karma, the objects are not nicely stringified in the output when the test + // fails, only showing "Expected: [object Object], Actual: [object Object]" instead. Running + // QUnit in browser does this, and stringifying causes double escaping in output. + if ( stringify ) { + actualSummaryHtml = JSON.stringify( actualSummaryHtml, null, 2 ); + expectedSummaryHtml = JSON.stringify( expectedSummaryHtml, null, 2 ); + } + + QUnit.push( + QUnit.equiv( actualSummary, expectedSummary ), actualSummaryHtml, expectedSummaryHtml, message + ); + }; + +}( QUnit ) ); diff --git a/vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js b/vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js new file mode 100644 index 00000000..f5c483ad --- /dev/null +++ b/vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js @@ -0,0 +1,64 @@ +( function () { + QUnit.module( 'FlaggedElement' ); + + function TestElement( config ) { + TestElement.super.call( this, config ); + OO.ui.FlaggedElement.call( this, config ); + } + OO.inheritClass( TestElement, OO.ui.Widget ); + OO.mixinClass( TestElement, OO.ui.FlaggedElement ); + + QUnit.test( 'constructor', 2, function ( assert ) { + var element; + + element = new TestElement(); + assert.deepEqual( element.getFlags(), [], 'No flags by default' ); + + element = new TestElement( { + flags: [ 'foo' ] + } ); + assert.deepEqual( element.getFlags(), [ 'foo' ], 'Config option "flags"' ); + } ); + + QUnit.test( 'getFlags', 2, function ( assert ) { + var element = new TestElement(); + + element.setFlags( 'foo' ); + assert.deepEqual( element.getFlags(), [ 'foo' ], 'Flag was set' ); + + element.clearFlags(); + assert.deepEqual( element.getFlags(), [], 'Flag was removed' ); + } ); + + QUnit.test( 'hasFlag', 3, function ( assert ) { + var element = new TestElement(); + assert.deepEqual( element.hasFlag( 'foo' ), false, 'Flag absent by default' ); + + element.setFlags( 'foo' ); + assert.deepEqual( element.hasFlag( 'foo' ), true, 'Flag was set' ); + + element.clearFlags(); + assert.deepEqual( element.hasFlag( 'foo' ), false, 'Flag was removed' ); + } ); + + QUnit.test( 'clearFlags', 1, function ( assert ) { + var element = new TestElement(); + element.setFlags( 'foo' ); + element.clearFlags(); + assert.deepEqual( element.hasFlag( 'foo' ), false, 'Flag was removed' ); + } ); + + QUnit.test( 'setFlags', 5, function ( assert ) { + var element = new TestElement(); + element.setFlags( 'foo' ); + assert.deepEqual( element.hasFlag( 'foo' ), true, 'string' ); + + element.setFlags( [ 'bar', 'qux' ] ); + assert.deepEqual( element.hasFlag( 'bar' ), true, 'array[ 0 ]' ); + assert.deepEqual( element.hasFlag( 'qux' ), true, 'array[ 1 ]' ); + + element.setFlags( { bar: false, quux: true } ); + assert.deepEqual( element.hasFlag( 'bar' ), false, 'object set' ); + assert.deepEqual( element.hasFlag( 'quux' ), true, 'object remove' ); + } ); +}() ); diff --git a/vendor/oojs/oojs-ui/tests/index.php b/vendor/oojs/oojs-ui/tests/index.php new file mode 100644 index 00000000..d8e06835 --- /dev/null +++ b/vendor/oojs/oojs-ui/tests/index.php @@ -0,0 +1,77 @@ +Did you forget to run composer install?'; + exit; + } + require_once $autoload; + + $testSuiteFile = 'JSPHP-suite.json'; + if ( !file_exists( $testSuiteFile ) ) { + echo '

Did you forget to run grunt build?

'; + exit; + } + $testSuiteJSON = file_get_contents( $testSuiteFile ); + $testSuite = json_decode( $testSuiteJSON, true ); +?> + + + + + OOjs UI Test Suite + + + + + + + + + + + + + + + + + + + + + +
+
+ + -- cgit v1.2.3-54-g00ecf