Merge "Block: Type hint Block constructor, follow-up on I37ab858494a173c6982bb"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 30 Apr 2019 19:04:37 +0000 (19:04 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 30 Apr 2019 19:04:37 +0000 (19:04 +0000)
includes/user/User.php
maintenance/populateArchiveRevId.php
resources/src/mediawiki.api/parse.js
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js
tests/selenium/specs/rollback.js
tests/selenium/wdio-mediawiki/LoginPage.js
tests/selenium/wdio-mediawiki/Util.js

index 11c712a..bca5d4b 100644 (file)
@@ -4203,7 +4203,7 @@ class User implements IDBAccessObject, UserIdentity {
                $newTouched = $this->newTouchedTimestamp();
 
                $dbw = wfGetDB( DB_MASTER );
-               $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) use ( $newTouched ) {
+               $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) use ( $newTouched ) {
                        global $wgActorTableSchemaMigrationStage;
 
                        $dbw->update( 'user',
@@ -4329,7 +4329,7 @@ class User implements IDBAccessObject, UserIdentity {
                        $fields["user_$name"] = $value;
                }
 
-               return $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) use ( $fields ) {
+               return $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) use ( $fields ) {
                        $dbw->insert( 'user', $fields, $fname, [ 'IGNORE' ] );
                        if ( $dbw->affectedRows() ) {
                                $newUser = self::newFromId( $dbw->insertId() );
@@ -4383,7 +4383,7 @@ class User implements IDBAccessObject, UserIdentity {
                $this->mTouched = $this->newTouchedTimestamp();
 
                $dbw = wfGetDB( DB_MASTER );
-               $status = $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) {
+               $status = $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) {
                        $noPass = PasswordFactory::newInvalidPassword()->toString();
                        $dbw->insert( 'user',
                                [
index ec2eff4..96fcebf 100644 (file)
@@ -110,7 +110,7 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance {
                $ok = false;
                while ( !$ok ) {
                        try {
-                               $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) {
+                               $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) {
                                        $dbw->insert( 'revision', self::$dummyRev, $fname );
                                        $id = $dbw->insertId();
                                        $toDelete[] = $id;
@@ -147,7 +147,7 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance {
                        self::$dummyRev = self::makeDummyRevisionRow( $dbw );
                }
 
-               $updates = $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) use ( $arIds ) {
+               $updates = $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) use ( $arIds ) {
                        // Create new rev_ids by inserting dummy rows into revision and then deleting them.
                        $dbw->insert( 'revision', array_fill( 0, count( $arIds ), self::$dummyRev ), $fname );
                        $revIds = $dbw->selectFieldValues(
index 42b0771..447b936 100644 (file)
                        if ( mw.Title && content instanceof mw.Title ) {
                                // Parse existing page
                                config.page = content.getPrefixedDb();
+                               apiPromise = this.get( config );
                        } else {
                                // Parse wikitext from input
                                config.text = String( content );
+                               apiPromise = this.post( config );
                        }
 
-                       apiPromise = this.get( config );
-
                        return apiPromise
                                .then( function ( data ) {
                                        return data.parse.text;
index 0bcce12..29cffaf 100644 (file)
@@ -7,7 +7,7 @@
        } ) );
 
        QUnit.test( '.parse( string )', function ( assert ) {
-               this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
+               this.server.respondWith( 'POST', /api.php/, [ 200,
                        { 'Content-Type': 'application/json' },
                        '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
                ] );
@@ -18,7 +18,7 @@
        } );
 
        QUnit.test( '.parse( Object.toString )', function ( assert ) {
-               this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
+               this.server.respondWith( 'POST', /api.php/, [ 200,
                        { 'Content-Type': 'application/json' },
                        '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
                ] );
@@ -33,7 +33,7 @@
        } );
 
        QUnit.test( '.parse( mw.Title )', function ( assert ) {
-               this.server.respondWith( /action=parse.*&page=Earth/, [ 200,
+               this.server.respondWith( 'GET', /action=parse.*&page=Earth/, [ 200,
                        { 'Content-Type': 'application/json' },
                        '{ "parse": { "text": "<p><b>Earth</b> is a planet.</p>" } }'
                ] );
index 970fb9e..51a1fc6 100644 (file)
@@ -17,7 +17,7 @@ describe( 'Rollback with confirmation', function () {
                // Requires user to log in again, handled by deleteCookie() call in beforeEach function
                UserLoginPage.loginAdmin();
 
-               browser.pause( 300 );
+               UserLoginPage.waitForScriptsToBeReady();
                browser.execute( function () {
                        return ( new mw.Api() ).saveOption(
                                'showrollbackconfirmation',
@@ -48,22 +48,22 @@ describe( 'Rollback with confirmation', function () {
                assert.strictEqual( HistoryPage.rollbackConfirmableNo.getText(), 'Cancel' );
        } );
 
-       it.skip( 'should offer a way to cancel rollbacks', function () {
+       it( 'should offer a way to cancel rollbacks', function () {
                HistoryPage.rollback.click();
 
-               browser.pause( 300 );
+               HistoryPage.rollbackConfirmableNo.waitForVisible( 5000 );
 
                HistoryPage.rollbackConfirmableNo.click();
 
-               browser.pause( 500 );
+               browser.pause( 1000 ); // Waiting to ensure we are NOT redirected and stay on the same page
 
                assert.strictEqual( HistoryPage.heading.getText(), 'Revision history of "' + name + '"' );
        } );
 
-       it.skip( 'should perform rollbacks after confirming intention', function () {
+       it( 'should perform rollbacks after confirming intention', function () {
                HistoryPage.rollback.click();
 
-               browser.pause( 300 );
+               HistoryPage.rollbackConfirmableYes.waitForVisible( 5000 );
 
                HistoryPage.rollbackConfirmableYes.click();
 
@@ -104,7 +104,7 @@ describe( 'Rollback without confirmation', function () {
                // Requires user to log in again, handled by deleteCookie() call in beforeEach function
                UserLoginPage.loginAdmin();
 
-               browser.pause( 300 );
+               UserLoginPage.waitForScriptsToBeReady();
                browser.execute( function () {
                        return ( new mw.Api() ).saveOption(
                                'showrollbackconfirmation',
index 8838530..60855f8 100644 (file)
@@ -1,4 +1,5 @@
-const Page = require( './Page' );
+const Page = require( './Page' ),
+       Util = require( 'wdio-mediawiki/Util' );
 
 class LoginPage extends Page {
        get username() { return browser.element( '#wpName1' ); }
@@ -20,6 +21,10 @@ class LoginPage extends Page {
        loginAdmin() {
                this.login( browser.options.username, browser.options.password );
        }
+
+       waitForScriptsToBeReady() {
+               Util.waitForModuleState( 'mediawiki.api' );
+       }
 }
 
 module.exports = new LoginPage();
index 247c958..dd08ee9 100644 (file)
@@ -1,5 +1,21 @@
 module.exports = {
        getTestString( prefix = '' ) {
                return prefix + Math.random().toString() + '-Iñtërnâtiônàlizætiøn';
+       },
+
+       /**
+        * Wait for a given module to reach a specific state
+        * @param {string} moduleName The name of the module to wait for
+        * @param {string} moduleStatus 'registered', 'loaded', 'loading', 'ready', 'error', 'missing'
+        * @param {int} timeout The wait time in milliseconds before the wait fails
+        */
+       waitForModuleState( moduleName, moduleStatus = 'ready', timeout = 2000 ) {
+               browser.waitUntil( () => {
+                       const result = browser.execute( ( module ) => {
+                               return typeof mw !== 'undefined' &&
+                                       mw.loader.getState( module.name ) === module.status;
+                       }, { status: moduleStatus, name: moduleName } );
+                       return result.value;
+               }, timeout, 'Failed to wait for ' + moduleName + ' to be ' + moduleStatus + ' after ' + timeout + ' ms.' );
        }
 };