2 QUnit
.module( 'mediawiki.api.edit', QUnit
.newMwEnvironment( {
4 this.server
= this.sandbox
.useFakeServer();
5 this.server
.respondImmediately
= true;
9 QUnit
.test( 'edit( title, transform String )', function ( assert
) {
10 this.server
.respond( function ( req
) {
11 if ( /query.+titles=Sandbox/.test( req
.url
) ) {
12 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
13 curtimestamp
: '2016-01-02T12:00:00Z',
20 timestamp
: '2016-01-01T12:00:00Z',
21 contentformat
: 'text/x-wiki',
22 contentmodel
: 'wikitext',
29 if ( /edit.+basetimestamp=2016-01-01.+starttimestamp=2016-01-02.+text=Box%2E/.test( req
.requestBody
) ) {
30 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
35 newtimestamp
: '2016-01-03T12:00:00Z'
42 .edit( 'Sandbox', function ( revision
) {
43 return revision
.content
.replace( 'Sand', 'Box' );
45 .then( function ( edit
) {
46 assert
.equal( edit
.newrevid
, 13 );
50 QUnit
.test( 'edit( title, transform Promise )', function ( assert
) {
51 this.server
.respond( function ( req
) {
52 if ( /query.+titles=Async/.test( req
.url
) ) {
53 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
54 curtimestamp
: '2016-02-02T12:00:00Z',
61 timestamp
: '2016-02-01T12:00:00Z',
62 contentformat
: 'text/x-wiki',
63 contentmodel
: 'wikitext',
70 if ( /edit.+basetimestamp=2016-02-01.+starttimestamp=2016-02-02.+text=Promise%2E/.test( req
.requestBody
) ) {
71 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
76 newtimestamp
: '2016-02-03T12:00:00Z'
83 .edit( 'Async', function ( revision
) {
84 return $.Deferred().resolve( revision
.content
.replace( 'Async', 'Promise' ) );
86 .then( function ( edit
) {
87 assert
.equal( edit
.newrevid
, 23 );
91 QUnit
.test( 'edit( title, transform Object )', function ( assert
) {
92 this.server
.respond( function ( req
) {
93 if ( /query.+titles=Param/.test( req
.url
) ) {
94 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
95 curtimestamp
: '2016-03-02T12:00:00Z',
102 timestamp
: '2016-03-01T12:00:00Z',
103 contentformat
: 'text/x-wiki',
104 contentmodel
: 'wikitext',
111 if ( /edit.+basetimestamp=2016-03-01.+starttimestamp=2016-03-02.+text=Content&summary=Sum/.test( req
.requestBody
) ) {
112 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
117 newtimestamp
: '2016-03-03T12:00:00Z'
124 .edit( 'Param', function () {
125 return { text
: 'Content', summary
: 'Sum' };
127 .then( function ( edit
) {
128 assert
.equal( edit
.newrevid
, 33 );
132 QUnit
.test( 'create( title, content )', function ( assert
) {
133 this.server
.respond( function ( req
) {
134 if ( /edit.+text=Sand/.test( req
.requestBody
) ) {
135 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
140 newtimestamp
: '2016-04-01T12:00:00Z'
147 .create( 'Sandbox', { summary
: 'Load sand particles.' }, 'Sand.' )
148 .then( function ( page
) {
149 assert
.equal( page
.newrevid
, 41 );
153 }( mediaWiki
, jQuery
) );