Merge "Fix ParserOutput::getText 'unwrap' flag for end-of-doc comment"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.edit.test.js
index f83f66c..4ce7c5d 100644 (file)
@@ -15,7 +15,7 @@
                                                pages: [ {
                                                        pageid: 1,
                                                        ns: 0,
-                                                       title:  'Sandbox',
+                                                       title: 'Sandbox',
                                                        revisions: [ {
                                                                timestamp: '2016-01-01T12:00:00Z',
                                                                contentformat: 'text/x-wiki',
                        } );
        } );
 
+       QUnit.test( 'edit( mw.Title, transform String )', function ( assert ) {
+               this.server.respond( function ( req ) {
+                       if ( /query.+titles=Sandbox/.test( req.url ) ) {
+                               req.respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify( {
+                                       curtimestamp: '2016-01-02T12:00:00Z',
+                                       query: {
+                                               pages: [ {
+                                                       pageid: 1,
+                                                       ns: 0,
+                                                       title: 'Sandbox',
+                                                       revisions: [ {
+                                                               timestamp: '2016-01-01T12:00:00Z',
+                                                               contentformat: 'text/x-wiki',
+                                                               contentmodel: 'wikitext',
+                                                               content: 'Sand.'
+                                                       } ]
+                                               } ]
+                                       }
+                               } ) );
+                       }
+                       if ( /edit.+basetimestamp=2016-01-01.+starttimestamp=2016-01-02.+text=Box%2E/.test( req.requestBody ) ) {
+                               req.respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify( {
+                                       edit: {
+                                               result: 'Success',
+                                               oldrevid: 11,
+                                               newrevid: 13,
+                                               newtimestamp: '2016-01-03T12:00:00Z'
+                                       }
+                               } ) );
+                       }
+               } );
+
+               return new mw.Api()
+                       .edit( new mw.Title( 'Sandbox' ), function ( revision ) {
+                               return revision.content.replace( 'Sand', 'Box' );
+                       } )
+                       .then( function ( edit ) {
+                               assert.equal( edit.newrevid, 13 );
+                       } );
+       } );
+
        QUnit.test( 'edit( title, transform Promise )', function ( assert ) {
                this.server.respond( function ( req ) {
                        if ( /query.+titles=Async/.test( req.url ) ) {
@@ -56,7 +97,7 @@
                                                pages: [ {
                                                        pageid: 4,
                                                        ns: 0,
-                                                       title:  'Async',
+                                                       title: 'Async',
                                                        revisions: [ {
                                                                timestamp: '2016-02-01T12:00:00Z',
                                                                contentformat: 'text/x-wiki',
                                                pages: [ {
                                                        pageid: 3,
                                                        ns: 0,
-                                                       title:  'Param',
+                                                       title: 'Param',
                                                        revisions: [ {
                                                                timestamp: '2016-03-01T12:00:00Z',
                                                                contentformat: 'text/x-wiki',
                        } );
        } );
 
+       QUnit.test( 'edit( invalid-title, transform String )', function ( assert ) {
+               this.server.respond( function ( req ) {
+                       if ( /query.+titles=%1F%7C/.test( req.url ) ) {
+                               req.respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify( {
+                                       query: {
+                                               pages: [ {
+                                                       title: '|',
+                                                       invalidreason: 'The requested page title contains invalid characters: "|".',
+                                                       invalid: true
+                                               } ]
+                                       }
+                               } ) );
+                       }
+               } );
+
+               return new mw.Api()
+                       .edit( '|', function ( revision ) {
+                               return revision.content.replace( 'Sand', 'Box' );
+                       } )
+                       .then( function () {
+                               return $.Deferred().reject( 'Unexpected success' );
+                       }, function ( reason ) {
+                               assert.equal( reason, 'invalidtitle' );
+                       } );
+       } );
+
        QUnit.test( 'create( title, content )', function ( assert ) {
                this.server.respond( function ( req ) {
                        if ( /edit.+text=Sand/.test( req.requestBody ) ) {
                                req.respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify( {
                                        edit: {
-                                               'new': true,
+                                               new: true,
                                                result: 'Success',
                                                newrevid: 41,
                                                newtimestamp: '2016-04-01T12:00:00Z'