X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fqunit%2Fsuites%2Fresources%2Fmediawiki.api%2Fmediawiki.api.edit.test.js;h=ff5cb2c93e3b7586f4aea9afe3eac53b40770458;hb=138298b397b308ad6e4bfc7088884d90e8ac1e37;hp=13d7dcc2878a04598cb1f7a1fedbf06c5e9cf226;hpb=dae4c94d893057345f62a3d498fb85c0a54de5a6;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.edit.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.edit.test.js index 13d7dcc287..ff5cb2c93e 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.edit.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.edit.test.js @@ -43,7 +43,48 @@ return revision.content.replace( 'Sand', 'Box' ); } ) .then( function ( edit ) { - assert.equal( edit.newrevid, 13 ); + assert.strictEqual( edit.newrevid, 13 ); + } ); + } ); + + 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.strictEqual( edit.newrevid, 13 ); } ); } ); @@ -84,7 +125,7 @@ return $.Deferred().resolve( revision.content.replace( 'Async', 'Promise' ) ); } ) .then( function ( edit ) { - assert.equal( edit.newrevid, 23 ); + assert.strictEqual( edit.newrevid, 23 ); } ); } ); @@ -125,7 +166,33 @@ return { text: 'Content', summary: 'Sum' }; } ) .then( function ( edit ) { - assert.equal( edit.newrevid, 33 ); + assert.strictEqual( edit.newrevid, 33 ); + } ); + } ); + + 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.strictEqual( reason, 'invalidtitle' ); } ); } ); @@ -146,7 +213,7 @@ return new mw.Api() .create( 'Sandbox', { summary: 'Load sand particles.' }, 'Sand.' ) .then( function ( page ) { - assert.equal( page.newrevid, 41 ); + assert.strictEqual( page.newrevid, 41 ); } ); } );