X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2Fqunit%2Fsuites%2Fresources%2Fmediawiki.api%2Fmediawiki.api.options.test.js;h=0797f32dfbb2c1fc3b32a5cabe3f9d6b9a0bfb84;hb=46c7453ddb593a124a307a7a3944c3fcf0983d29;hp=c0a6585f30e87c0af188d3e97a389433375b1644;hpb=4f21e6be661f7305abc223bb31600970a3fb5326;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js index c0a6585f30..0797f32dfb 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js @@ -18,18 +18,18 @@ assert.deepEqual( stub.getCall( 0 ).args, [ { foo: 'bar' } ], '#saveOptions called correctly' ); } ); - QUnit.test( 'saveOptions', function ( assert ) { + QUnit.test( 'saveOptions without Unit Separator', function ( assert ) { QUnit.expect( 13 ); - var api = new mw.Api(); + var api = new mw.Api( { useUS: false } ); // We need to respond to the request for token first, otherwise the other requests won't be sent // until after the server.respond call, which confuses sinon terribly. This sucks a lot. api.getToken( 'options' ); this.server.respond( - /action=tokens.*&type=options/, + /meta=tokens&type=csrf/, [ 200, { 'Content-Type': 'application/json' }, - '{ "tokens": { "optionstoken": "+\\\\" } }' ] + '{ "query": { "tokens": { "csrftoken": "+\\\\" } } }' ] ); api.saveOptions( {} ).done( function () { @@ -55,23 +55,85 @@ this.server.respond( function ( request ) { switch ( request.requestBody ) { // simple - case 'action=options&format=json&change=foo%3Dbar&token=%2B%5C': + case 'action=options&format=json&formatversion=2&change=foo%3Dbar&token=%2B%5C': // two options - case 'action=options&format=json&change=foo%3Dbar%7Cbaz%3Dquux&token=%2B%5C': + case 'action=options&format=json&formatversion=2&change=foo%3Dbar%7Cbaz%3Dquux&token=%2B%5C': // not bundleable - case 'action=options&format=json&optionname=foo&optionvalue=bar%7Cquux&token=%2B%5C': - case 'action=options&format=json&optionname=bar&optionvalue=a%7Cb%7Cc&token=%2B%5C': - case 'action=options&format=json&change=baz%3Dquux&token=%2B%5C': + case 'action=options&format=json&formatversion=2&optionname=foo&optionvalue=bar%7Cquux&token=%2B%5C': + case 'action=options&format=json&formatversion=2&optionname=bar&optionvalue=a%7Cb%7Cc&token=%2B%5C': + case 'action=options&format=json&formatversion=2&change=baz%3Dquux&token=%2B%5C': // reset an option - case 'action=options&format=json&change=foo&token=%2B%5C': + case 'action=options&format=json&formatversion=2&change=foo&token=%2B%5C': // reset an option, not bundleable - case 'action=options&format=json&optionname=foo%7Cbar%3Dquux&token=%2B%5C': + case 'action=options&format=json&formatversion=2&optionname=foo%7Cbar%3Dquux&token=%2B%5C': assert.ok( true, 'Repond to ' + request.requestBody ); request.respond( 200, { 'Content-Type': 'application/json' }, '{ "options": "success" }' ); break; default: - assert.ok( false, 'Unexpected request:' + request.requestBody ); + assert.ok( false, 'Unexpected request: ' + request.requestBody ); + } + } ); + } ); + + QUnit.test( 'saveOptions with Unit Separator', function ( assert ) { + QUnit.expect( 14 ); + + var api = new mw.Api( { useUS: true } ); + + // We need to respond to the request for token first, otherwise the other requests won't be sent + // until after the server.respond call, which confuses sinon terribly. This sucks a lot. + api.getToken( 'options' ); + this.server.respond( + /meta=tokens&type=csrf/, + [ 200, { 'Content-Type': 'application/json' }, + '{ "query": { "tokens": { "csrftoken": "+\\\\" } } }' ] + ); + + api.saveOptions( {} ).done( function () { + assert.ok( true, 'Request completed: empty case' ); + } ); + api.saveOptions( { foo: 'bar' } ).done( function () { + assert.ok( true, 'Request completed: simple' ); + } ); + api.saveOptions( { foo: 'bar', baz: 'quux' } ).done( function () { + assert.ok( true, 'Request completed: two options' ); + } ); + api.saveOptions( { foo: 'bar|quux', bar: 'a|b|c', baz: 'quux' } ).done( function () { + assert.ok( true, 'Request completed: bundleable with unit separator' ); + } ); + api.saveOptions( { foo: 'bar|quux', bar: 'a|b|c', 'baz=baz': 'quux' } ).done( function () { + assert.ok( true, 'Request completed: not bundleable with unit separator' ); + } ); + api.saveOptions( { foo: null } ).done( function () { + assert.ok( true, 'Request completed: reset an option' ); + } ); + api.saveOptions( { 'foo|bar=quux': null } ).done( function () { + assert.ok( true, 'Request completed: reset an option, not bundleable' ); + } ); + + // Requests are POST, match requestBody instead of url + this.server.respond( function ( request ) { + switch ( request.requestBody ) { + // simple + case 'action=options&format=json&formatversion=2&change=foo%3Dbar&token=%2B%5C': + // two options + case 'action=options&format=json&formatversion=2&change=foo%3Dbar%7Cbaz%3Dquux&token=%2B%5C': + // bundleable with unit separator + case 'action=options&format=json&formatversion=2&change=%1Ffoo%3Dbar%7Cquux%1Fbar%3Da%7Cb%7Cc%1Fbaz%3Dquux&token=%2B%5C': + // not bundleable with unit separator + case 'action=options&format=json&formatversion=2&optionname=baz%3Dbaz&optionvalue=quux&token=%2B%5C': + case 'action=options&format=json&formatversion=2&change=%1Ffoo%3Dbar%7Cquux%1Fbar%3Da%7Cb%7Cc&token=%2B%5C': + // reset an option + case 'action=options&format=json&formatversion=2&change=foo&token=%2B%5C': + // reset an option, not bundleable + case 'action=options&format=json&formatversion=2&optionname=foo%7Cbar%3Dquux&token=%2B%5C': + assert.ok( true, 'Repond to ' + request.requestBody ); + request.respond( 200, { 'Content-Type': 'application/json' }, + '{ "options": "success" }' ); + break; + default: + assert.ok( false, 'Unexpected request: ' + request.requestBody ); } } ); } );