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
.strictEqual( edit
.newrevid
, 13 );
50 QUnit
.test( 'edit( mw.Title, transform String )', function ( assert
) {
51 this.server
.respond( function ( req
) {
52 if ( /query.+titles=Sandbox/.test( req
.url
) ) {
53 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
54 curtimestamp
: '2016-01-02T12:00:00Z',
61 timestamp
: '2016-01-01T12:00:00Z',
62 contentformat
: 'text/x-wiki',
63 contentmodel
: 'wikitext',
70 if ( /edit.+basetimestamp=2016-01-01.+starttimestamp=2016-01-02.+text=Box%2E/.test( req
.requestBody
) ) {
71 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
76 newtimestamp
: '2016-01-03T12:00:00Z'
83 .edit( new mw
.Title( 'Sandbox' ), function ( revision
) {
84 return revision
.content
.replace( 'Sand', 'Box' );
86 .then( function ( edit
) {
87 assert
.strictEqual( edit
.newrevid
, 13 );
91 QUnit
.test( 'edit( title, transform Promise )', function ( assert
) {
92 this.server
.respond( function ( req
) {
93 if ( /query.+titles=Async/.test( req
.url
) ) {
94 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
95 curtimestamp
: '2016-02-02T12:00:00Z',
102 timestamp
: '2016-02-01T12:00:00Z',
103 contentformat
: 'text/x-wiki',
104 contentmodel
: 'wikitext',
111 if ( /edit.+basetimestamp=2016-02-01.+starttimestamp=2016-02-02.+text=Promise%2E/.test( req
.requestBody
) ) {
112 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
117 newtimestamp
: '2016-02-03T12:00:00Z'
124 .edit( 'Async', function ( revision
) {
125 return $.Deferred().resolve( revision
.content
.replace( 'Async', 'Promise' ) );
127 .then( function ( edit
) {
128 assert
.strictEqual( edit
.newrevid
, 23 );
132 QUnit
.test( 'edit( title, transform Object )', function ( assert
) {
133 this.server
.respond( function ( req
) {
134 if ( /query.+titles=Param/.test( req
.url
) ) {
135 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
136 curtimestamp
: '2016-03-02T12:00:00Z',
143 timestamp
: '2016-03-01T12:00:00Z',
144 contentformat
: 'text/x-wiki',
145 contentmodel
: 'wikitext',
152 if ( /edit.+basetimestamp=2016-03-01.+starttimestamp=2016-03-02.+text=Content&summary=Sum/.test( req
.requestBody
) ) {
153 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
158 newtimestamp
: '2016-03-03T12:00:00Z'
165 .edit( 'Param', function () {
166 return { text
: 'Content', summary
: 'Sum' };
168 .then( function ( edit
) {
169 assert
.strictEqual( edit
.newrevid
, 33 );
173 QUnit
.test( 'edit( invalid-title, transform String )', function ( assert
) {
174 this.server
.respond( function ( req
) {
175 if ( /query.+titles=%1F%7C/.test( req
.url
) ) {
176 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
180 invalidreason
: 'The requested page title contains invalid characters: "|".',
189 .edit( '|', function ( revision
) {
190 return revision
.content
.replace( 'Sand', 'Box' );
193 return $.Deferred().reject( 'Unexpected success' );
194 }, function ( reason
) {
195 assert
.strictEqual( reason
, 'invalidtitle' );
199 QUnit
.test( 'create( title, content )', function ( assert
) {
200 this.server
.respond( function ( req
) {
201 if ( /edit.+text=Sand/.test( req
.requestBody
) ) {
202 req
.respond( 200, { 'Content-Type': 'application/json' }, JSON
.stringify( {
207 newtimestamp
: '2016-04-01T12:00:00Z'
214 .create( 'Sandbox', { summary
: 'Load sand particles.' }, 'Sand.' )
215 .then( function ( page
) {
216 assert
.strictEqual( page
.newrevid
, 41 );
220 }( mediaWiki
, jQuery
) );