Debian Codegraph @

vendor/wikimedia/parsoid/tests/api-testing/Parsoid.js

raw
1 /** Cases for testing the Parsoid API through HTTP */
2 /* global describe, it, before */
3
4 'use strict';
5
6 const { action, assert, REST, utils } = require( 'api-testing' );
7
8 var domino = require('domino');
9 var should = require('chai').should();
10 var semver = require('semver');
11 var url = require('url');
12 const { DOMUtils } = require( "../../lib/utils/DOMUtils" );
13
14 var Util = require('../../lib/utils/Util.js').Util;
15 var JSUtils = require('../../lib/utils/jsutils').JSUtils;
16
17 const parsoidOptions = {
18 limits: {
19 wt2html: { maxWikitextSize: 20000 },
20 html2wt: { maxHTMLSize: 10000 },
21 },
22 };
23
24 // FIXME(T283875): These should all be re-enabled
25 var skipForNow = true;
26
27 var defaultContentVersion = '2.8.0';
28
29 // section wrappers are a distraction from the main business of
30 // this file which is to verify functionality of API end points
31 // independent of what they are returning and computing.
32 //
33 // Verifying the correctness of content is actually the job of
34 // parser tests and other tests.
35 //
36 // So, hide most of that that distraction in a helper.
37 //
38 // Right now, all uses of this helper have empty lead sections.
39 // But, maybe in the future, this may change. So, retain the option.
40 function validateDoc(doc, nodeName, emptyLead) {
41 var leadSection = doc.body.firstChild;
42 leadSection.nodeName.should.equal('SECTION');
43 if (emptyLead) {
44 // Could have whitespace and comments
45 leadSection.childElementCount.should.equal(0);
46 }
47 var nonEmptySection = emptyLead ? leadSection.nextSibling : leadSection;
48 nonEmptySection.firstChild.nodeName.should.equal(nodeName);
49 }
50
51 function status200( res ) {
52 assert.strictEqual( res.status, 200, res.text );
53 }
54
55 // Return a matcher function that checks whether a content type matches the given parameters.
56 function contentTypeMatcher( expectedMime, expectedSpec, expectedVersion ) {
57 const pattern = /^([-\w]+\/[-\w]+);(?: charset=utf-8;)? profile="https:\/\/www.mediawiki.org\/wiki\/Specs\/([-\w]+)\/(\d+\.\d+\.\d+)"$/;
58
59 return ( actual ) => {
60 const parts = pattern.exec( actual );
61 if ( !parts ) {
62 return false;
63 }
64
65 const [ , mime, spec, version ] = parts;
66
67 // match version using caret semantics
68 if ( !semver.satisfies( version, `^${ expectedVersion || defaultContentVersion }` ) ) {
69 return false;
70 }
71
72 if ( mime !== expectedMime || spec !== expectedSpec ) {
73 return false;
74 }
75
76 return true;
77 };
78 }
79
80 describe('Parsoid API', function() {
81 const client = new REST();
82 const parsedUrl = new url.URL(client.req.app);
83 const hostname = parsedUrl.hostname;
84 const mockDomain = client.pathPrefix = `rest.php/${ hostname }`;
85 const page = utils.title( 'Lint Page ' );
86 const pageEncoded = encodeURIComponent( page );
87 let revid, oldrevid;
88
89 before(async function() {
90 this.timeout(30000);
91
92 const alice = await action.alice();
93
94 // Create pages
95 const oldEdit = await alice.edit(page, { text: 'First Revision Content' });
96 oldEdit.result.should.equal('Success');
97 oldrevid = oldEdit.newrevid;
98
99 let edit = await alice.edit(page, { text: '{|\n|hi\n|ho\n|}' });
100 edit.result.should.equal('Success');
101 revid = edit.newrevid;
102
103 edit = await alice.edit('JSON Page', {
104 text: '[1]', contentmodel: 'json'
105 });
106 edit.result.should.equal('Success');
107 });
108
109 const acceptableHtmlResponse = function(contentVersion, expectFunc) {
110 return function(res) {
111 res.statusCode.should.equal(200, res.text);
112 res.headers.should.have.property('content-type');
113 res.headers['content-type'].should.equal(
114 'text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + contentVersion + '"'
115 );
116 res.text.should.not.equal('');
117 if (expectFunc) {
118 return expectFunc(res.text);
119 }
120 };
121 };
122
123 const acceptablePageBundleResponse = function(contentVersion, expectFunc) {
124 return function(res) {
125 res.statusCode.should.equal(200, res.text);
126 res.headers.should.have.property('content-type');
127 res.headers['content-type'].should.satisfy( contentTypeMatcher( 'application/json', 'pagebundle', contentVersion ) );
128 res.body.should.have.property('html');
129 res.body.html.should.have.property('headers');
130 res.body.html.headers.should.have.property('content-type');
131 res.body.html.headers['content-type'].should.satisfy( contentTypeMatcher( 'text/html', 'HTML', contentVersion ) );
132 res.body.html.should.have.property('body');
133 res.body.should.have.property('data-parsoid');
134 res.body['data-parsoid'].should.have.property('headers');
135 res.body['data-parsoid'].headers.should.have.property('content-type');
136 res.body['data-parsoid'].headers['content-type'].should.satisfy( contentTypeMatcher( 'application/json', 'data-parsoid', contentVersion ) );
137 res.body['data-parsoid'].should.have.property('body');
138 if (semver.gte(contentVersion, '999.0.0')) {
139 res.body.should.have.property('data-mw');
140 res.body['data-mw'].should.have.property('headers');
141 res.body['data-mw'].headers.should.have.property('content-type');
142 res.body['data-mw'].headers['content-type'].should.satisfy( contentTypeMatcher( 'application/json', 'data-mw', contentVersion ) );
143 res.body['data-mw'].should.have.property('body');
144 }
145 if (expectFunc) {
146 return expectFunc(res.body.html.body);
147 }
148 };
149 };
150
151 describe('domain check', function() {
152 it('should apply to /v3/transform endpoint', function(done) {
153 client.req
154 .get('rest.php/the.wrong.domain/v3/page/wikitext/' + pageEncoded )
155 .expect(function(res) {
156 res.status.should.equal(400, res.text);
157 res.body.error.should.equal('parameter-validation-failed');
158 res.body.failureCode.should.equal('invalid-domain');
159 })
160 .end(done);
161 });
162
163 it('should apply to /v3/transform endpoint', function(done) {
164 client.req
165 .post('rest.php/the.wrong.domain/v3/transform/wikitext/to/html/')
166 .send({ wikitext: '== h2 ==' })
167 .expect(function(res) {
168 res.status.should.equal(400, res.text);
169 res.body.error.should.equal('parameter-validation-failed');
170 res.body.failureCode.should.equal('invalid-domain');
171 })
172 .end(done);
173 });
174 });
175
176 describe('formats', function() {
177
178 it('should accept application/x-www-form-urlencoded', function(done) {
179 client.req
180 .post(mockDomain + '/v3/transform/wikitext/to/html/')
181 .type('form')
182 .send({
183 wikitext: '== h2 ==',
184 })
185 .expect(status200)
186 .expect(function(res) {
187 validateDoc(domino.createDocument(res.text), 'H2', true);
188 })
189 .end(done);
190 });
191
192 it('should accept application/json', function(done) {
193 client.req
194 .post(mockDomain + '/v3/transform/wikitext/to/html/')
195 .type('json')
196 .send({
197 wikitext: '== h2 ==',
198 })
199 .expect(status200)
200 .expect(function(res) {
201 validateDoc(domino.createDocument(res.text), 'H2', true);
202 })
203 .end(done);
204 });
205
206 it('should accept multipart/form-data', function(done) {
207 client.req
208 .post(mockDomain + '/v3/transform/wikitext/to/html/')
209 .field('wikitext', '== h2 ==')
210 .expect(status200)
211 .expect(function(res) {
212 validateDoc(domino.createDocument(res.text), 'H2', true);
213 })
214 .end(done);
215 });
216
217 // Skipped because all errors are returned as JSON in Parsoid/PHP
218 it.skip('should return a plaintext error', function(done) {
219 client.req
220 .get(mockDomain + '/v3/page/wikitext/Doesnotexist')
221 .expect(404)
222 .expect(function(res) {
223 res.headers['content-type'].should.equal(
224 'text/plain; charset=utf-8'
225 );
226 res.text.should.equal('Did not find page revisions for Doesnotexist');
227 })
228 .end(done);
229 });
230
231 it('should return a json error', function(done) {
232 client.req
233 .get(mockDomain + '/v3/page/pagebundle/Doesnotexist')
234 .expect(404)
235 .expect(function(res) {
236 res.headers['content-type'].should.equal(
237 'application/json'
238 );
239 res.body.errorKey.should.equal('rest-specified-revision-unavailable');
240 })
241 .end(done);
242 });
243
244 // Skipped because all errors are returned as JSON in Parsoid/PHP
245 it.skip('should return an html error', function(done) {
246 client.req
247 .get('<img src=x onerror="javascript:alert(\'hi\')">/v3/page/html/XSS')
248 .expect(404)
249 .expect(function(res) {
250 res.headers['content-type'].should.equal(
251 'text/html; charset=utf-8'
252 );
253 res.text.should.equal('Invalid domain: &lt;img src=x onerror=&quot;javascript:alert(&apos;hi&apos;)&quot;&gt;');
254 })
255 .end(done);
256 });
257
258 }); // formats
259
260 describe('accepts', function() {
261
262 it('should not accept requests for older content versions (html)', function(done) {
263 client.req
264 .post(mockDomain + '/v3/transform/wikitext/to/html/')
265 .set('Accept', 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/0.0.0"')
266 .send({ wikitext: '== h2 ==' })
267 .expect(406)
268 .expect(function(res) {
269 // FIXME: See skipped html error test above
270 JSON.parse(res.error.text).errorKey.should.equal(
271 'rest-unsupported-target-format'
272 );
273 })
274 .end(done);
275 });
276
277 it('should not accept requests for older content versions (pagebundle)', function(done) {
278 client.req
279 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
280 .set('Accept', 'application/json; profile="https://www.mediawiki.org/wiki/Specs/HTML/0.0.0"')
281 .send({ wikitext: '== h2 ==' })
282 .expect(406)
283 .expect(function(res) {
284 JSON.parse(res.error.text).errorKey.should.equal(
285 'rest-unsupported-target-format'
286 );
287 })
288 .end(done);
289 });
290
291 it('should not accept requests for other profiles (html)', function(done) {
292 client.req
293 .post(mockDomain + '/v3/transform/wikitext/to/html/')
294 .set('Accept', 'text/html; profile="something different"')
295 .send({ wikitext: '== h2 ==' })
296 .expect(406)
297 .end(done);
298 });
299
300 it('should not accept requests for other profiles (pagebundle)', function(done) {
301 client.req
302 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
303 .set('Accept', 'application/json; profile="something different"')
304 .send({ wikitext: '== h2 ==' })
305 .expect(406)
306 .end(done);
307 });
308
309 it('should accept wildcards (html)', function(done) {
310 client.req
311 .post(mockDomain + '/v3/transform/wikitext/to/html/')
312 .set('Accept', '*/*')
313 .send({ wikitext: '== h2 ==' })
314 .expect(status200)
315 .expect(acceptableHtmlResponse(defaultContentVersion))
316 .end(done);
317 });
318
319 it('should accept wildcards (pagebundle)', function(done) {
320 client.req
321 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
322 .set('Accept', '*/*')
323 .send({ wikitext: '== h2 ==' })
324 .expect(status200)
325 .expect(acceptablePageBundleResponse(defaultContentVersion))
326 .end(done);
327 });
328
329 // T347426: Support for non-default major HTML versions has been disabled
330 it.skip('should prefer higher quality (html)', function(done) {
331 var contentVersion = '999.0.0';
332 client.req
333 .post(mockDomain + '/v3/transform/wikitext/to/html/')
334 .set('Accept',
335 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/2.8.0"; q=0.5,' +
336 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"; q=0.8')
337 .send({ wikitext: '== h2 ==' })
338 .expect(status200)
339 .expect(acceptableHtmlResponse(contentVersion))
340 .end(done);
341 });
342
343 // T347426: Support for non-default major HTML versions has been disabled
344 it.skip('should prefer higher quality (pagebundle)', function(done) {
345 var contentVersion = '999.0.0';
346 client.req
347 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
348 .set('Accept',
349 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/2.8.0"; q=0.5,' +
350 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/999.0.0"; q=0.8')
351 .send({ wikitext: '== h2 ==' })
352 .expect(status200)
353 .expect(acceptablePageBundleResponse(contentVersion))
354 .end(done);
355 });
356
357 it('should accept requests for the latest content version (html)', function(done) {
358 client.req
359 .post(mockDomain + '/v3/transform/wikitext/to/html/')
360 .send({ wikitext: '== h2 ==' })
361 .expect(status200)
362 .expect(acceptableHtmlResponse(defaultContentVersion))
363 .end(done);
364 });
365
366 it('should accept requests for the latest content version (pagebundle)', function(done) {
367 client.req
368 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
369 .send({ wikitext: '== h2 ==' })
370 .expect(status200)
371 .expect(acceptablePageBundleResponse(defaultContentVersion))
372 .end(done);
373 });
374
375 it('should accept requests for content version 2.x (html)', function(done) {
376 var contentVersion = '2.8.0';
377 client.req
378 .post(mockDomain + '/v3/transform/wikitext/to/html/')
379 .set('Accept', 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + contentVersion + '"')
380 .send({ wikitext: '{{1x|hi}}' })
381 .expect(status200)
382 .expect(acceptableHtmlResponse(contentVersion))
383 .end(done);
384 });
385
386 it('should accept requests for content version 2.x (pagebundle)', function(done) {
387 var contentVersion = '2.8.0';
388 client.req
389 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
390 .set('Accept', 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/' + contentVersion + '"')
391 .send({ wikitext: '{{1x|hi}}' })
392 .expect(status200)
393 .expect(acceptablePageBundleResponse(contentVersion, function(html) {
394 // In < 999.x, data-mw is still inline.
395 html.should.match(/\s+data-mw\s*=\s*['"]/);
396 }))
397 .end(done);
398 });
399
400 // Note that these tests aren't that useful directly after a major version bump
401
402 it('should accept requests for older content version 2.x (html)', function(done) {
403 var contentVersion = '2.8.0';
404 client.req
405 .post(mockDomain + '/v3/transform/wikitext/to/html/')
406 .set('Accept', 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/2.0.0"') // Keep this on the older version
407 .send({ wikitext: '{{1x|hi}}' })
408 .expect(status200)
409 .expect(acceptableHtmlResponse(contentVersion))
410 .end(done);
411 });
412
413 it('should accept requests for older content version 2.x (pagebundle)', function(done) {
414 var contentVersion = '2.8.0';
415 client.req
416 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
417 .set('Accept', 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/2.0.0"') // Keep this on the older version
418 .send({ wikitext: '{{1x|hi}}' })
419 .expect(status200)
420 .expect(acceptablePageBundleResponse(contentVersion, function(html) {
421 // In < 999.x, data-mw is still inline.
422 html.should.match(/\s+data-mw\s*=\s*['"]/);
423 }))
424 .end(done);
425 });
426
427 it('should sanity check 2.x content (pagebundle)', function(done) {
428 if (skipForNow) {
429 return this.skip();
430 } // Missing files in wiki
431 var contentVersion = '2.8.0';
432 client.req
433 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
434 .set('Accept', 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/' + contentVersion + '"')
435 .send({ wikitext: '[[File:Audio.oga]]' })
436 .expect(status200)
437 .expect(acceptablePageBundleResponse(contentVersion, function(html) {
438 var doc = domino.createDocument(html);
439 doc.querySelectorAll('audio').length.should.equal(1);
440 doc.querySelectorAll('video').length.should.equal(0);
441 }))
442 .end(done);
443 });
444
445 // T347426: Support for non-default major HTML versions has been disabled
446 it.skip('should accept requests for content version 999.x (html)', function(done) {
447 var contentVersion = '999.0.0';
448 client.req
449 .post(mockDomain + '/v3/transform/wikitext/to/html/')
450 .set('Accept', 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + contentVersion + '"')
451 .send({ wikitext: '{{1x|hi}}' })
452 .expect(status200)
453 .expect(acceptableHtmlResponse(contentVersion))
454 .end(done);
455 });
456
457 // T347426: Support for non-default major HTML versions has been disabled
458 it.skip('should accept requests for content version 999.x (pagebundle)', function(done) {
459 var contentVersion = '999.0.0';
460 client.req
461 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
462 .set('Accept', 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/' + contentVersion + '"')
463 .send({ wikitext: '{{1x|hi}}' })
464 .expect(status200)
465 .expect(acceptablePageBundleResponse(contentVersion, function(html) {
466 // In 999.x, data-mw is in the pagebundle.
467 html.should.not.match(/\s+data-mw\s*=\s*['"]/);
468 }))
469 .end(done);
470 });
471
472 }); // accepts
473
474 const validWikitextResponse = function(expected) {
475 return function(res) {
476 res.statusCode.should.equal(200, res.text);
477 res.headers.should.have.property('content-type');
478 res.headers['content-type'].should.satisfy( contentTypeMatcher( 'text/plain', 'wikitext', '1.0.0' ) );
479 if (expected !== undefined) {
480 res.text.should.equal(expected);
481 } else {
482 res.text.should.not.equal('');
483 }
484 };
485 };
486
487 const validHtmlResponse = function(expectFunc) {
488 return function(res) {
489 res.statusCode.should.equal(200, res.text);
490 res.headers.should.have.property('content-type');
491 res.headers['content-type'].should.satisfy( contentTypeMatcher( 'text/html', 'HTML' ) );
492 var doc = domino.createDocument(res.text);
493 if (expectFunc) {
494 return expectFunc(doc);
495 } else {
496 res.text.should.not.equal('');
497 }
498 };
499 };
500
501 const validJsonResponse = function(expected) {
502 return function(res) {
503 res.statusCode.should.equal(200, res.text);
504 res.headers.should.have.property('content-type');
505 res.headers['content-type'].should.equal( 'application/json' );
506 if (expected !== undefined) {
507 res.text.should.equal(expected);
508 } else {
509 res.text.should.not.equal('');
510 }
511 };
512 };
513
514 const validPageBundleResponse = function(expectFunc) {
515 return function(res) {
516 res.statusCode.should.equal(200, res.text);
517 res.body.should.have.property('html');
518 res.body.html.should.have.property('headers');
519 res.body.html.headers.should.have.property('content-type');
520 res.body.html.headers['content-type'].should.satisfy( contentTypeMatcher( 'text/html', 'HTML' ) );
521 res.body.html.should.have.property('body');
522 res.body.should.have.property('data-parsoid');
523 res.body['data-parsoid'].should.have.property('headers');
524 res.body['data-parsoid'].headers.should.have.property('content-type');
525 res.body['data-parsoid'].headers['content-type'].should.satisfy( contentTypeMatcher( 'application/json', 'data-parsoid' ) );
526 res.body['data-parsoid'].should.have.property('body');
527 // TODO: Check data-mw when 999.x is the default.
528 console.assert(!semver.gte(defaultContentVersion, '999.0.0'));
529 var doc = domino.createDocument(res.body.html.body);
530 if (expectFunc) {
531 return expectFunc(doc, res.body['data-parsoid'].body);
532 }
533 };
534 };
535
536 describe('wt2lint', function() {
537
538 it('should lint the given page', function(done) {
539 if (skipForNow) {
540 return this.skip();
541 } // Enable linting config
542 client.req
543 .get(mockDomain + '/v3/page/lint/' + page + '/' + revid )
544 .expect(status200)
545 .expect(function(res) {
546 res.body.should.be.instanceof(Array);
547 res.body.length.should.equal(1);
548 res.body[0].type.should.equal('fostered');
549 })
550 .end(done);
551 });
552
553 it('should lint the given wikitext', function(done) {
554 if (skipForNow) {
555 return this.skip();
556 } // Enable linting config
557 client.req
558 .post(mockDomain + '/v3/transform/wikitext/to/lint/')
559 .send({
560 wikitext: {
561 headers: {
562 'content-type': 'text/plain;profile="https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0"',
563 },
564 body: "{|\nhi\n|ho\n|}",
565 },
566 })
567 .expect(status200)
568 .expect(function(res) {
569 res.body.should.be.instanceof(Array);
570 res.body.length.should.equal(1);
571 res.body[0].type.should.equal('fostered');
572 })
573 .end(done);
574 });
575
576 it('should lint the given page, transform', function(done) {
577 if (skipForNow) {
578 return this.skip();
579 } // Enable linting config
580 client.req
581 .post(mockDomain + '/v3/transform/wikitext/to/lint/' + page + '/' + revid)
582 .send({})
583 .expect(status200)
584 .expect(function(res) {
585 res.body.should.be.instanceof(Array);
586 res.body.length.should.equal(1);
587 res.body[0].type.should.equal('fostered');
588 })
589 .end(done);
590 });
591
592 it('should redirect title to latest revision (lint)', function(done) {
593 client.req
594 .post(mockDomain + '/v3/transform/wikitext/to/lint/')
595 .send({
596 // no revid or wikitext source provided
597 original: {
598 title: page,
599 },
600 })
601 .expect( validJsonResponse() )
602 .end(done);
603 });
604
605 });
606
607 describe("wt2html", function() {
608
609 it('should get from a title and old revision (html)', function(done) {
610 client.req
611 .get(mockDomain + `/v3/page/html/${ page }/${ oldrevid }`)
612 .redirects( 0 )
613 .expect(validHtmlResponse(function(doc) {
614 doc.body.firstChild.firstChild.textContent.should.contain('First Revision Content');
615 }))
616 .end(done);
617 });
618
619 it('should get from a title and current revision (html)', function(done) {
620 client.req
621 .get(mockDomain + `/v3/page/html/${ page }`)
622 .redirects( 1 )
623 .expect(validHtmlResponse(function(doc) {
624 doc.body.firstChild.firstChild.textContent.should.contain('hi');
625 }))
626 .end(done);
627 });
628
629 // Disabled for T349098
630 it.skip('should get from a title and current revision (html, json content)', function(done) {
631 client.req
632 .get(mockDomain + '/v3/page/html/JSON_Page')
633 .redirects(1)
634 .expect(validHtmlResponse(function(doc) {
635 doc.body.firstChild.nodeName.should.equal('TABLE');
636 }))
637 .end(done);
638 });
639
640 it('should get from a title and revision (pagebundle)', function(done) {
641 client.req
642 .get(mockDomain + `/v3/page/pagebundle/${ page }/${ revid }`)
643 .redirects( 0 )
644 .expect(validPageBundleResponse())
645 .end(done);
646 });
647
648 // Disabled for T349098
649 it.skip('should get from a title and revision (pagebundle, json content)', function(done) {
650 client.req
651 .get(mockDomain + '/v3/page/pagebundle/JSON_Page')
652 .redirects(1)
653 .expect(validPageBundleResponse(function(doc) {
654 doc.body.firstChild.nodeName.should.equal('TABLE');
655 }))
656 .end(done);
657 });
658
659 it('should get from a title and revision (wikitext)', function(done) {
660 client.req
661 .get(mockDomain + `/v3/page/wikitext/${ page }/${ oldrevid }`)
662 .redirects( 0 )
663 .expect(validWikitextResponse('First Revision Content'))
664 .end(done);
665 });
666
667 it.skip('should set a custom etag for get requests (html)', function(done) {
668 const etagPrefixExp = new RegExp( '^"' + revid + '/' );
669 client.req
670 .get(mockDomain + `/v3/page/html/${ page }/${ revid }`)
671 .expect(validHtmlResponse())
672 .expect((res) => {
673 res.headers.should.have.property('etag');
674 res.headers.etag.should.match( etagPrefixExp );
675 })
676 .end(done);
677 });
678
679 it.skip('should set a custom etag for get requests (pagebundle)', function(done) {
680 const etagPrefixExp = new RegExp( '^"' + revid + '/' );
681 client.req
682 .get(mockDomain + `/v3/page/pagebundle/${ page }/${ revid }`)
683 .expect(validPageBundleResponse())
684 .expect((res) => {
685 res.headers.should.have.property('etag');
686 res.headers.etag.should.match( etagPrefixExp );
687 })
688 .end(done);
689 });
690
691 it('should accept wikitext as a string for html', function(done) {
692 client.req
693 .post(mockDomain + '/v3/transform/wikitext/to/html/')
694 .send({
695 wikitext: "== h2 ==",
696 })
697 .expect(validHtmlResponse(function(doc) {
698 validateDoc(doc, 'H2', true);
699 }))
700 .end(done);
701 });
702
703 it('should accept json contentmodel as a string for html', function(done) {
704 client.req
705 .post(mockDomain + '/v3/transform/wikitext/to/html/')
706 .send({
707 wikitext: '{"1":2}',
708 contentmodel: 'json',
709 })
710 .expect(validHtmlResponse(function(doc) {
711 doc.body.firstChild.nodeName.should.equal('TABLE');
712 }))
713 .end(done);
714 });
715
716 it('should accept wikitext as a string for pagebundle', function(done) {
717 client.req
718 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
719 .send({
720 wikitext: "== h2 ==",
721 })
722 .expect(validPageBundleResponse(function(doc) {
723 validateDoc(doc, 'H2', true);
724 }))
725 .end(done);
726 });
727
728 it('should accept json contentmodel as a string for pagebundle', function(done) {
729 client.req
730 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
731 .send({
732 wikitext: '{"1":2}',
733 contentmodel: 'json',
734 })
735 .expect(validPageBundleResponse(function(doc) {
736 doc.body.firstChild.nodeName.should.equal('TABLE');
737 should.not.exist(doc.querySelector('*[typeof="mw:Error"]'));
738 }))
739 .end(done);
740 });
741
742 it('should accept wikitext with headers', function(done) {
743 client.req
744 .post(mockDomain + '/v3/transform/wikitext/to/html/')
745 .send({
746 wikitext: {
747 headers: {
748 'content-type': 'text/plain;profile="https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0"',
749 },
750 body: "== h2 ==",
751 },
752 })
753 .expect(validHtmlResponse(function(doc) {
754 validateDoc(doc, 'H2', true);
755 }))
756 .end(done);
757 });
758
759 it('should require a title when no wikitext is provided (html)', function(done) {
760 client.req
761 .post(mockDomain + '/v3/transform/wikitext/to/html/')
762 .send({})
763 .expect(400)
764 .end(done);
765 });
766
767 it('should require a title when no wikitext is provided (pagebundle)', function(done) {
768 client.req
769 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
770 .send({})
771 .expect(400)
772 .end(done);
773 });
774
775 it('should error when revision not found (page, html)', function(done) {
776 client.req
777 .get(mockDomain + '/v3/page/html/Doesnotexist')
778 .expect(404)
779 .end(done);
780 });
781
782 it('should error when revision not found (page, pagebundle)', function(done) {
783 client.req
784 .get(mockDomain + '/v3/page/pagebundle/Doesnotexist')
785 .expect(404)
786 .end(done);
787 });
788
789 it('should error when revision not found (transform, wt2html)', function(done) {
790 client.req
791 .post(mockDomain + '/v3/transform/wikitext/to/html/Doesnotexist')
792 .send({})
793 .expect(404)
794 .end(done);
795 });
796
797 it('should error when revision not found (transform, wt2pb)', function(done) {
798 client.req
799 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/Doesnotexist')
800 .send({})
801 .expect(404)
802 .end(done);
803 });
804
805 it('should accept an original title (html)', function(done) {
806 client.req
807 .post(mockDomain + '/v3/transform/wikitext/to/html/')
808 .send({
809 // no revid or wikitext source provided
810 original: {
811 title: page,
812 },
813 })
814 .expect(validHtmlResponse())
815 .end(done);
816 });
817
818 it('should accept an original title (pagebundle)', function(done) {
819 client.req
820 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
821 .send({
822 // no revid or wikitext source provided
823 original: {
824 title: page,
825 },
826 })
827 .expect(validPageBundleResponse())
828 .end(done);
829 });
830
831 it('should accept an original title, other than main', function(done) {
832 client.req
833 .post(mockDomain + '/v3/transform/wikitext/to/html/')
834 .send({
835 // no revid or wikitext source provided
836 original: {
837 title: page,
838 },
839 })
840 .expect(validHtmlResponse())
841 .end(done);
842 });
843
844 it('should not require a title when empty wikitext is provided (html)', function(done) {
845 client.req
846 .post(mockDomain + '/v3/transform/wikitext/to/html/')
847 .send({
848 wikitext: '',
849 })
850 .expect(validHtmlResponse(function(doc) {
851 doc.body.children.length.should.equal(1); // empty lead section
852 doc.body.firstChild.nodeName.should.equal('SECTION');
853 doc.body.firstChild.children.length.should.equal(0);
854 }))
855 .end(done);
856 });
857
858 it('should not require a title when empty wikitext is provided (pagebundle)', function(done) {
859 client.req
860 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
861 .send({
862 wikitext: '',
863 })
864 .expect(validPageBundleResponse())
865 .end(done);
866 });
867
868 it('should not require a title when wikitext is provided', function(done) {
869 client.req
870 .post(mockDomain + '/v3/transform/wikitext/to/html/')
871 .send({
872 wikitext: "== h2 ==",
873 })
874 .expect(validHtmlResponse(function(doc) {
875 validateDoc(doc, 'H2', true);
876 }))
877 .end(done);
878 });
879
880 it('should not require a rev id when wikitext and a title is provided', function(done) {
881 client.req
882 .post(mockDomain + '/v3/transform/wikitext/to/html/Main_Page')
883 .send({
884 wikitext: "== h2 ==",
885 })
886 .expect(validHtmlResponse(function(doc) {
887 validateDoc(doc, 'H2', true);
888 }))
889 .end(done);
890 });
891
892 it('should accept the wikitext source as original data', function(done) {
893 client.req
894 .post(mockDomain + `/v3/transform/wikitext/to/html/${ page }/${ revid }`)
895 .send({
896 original: {
897 wikitext: {
898 headers: {
899 'content-type': 'text/plain;profile="https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0"',
900 },
901 body: "== h2 ==",
902 },
903 },
904 })
905 .expect(validHtmlResponse(function(doc) {
906 validateDoc(doc, 'H2', true);
907 }))
908 .end(done);
909 });
910
911 it('should use the proper source text', function(done) {
912 if (skipForNow) {
913 return this.skip();
914 } // Missing template 1x
915 client.req
916 .post(mockDomain + `/v3/transform/wikitext/to/html/${ page }/${ revid }`)
917 .send({
918 original: {
919 wikitext: {
920 headers: {
921 'content-type': 'text/plain;profile="https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0"',
922 },
923 body: "{{1x|foo|bar=bat}}",
924 },
925 },
926 })
927 .expect(validHtmlResponse(function(doc) {
928 validateDoc(doc, 'P', false);
929 var span = doc.querySelector('span[typeof="mw:Transclusion"]');
930 var dmw = JSON.parse(span.getAttribute('data-mw'));
931 var template = dmw.parts[0].template;
932 template.target.wt.should.equal('1x');
933 template.params[1].wt.should.equal('foo');
934 template.params.bar.wt.should.equal('bat');
935 }))
936 .end(done);
937 });
938
939 it('should accept the wikitext source as original without a title or revision', function(done) {
940 client.req
941 .post(mockDomain + '/v3/transform/wikitext/to/html/')
942 .send({
943 original: {
944 wikitext: {
945 headers: {
946 'content-type': 'text/plain;profile="https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0"',
947 },
948 body: "== h2 ==",
949 },
950 },
951 })
952 .expect(validHtmlResponse(function(doc) {
953 validateDoc(doc, 'H2', true);
954 }))
955 .end(done);
956 });
957
958 it("should respect body parameter in wikitext->html (body_only)", function(done) {
959 client.req
960 .post(mockDomain + '/v3/transform/wikitext/to/html/')
961 .send({
962 wikitext: "''foo''",
963 body_only: 1,
964 })
965 .expect(validHtmlResponse())
966 .expect(function(res) {
967 // v3 only returns children of <body>
968 res.text.should.not.match(/<body/);
969 res.text.should.match(/<p/);
970 })
971 .end(done);
972 });
973
974 it("should respect body parameter in wikitext->pagebundle requests (body_only)", function(done) {
975 client.req
976 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
977 .send({
978 wikitext: "''foo''",
979 body_only: 1,
980 })
981 .expect(validPageBundleResponse())
982 .expect(function(res) {
983 // v3 only returns children of <body>
984 res.body.html.body.should.not.match(/<body/);
985 res.body.html.body.should.match(/<p/);
986 // No section wrapping in body-only mode
987 res.body.html.body.should.not.match(/<section/);
988 })
989 .end(done);
990 });
991
992 it('should not include captured offsets', function(done) {
993 client.req
994 .get(mockDomain + `/v3/page/pagebundle/${ page }/${ revid }`)
995 .expect(validPageBundleResponse(function(doc, dp) {
996 dp.should.not.have.property('sectionOffsets');
997 }))
998 .end(done);
999 });
1000
1001 it('should return a request too large error (post wt)', function(done) {
1002 if (skipForNow) {
1003 return this.skip();
1004 } // Set limits in config
1005 client.req
1006 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
1007 .send({
1008 original: {
1009 title: 'Large_Page',
1010 },
1011 wikitext: "a".repeat(parsoidOptions.limits.wt2html.maxWikitextSize + 1),
1012 })
1013 .expect(413)
1014 .end(done);
1015 });
1016
1017 it('should return a request too large error (get page)', function(done) {
1018 if (skipForNow) {
1019 return this.skip();
1020 } // Set limits in config
1021 client.req
1022 .get(mockDomain + '/v3/page/html/Large_Page/3')
1023 .expect(413)
1024 .end(done);
1025 });
1026
1027 it('should add redlinks for get (html)', function(done) {
1028 if (skipForNow) {
1029 return this.skip();
1030 } // Create Relinks_Page
1031 client.req
1032 .get(mockDomain + '/v3/page/html/Redlinks_Page/103')
1033 .expect(validHtmlResponse(function(doc) {
1034 doc.body.querySelectorAll('a').length.should.equal(3);
1035 var redLinks = doc.body.querySelectorAll('.new');
1036 redLinks.length.should.equal(1);
1037 redLinks[0].getAttribute('title').should.equal('Doesnotexist');
1038 var redirects = doc.body.querySelectorAll('.mw-redirect');
1039 redirects.length.should.equal(1);
1040 redirects[0].getAttribute('title').should.equal('Redirected');
1041 }))
1042 .end(done);
1043 });
1044
1045 it('should add redlinks for get (pagebundle)', function(done) {
1046 if (skipForNow) {
1047 return this.skip();
1048 } // Create Redlinks_Page
1049 client.req
1050 .get(mockDomain + '/v3/page/pagebundle/Redlinks_Page/103')
1051 .expect(validPageBundleResponse(function(doc) {
1052 doc.body.querySelectorAll('a').length.should.equal(3);
1053 var redLinks = doc.body.querySelectorAll('.new');
1054 redLinks.length.should.equal(1);
1055 redLinks[0].getAttribute('title').should.equal('Doesnotexist');
1056 var redirects = doc.body.querySelectorAll('.mw-redirect');
1057 redirects.length.should.equal(1);
1058 redirects[0].getAttribute('title').should.equal('Redirected');
1059 }))
1060 .end(done);
1061 });
1062
1063 it('should add redlinks for transform (html)', function(done) {
1064 if (skipForNow) {
1065 return this.skip();
1066 } // Fix redlinks count, by creating pages
1067 client.req
1068 .post(mockDomain + '/v3/transform/wikitext/to/html/')
1069 .send({
1070 wikitext: "[[Special:Version]] [[Doesnotexist]] [[Redirected]]",
1071 })
1072 .expect(validHtmlResponse(function(doc) {
1073 doc.body.querySelectorAll('a').length.should.equal(3);
1074 var redLinks = doc.body.querySelectorAll('.new');
1075 redLinks.length.should.equal(1);
1076 redLinks[0].getAttribute('title').should.equal('Doesnotexist');
1077 var redirects = doc.body.querySelectorAll('.mw-redirect');
1078 redirects.length.should.equal(1);
1079 redirects[0].getAttribute('title').should.equal('Redirected');
1080 }))
1081 .end(done);
1082 });
1083
1084 it('should add redlinks for transform (pagebundle)', function(done) {
1085 if (skipForNow) {
1086 return this.skip();
1087 } // Fix redlinks count, by creating pages
1088 client.req
1089 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
1090 .send({
1091 wikitext: "[[Special:Version]] [[Doesnotexist]] [[Redirected]]",
1092 })
1093 .expect(validPageBundleResponse(function(doc) {
1094 doc.body.querySelectorAll('a').length.should.equal(3);
1095 var redLinks = doc.body.querySelectorAll('.new');
1096 redLinks.length.should.equal(1);
1097 redLinks[0].getAttribute('title').should.equal('Doesnotexist');
1098 var redirects = doc.body.querySelectorAll('.mw-redirect');
1099 redirects.length.should.equal(1);
1100 redirects[0].getAttribute('title').should.equal('Redirected');
1101 }))
1102 .end(done);
1103 });
1104
1105 (skipForNow ? describe.skip : describe)('Variant conversion', function() {
1106
1107 it('should not perform unnecessary variant conversion for get of en page (html)', function(done) {
1108 client.req
1109 .get(mockDomain + `/v3/page/html/${ page }/${ revid }`)
1110 .set('Accept-Language', 'sr-el')
1111 .expect(validHtmlResponse())
1112 .expect('Content-Language', 'en')
1113 .expect((res) => {
1114 const vary = res.headers.vary || '';
1115 vary.should.not.match(/\bAccept-Language\b/i);
1116 })
1117 .end(done);
1118 });
1119
1120 it('should not perform unnecessary variant conversion for get of en page (pagebundle)', function(done) {
1121 client.req
1122 .get(mockDomain + `/v3/page/pagebundle/${ page }/${ revid }`)
1123 .set('Accept-Language', 'sr-el')
1124 .expect(validPageBundleResponse())
1125 .expect((res) => {
1126 // HTTP headers should not be set.
1127 const vary1 = res.headers.vary || '';
1128 vary1.should.not.match(/\bAccept-Language\b/i);
1129 const lang1 = res.headers['content-language'] || '';
1130 lang1.should.equal('');
1131 // But equivalent headers should be present in the JSON body.
1132 const headers = res.body.html.headers;
1133 const vary2 = headers.vary || '';
1134 vary2.should.not.match(/\bAccept-Language\b/i);
1135 const lang2 = headers['content-language'];
1136 lang2.should.equal('en');
1137 })
1138 .end(done);
1139 });
1140
1141 it('should not perform unnecessary variant conversion for get on page w/ magic word (html)', function(done) {
1142 client.req
1143 .get(mockDomain + '/v3/page/html/No_Variant_Page/105')
1144 .set('Accept-Language', 'sr-el')
1145 .expect(validHtmlResponse((doc) => {
1146 // No conversion done since __NOCONTENTCONVERT__ is set
1147 doc.body.textContent.should.equal('абвг abcd\n');
1148 }))
1149 // But the vary/language headers are still set.
1150 .expect('Content-Language', 'sr-el')
1151 .expect('Vary', /\bAccept-Language\b/i)
1152 .end(done);
1153 });
1154
1155 it('should not perform unnecessary variant conversion for get on page w/ magic word (pagebundle)', function(done) {
1156 client.req
1157 .get(mockDomain + '/v3/page/pagebundle/No_Variant_Page/105')
1158 .set('Accept-Language', 'sr-el')
1159 .expect(validPageBundleResponse((doc) => {
1160 // No conversion done since __NOCONTENTCONVERT__ is set
1161 doc.body.textContent.should.equal('абвг abcd\n');
1162 }))
1163 .expect((res) => {
1164 // HTTP headers should not be set.
1165 const vary1 = res.headers.vary || '';
1166 vary1.should.not.match(/\bAccept-Language\b/i);
1167 const lang1 = res.headers['content-language'] || '';
1168 lang1.should.equal('');
1169 // But vary/language headers should be set in JSON body.
1170 const headers = res.body.html.headers;
1171 const vary2 = headers.vary || '';
1172 vary2.should.match(/\bAccept-Language\b/i);
1173 const lang2 = headers['content-language'];
1174 lang2.should.equal('sr-el');
1175 })
1176 .end(done);
1177 });
1178
1179 it('should not perform unrequested variant conversion for get w/ no accept-language header (html)', function(done) {
1180 client.req
1181 .get(mockDomain + '/v3/page/html/Variant_Page/104')
1182 // no accept-language header sent
1183 .expect('Content-Language', 'sr')
1184 .expect('Vary', /\bAccept-Language\b/i)
1185 .expect(validHtmlResponse((doc) => {
1186 doc.body.textContent.should.equal('абвг abcd');
1187 }))
1188 .end(done);
1189 });
1190
1191 it('should not perform unrequested variant conversion for get w/ no accept-language header (pagebundle)', function(done) {
1192 client.req
1193 .get(mockDomain + '/v3/page/pagebundle/Variant_Page/104')
1194 // no accept-language header sent
1195 .expect(validPageBundleResponse((doc) => {
1196 doc.body.textContent.should.equal('абвг abcd');
1197 }))
1198 .expect((res) => {
1199 // HTTP headers should not be set.
1200 const vary1 = res.headers.vary || '';
1201 vary1.should.not.match(/\bAccept-Language\b/i);
1202 const lang1 = res.headers['content-language'] || '';
1203 lang1.should.equal('');
1204 // But vary/language headers should be set in JSON body.
1205 const headers = res.body.html.headers;
1206 const vary2 = headers.vary || '';
1207 vary2.should.match(/\bAccept-Language\b/i);
1208 const lang2 = headers['content-language'];
1209 lang2.should.equal('sr');
1210 })
1211 .end(done);
1212 });
1213
1214 it('should not perform variant conversion for get w/ base variant specified (html)', function(done) {
1215 client.req
1216 .get(mockDomain + '/v3/page/html/Variant_Page/104')
1217 .set('Accept-Language', 'sr') // this is base variant
1218 .expect('Content-Language', 'sr')
1219 .expect('Vary', /\bAccept-Language\b/i)
1220 .expect(validHtmlResponse((doc) => {
1221 doc.body.textContent.should.equal('абвг abcd');
1222 }))
1223 .end(done);
1224 });
1225
1226 it('should not perform variant conversion for get w/ base variant specified (pagebundle)', function(done) {
1227 client.req
1228 .get(mockDomain + '/v3/page/pagebundle/Variant_Page/104')
1229 .set('Accept-Language', 'sr') // this is base variant
1230 .expect(validPageBundleResponse((doc) => {
1231 doc.body.textContent.should.equal('абвг abcd');
1232 }))
1233 .expect((res) => {
1234 // HTTP headers should not be set.
1235 const vary1 = res.headers.vary || '';
1236 vary1.should.not.match(/\bAccept-Language\b/i);
1237 const lang1 = res.headers['content-language'] || '';
1238 lang1.should.equal('');
1239 // But vary/language headers should be set in JSON body.
1240 const headers = res.body.html.headers;
1241 const vary2 = headers.vary || '';
1242 vary2.should.match(/\bAccept-Language\b/i);
1243 const lang2 = headers['content-language'];
1244 lang2.should.equal('sr');
1245 })
1246 .end(done);
1247 });
1248
1249 it('should not perform variant conversion for get w/ invalid variant specified (html)', function(done) {
1250 client.req
1251 .get(mockDomain + '/v3/page/html/Variant_Page/104')
1252 .set('Accept-Language', 'sr-BOGUS') // this doesn't exist
1253 .expect('Content-Language', 'sr')
1254 .expect('Vary', /\bAccept-Language\b/i)
1255 .expect(validHtmlResponse((doc) => {
1256 doc.body.textContent.should.equal('абвг abcd');
1257 }))
1258 .end(done);
1259 });
1260
1261 it('should not perform variant conversion for get w/ invalid variant specified (pagebundle)', function(done) {
1262 client.req
1263 .get(mockDomain + '/v3/page/pagebundle/Variant_Page/104')
1264 .set('Accept-Language', 'sr-BOGUS') // this doesn't exist
1265 .expect(validPageBundleResponse((doc) => {
1266 doc.body.textContent.should.equal('абвг abcd');
1267 }))
1268 .expect((res) => {
1269 // HTTP headers should not be set.
1270 const vary1 = res.headers.vary || '';
1271 vary1.should.not.match(/\bAccept-Language\b/i);
1272 const lang1 = res.headers['content-language'] || '';
1273 lang1.should.equal('');
1274 // But vary/language headers should be set in JSON body.
1275 const headers = res.body.html.headers;
1276 const vary2 = headers.vary || '';
1277 vary2.should.match(/\bAccept-Language\b/i);
1278 const lang2 = headers['content-language'];
1279 lang2.should.equal('sr');
1280 })
1281 .end(done);
1282 });
1283
1284 it('should perform variant conversion for get (html)', function(done) {
1285 client.req
1286 .get(mockDomain + '/v3/page/html/Variant_Page/104')
1287 .set('Accept-Language', 'sr-el')
1288 .expect('Content-Language', 'sr-el')
1289 .expect('Vary', /\bAccept-Language\b/i)
1290 .expect(validHtmlResponse((doc) => {
1291 doc.body.textContent.should.equal('abvg abcd');
1292 }))
1293 .end(done);
1294 });
1295
1296 it('should perform variant conversion for get (pagebundle)', function(done) {
1297 client.req
1298 .get(mockDomain + '/v3/page/pagebundle/Variant_Page/104')
1299 .set('Accept-Language', 'sr-el')
1300 .expect(validPageBundleResponse((doc) => {
1301 doc.body.textContent.should.equal('abvg abcd');
1302 }))
1303 .expect((res) => {
1304 const headers = res.body.html.headers;
1305 headers.should.have.property('content-language');
1306 headers.should.have.property('vary');
1307 headers['content-language'].should.equal('sr-el');
1308 headers.vary.should.match(/\bAccept-Language\b/i);
1309 })
1310 .end(done);
1311 });
1312
1313 it('should perform variant conversion for transform given pagelanguage in HTTP header (html)', function(done) {
1314 client.req
1315 .post(mockDomain + '/v3/transform/wikitext/to/html/')
1316 .set('Accept-Language', 'sr-el')
1317 .set('Content-Language', 'sr')
1318 .send({
1319 wikitext: "абвг abcd x",
1320 })
1321 .expect('Content-Language', 'sr-el')
1322 .expect('Vary', /\bAccept-Language\b/i)
1323 .expect(validHtmlResponse((doc) => {
1324 doc.body.textContent.should.equal('abvg abcd x');
1325 }))
1326 .end(done);
1327 });
1328
1329 it('should perform variant conversion for transform given pagelanguage in HTTP header (pagebundle)', function(done) {
1330 client.req
1331 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
1332 .set('Accept-Language', 'sr-el')
1333 .set('Content-Language', 'sr')
1334 .send({
1335 wikitext: "абвг abcd x",
1336 })
1337 .expect(validPageBundleResponse((doc) => {
1338 doc.body.textContent.should.equal('abvg abcd x');
1339 }))
1340 .expect((res) => {
1341 const headers = res.body.html.headers;
1342 headers.should.have.property('content-language');
1343 headers.should.have.property('vary');
1344 headers['content-language'].should.equal('sr-el');
1345 headers.vary.should.match(/\bAccept-Language\b/i);
1346 })
1347 .end(done);
1348 });
1349
1350 it('should perform variant conversion for transform given pagelanguage in JSON header (html)', function(done) {
1351 client.req
1352 .post(mockDomain + '/v3/transform/wikitext/to/html/')
1353 .set('Accept-Language', 'sr-el')
1354 .send({
1355 wikitext: {
1356 headers: {
1357 'content-language': 'sr',
1358 },
1359 body: "абвг abcd x",
1360 },
1361 })
1362 .expect('Content-Language', 'sr-el')
1363 .expect('Vary', /\bAccept-Language\b/i)
1364 .expect(validHtmlResponse((doc) => {
1365 doc.body.textContent.should.equal('abvg abcd x');
1366 }))
1367 .end(done);
1368 });
1369
1370 it('should perform variant conversion for transform given pagelanguage in JSON header (pagebundle)', function(done) {
1371 client.req
1372 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
1373 .set('Accept-Language', 'sr-el')
1374 .send({
1375 wikitext: {
1376 headers: {
1377 'content-language': 'sr',
1378 },
1379 body: "абвг abcd",
1380 },
1381 })
1382 .expect(validPageBundleResponse((doc) => {
1383 doc.body.textContent.should.equal('abvg abcd');
1384 }))
1385 .expect((res) => {
1386 const headers = res.body.html.headers;
1387 headers.should.have.property('content-language');
1388 headers.should.have.property('vary');
1389 headers['content-language'].should.equal('sr-el');
1390 headers.vary.should.match(/\bAccept-Language\b/i);
1391 })
1392 .end(done);
1393 });
1394
1395 it('should perform variant conversion for transform given pagelanguage from oldid (html)', function(done) {
1396 client.req
1397 .post(mockDomain + '/v3/transform/wikitext/to/html/')
1398 .set('Accept-Language', 'sr-el')
1399 .send({
1400 original: { revid: 104 },
1401 wikitext: {
1402 body: "абвг abcd x",
1403 },
1404 })
1405 .expect('Content-Language', 'sr-el')
1406 .expect('Vary', /\bAccept-Language\b/i)
1407 .expect(validHtmlResponse((doc) => {
1408 doc.body.textContent.should.equal('abvg abcd x');
1409 }))
1410 .end(done);
1411 });
1412
1413 it('should perform variant conversion for transform given pagelanguage from oldid (pagebundle)', function(done) {
1414 client.req
1415 .post(mockDomain + '/v3/transform/wikitext/to/pagebundle/')
1416 .set('Accept-Language', 'sr-el')
1417 .send({
1418 original: { revid: 104 },
1419 wikitext: "абвг abcd",
1420 })
1421 .expect(validPageBundleResponse((doc) => {
1422 doc.body.textContent.should.equal('abvg abcd');
1423 }))
1424 .expect((res) => {
1425 const headers = res.body.html.headers;
1426 headers.should.have.property('content-language');
1427 headers.should.have.property('vary');
1428 headers['content-language'].should.equal('sr-el');
1429 headers.vary.should.match(/\bAccept-Language\b/i);
1430 })
1431 .end(done);
1432 });
1433
1434 });
1435
1436 }); // end wt2html
1437
1438 describe("html2wt", function() {
1439
1440 it('should require html when serializing', function(done) {
1441 client.req
1442 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1443 .send({})
1444 .expect(400)
1445 .end(done);
1446 });
1447
1448 it('should error when revision not found (transform, html2wt)', function(done) {
1449 client.req
1450 .post(mockDomain + '/v3/transform/html/to/wikitext/Doesnotexist/1122334455')
1451 .send({
1452 html: '<pre>hi ho</pre>'
1453 })
1454 .expect(404)
1455 .end(done);
1456 });
1457
1458 it('should error when if-match doesn\'t match', function(done) {
1459 client.req
1460 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1461 .set( 'if-match', '"1219844647/deadbeef"' )
1462 .send({
1463 html: '<pre>hi ho</pre>'
1464 })
1465 .expect(412)
1466 .end(done);
1467 });
1468
1469 it('should not error when oldid not supplied (transform, html2wt)', function(done) {
1470 client.req
1471 .post(mockDomain + '/v3/transform/html/to/wikitext/Doesnotexist')
1472 .send({
1473 html: '<pre>hi ho</pre>'
1474 })
1475 .expect(validWikitextResponse(' hi ho\n'))
1476 .end(done);
1477 });
1478
1479 it('should accept html as a string', function(done) {
1480 client.req
1481 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1482 .send({
1483 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1484 })
1485 .expect(validWikitextResponse())
1486 .end(done);
1487 });
1488
1489 it('should accept html for json contentmodel as a string', function(done) {
1490 client.req
1491 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1492 .send({
1493 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/"><head prefix="mwr: http://en.wikipedia.org/wiki/Special:Redirect/"><meta charset="utf-8"/><meta property="mw:articleNamespace" content="0"/><link rel="dc:isVersionOf" href="//en.wikipedia.org/wiki/Main_Page"/><title></title><base href="//en.wikipedia.org/wiki/"/><link rel="stylesheet" href="//en.wikipedia.org/w/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid|ext.cite.style&amp;only=styles&amp;skin=vector"/></head><body lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><table class="mw-json mw-json-object"><tbody><tr><th>a</th><td class="value mw-json-number">4</td></tr><tr><th>b</th><td class="value mw-json-number">3</td></tr></tbody></table></body></html>',
1494 contentmodel: 'json',
1495 })
1496 .expect(validJsonResponse('{"a":4,"b":3}'))
1497 .end(done);
1498 });
1499
1500 it('should accept html with headers', function(done) {
1501 client.req
1502 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1503 .send({
1504 html: {
1505 headers: {
1506 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1507 },
1508 body: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1509 },
1510 })
1511 .expect(validWikitextResponse())
1512 .end(done);
1513 });
1514
1515 it('should allow a title in the url', function(done) {
1516 client.req
1517 .post(mockDomain + '/v3/transform/html/to/wikitext/Main_Page')
1518 .send({
1519 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1520 })
1521 .expect(validWikitextResponse())
1522 .end(done);
1523 });
1524
1525 it('should allow a title in the original data', function(done) {
1526 client.req
1527 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1528 .send({
1529 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1530 original: {
1531 title: "Main_Page",
1532 },
1533 })
1534 .expect(validWikitextResponse())
1535 .end(done);
1536 });
1537
1538 it('should allow a revision id in the url', function(done) {
1539 client.req
1540 .post(mockDomain + `/v3/transform/html/to/wikitext/${ page }/${ revid }`)
1541 .send({
1542 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1543 })
1544 .expect(validWikitextResponse())
1545 .end(done);
1546 });
1547
1548 it('should allow a revision id in the original data', function(done) {
1549 client.req
1550 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1551 .send({
1552 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1553 original: {
1554 revid,
1555 },
1556 })
1557 .expect(validWikitextResponse())
1558 .end(done);
1559 });
1560
1561 it('should accept original wikitext as src', function(done) {
1562 client.req
1563 .post(mockDomain + '/v3/transform/html/to/wikitext/')
1564 .send({
1565 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1566 original: {
1567 wikitext: {
1568 headers: {
1569 'content-type': 'text/plain;profile="https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0"',
1570 },
1571 body: '<strong>MediaWiki has been successfully installed.</strong>\n\nConsult the [//meta.wikimedia.org/wiki/Help:Contents User\'s Guide] for information on using the wiki software.\n\n== Getting started ==\n* [//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]\n* [//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]\n* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]\n* [//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]\n',
1572 },
1573 },
1574 })
1575 .expect(validWikitextResponse())
1576 .end(done);
1577 });
1578
1579 it('should accept original html for selser (default)', function(done) {
1580 client.req
1581 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1582 .send({
1583 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1584 original: {
1585 html: {
1586 headers: {
1587 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1588 },
1589 body: "<!DOCTYPE html>\n<html prefix=\"dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/\" about=\"http://localhost/index.php/Special:Redirect/revision/1\"><head prefix=\"mwr: http://localhost/index.php/Special:Redirect/\"><meta property=\"mw:articleNamespace\" content=\"0\"/><link rel=\"dc:replaces\" resource=\"mwr:revision/0\"/><meta property=\"dc:modified\" content=\"2014-09-12T22:46:59.000Z\"/><meta about=\"mwr:user/0\" property=\"dc:title\" content=\"MediaWiki default\"/><link rel=\"dc:contributor\" resource=\"mwr:user/0\"/><meta property=\"mw:revisionSHA1\" content=\"8e0aa2f2a7829587801db67d0424d9b447e09867\"/><meta property=\"dc:description\" content=\"\"/><link rel=\"dc:isVersionOf\" href=\"http://localhost/index.php/Main_Page\"/><title>Main_Page</title><base href=\"http://localhost/index.php/\"/><link rel=\"stylesheet\" href=\"//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector\"/></head><body id=\"mwAA\" lang=\"en\" class=\"mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki\" dir=\"ltr\"><p id=\"mwAQ\"><strong id=\"mwAg\">MediaWiki has been successfully installed.</strong></p>\n\n<p id=\"mwAw\">Consult the <a rel=\"mw:ExtLink\" href=\"//meta.wikimedia.org/wiki/Help:Contents\" id=\"mwBA\">User's Guide</a> for information on using the wiki software.</p>\n\n<h2 id=\"mwBQ\"> Getting started </h2>\n<ul id=\"mwBg\"><li id=\"mwBw\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings\" id=\"mwCA\">Configuration settings list</a></li>\n<li id=\"mwCQ\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ\" id=\"mwCg\">MediaWiki FAQ</a></li>\n<li id=\"mwCw\"> <a rel=\"mw:ExtLink\" href=\"https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce\" id=\"mwDA\">MediaWiki release mailing list</a></li>\n<li id=\"mwDQ\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources\" id=\"mwDg\">Localise MediaWiki for your language</a></li></ul></body></html>",
1590 },
1591 "data-parsoid": {
1592 headers: {
1593 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/' + defaultContentVersion + '"',
1594 },
1595 body: {
1596 "counter": 14,
1597 "ids": {
1598 "mwAA": { "dsr": [0, 592, 0, 0] }, "mwAQ": { "dsr": [0, 59, 0, 0] }, "mwAg": { "stx": "html", "dsr": [0, 59, 8, 9] }, "mwAw": { "dsr": [61, 171, 0, 0] }, "mwBA": { "dsr": [73, 127, 41, 1] }, "mwBQ": { "dsr": [173, 194, 2, 2] }, "mwBg": { "dsr": [195, 592, 0, 0] }, "mwBw": { "dsr": [195, 300, 1, 0] }, "mwCA": { "dsr": [197, 300, 75, 1] }, "mwCQ": { "dsr": [301, 373, 1, 0] }, "mwCg": { "dsr": [303, 373, 56, 1] }, "mwCw": { "dsr": [374, 472, 1, 0] }, "mwDA": { "dsr": [376, 472, 65, 1] }, "mwDQ": { "dsr": [473, 592, 1, 0] }, "mwDg": { "dsr": [475, 592, 80, 1] },
1599 },
1600 },
1601 },
1602 },
1603 })
1604 .expect(validWikitextResponse())
1605 .end(done);
1606 });
1607
1608 it('should accept original html for selser (1.1.1, meta)', function(done) {
1609 client.req
1610 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1611 .send({
1612 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><meta property="mw:html:version" content="1.1.1"/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1613 original: {
1614 html: {
1615 headers: {
1616 'content-type': 'text/html; profile="mediawiki.org/specs/html/1.1.1"',
1617 },
1618 body: "<!DOCTYPE html>\n<html prefix=\"dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/\" about=\"http://localhost/index.php/Special:Redirect/revision/1\"><head prefix=\"mwr: http://localhost/index.php/Special:Redirect/\"><meta property=\"mw:articleNamespace\" content=\"0\"/><link rel=\"dc:replaces\" resource=\"mwr:revision/0\"/><meta property=\"dc:modified\" content=\"2014-09-12T22:46:59.000Z\"/><meta about=\"mwr:user/0\" property=\"dc:title\" content=\"MediaWiki default\"/><link rel=\"dc:contributor\" resource=\"mwr:user/0\"/><meta property=\"mw:revisionSHA1\" content=\"8e0aa2f2a7829587801db67d0424d9b447e09867\"/><meta property=\"dc:description\" content=\"\"/><link rel=\"dc:isVersionOf\" href=\"http://localhost/index.php/Main_Page\"/><title>Main_Page</title><base href=\"http://localhost/index.php/\"/><link rel=\"stylesheet\" href=\"//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector\"/></head><body id=\"mwAA\" lang=\"en\" class=\"mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki\" dir=\"ltr\"><p id=\"mwAQ\"><strong id=\"mwAg\">MediaWiki has been successfully installed.</strong></p>\n\n<p id=\"mwAw\">Consult the <a rel=\"mw:ExtLink\" href=\"//meta.wikimedia.org/wiki/Help:Contents\" id=\"mwBA\">User's Guide</a> for information on using the wiki software.</p>\n\n<h2 id=\"mwBQ\"> Getting started </h2>\n<ul id=\"mwBg\"><li id=\"mwBw\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings\" id=\"mwCA\">Configuration settings list</a></li>\n<li id=\"mwCQ\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ\" id=\"mwCg\">MediaWiki FAQ</a></li>\n<li id=\"mwCw\"> <a rel=\"mw:ExtLink\" href=\"https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce\" id=\"mwDA\">MediaWiki release mailing list</a></li>\n<li id=\"mwDQ\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources\" id=\"mwDg\">Localise MediaWiki for your language</a></li></ul></body></html>",
1619 },
1620 "data-parsoid": {
1621 headers: {
1622 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/0.0.1"',
1623 },
1624 body: {
1625 "counter": 14,
1626 "ids": {
1627 "mwAA": { "dsr": [0, 592, 0, 0] }, "mwAQ": { "dsr": [0, 59, 0, 0] }, "mwAg": { "stx": "html", "dsr": [0, 59, 8, 9] }, "mwAw": { "dsr": [61, 171, 0, 0] }, "mwBA": { "dsr": [73, 127, 41, 1] }, "mwBQ": { "dsr": [173, 194, 2, 2] }, "mwBg": { "dsr": [195, 592, 0, 0] }, "mwBw": { "dsr": [195, 300, 1, 0] }, "mwCA": { "dsr": [197, 300, 75, 1] }, "mwCQ": { "dsr": [301, 373, 1, 0] }, "mwCg": { "dsr": [303, 373, 56, 1] }, "mwCw": { "dsr": [374, 472, 1, 0] }, "mwDA": { "dsr": [376, 472, 65, 1] }, "mwDQ": { "dsr": [473, 592, 1, 0] }, "mwDg": { "dsr": [475, 592, 80, 1] },
1628 },
1629 },
1630 },
1631 },
1632 })
1633 .expect(validWikitextResponse())
1634 .end(done);
1635 });
1636
1637 it('should accept original html for selser (1.1.1, headers)', function(done) {
1638 client.req
1639 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1640 .send({
1641 // Don't set the mw:html:version so that we get it from the original/headers
1642 html: '<!DOCTYPE html>\n<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/index.php/Special:Redirect/revision/1"><head prefix="mwr: http://localhost/index.php/Special:Redirect/"><meta property="mw:articleNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="dc:modified" content="2014-09-12T22:46:59.000Z"/><meta about="mwr:user/0" property="dc:title" content="MediaWiki default"/><link rel="dc:contributor" resource="mwr:user/0"/><meta property="mw:revisionSHA1" content="8e0aa2f2a7829587801db67d0424d9b447e09867"/><meta property="dc:description" content=""/><link rel="dc:isVersionOf" href="http://localhost/index.php/Main_Page"/><title>Main_Page</title><base href="http://localhost/index.php/"/><link rel="stylesheet" href="//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector"/></head><body data-parsoid=\'{"dsr":[0,592,0,0]}\' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki" dir="ltr"><p data-parsoid=\'{"dsr":[0,59,0,0]}\'><strong data-parsoid=\'{"stx":"html","dsr":[0,59,8,9]}\'>MediaWiki has been successfully installed.</strong></p>\n\n<p data-parsoid=\'{"dsr":[61,171,0,0]}\'>Consult the <a rel="mw:ExtLink" href="//meta.wikimedia.org/wiki/Help:Contents" data-parsoid=\'{"dsr":[73,127,41,1]}\'>User\'s Guide</a> for information on using the wiki software.</p>\n\n<h2 data-parsoid=\'{"dsr":[173,194,2,2]}\'> Getting started </h2>\n<ul data-parsoid=\'{"dsr":[195,592,0,0]}\'><li data-parsoid=\'{"dsr":[195,300,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings" data-parsoid=\'{"dsr":[197,300,75,1]}\'>Configuration settings list</a></li>\n<li data-parsoid=\'{"dsr":[301,373,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ" data-parsoid=\'{"dsr":[303,373,56,1]}\'>MediaWiki FAQ</a></li>\n<li data-parsoid=\'{"dsr":[374,472,1,0]}\'> <a rel="mw:ExtLink" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce" data-parsoid=\'{"dsr":[376,472,65,1]}\'>MediaWiki release mailing list</a></li>\n<li data-parsoid=\'{"dsr":[473,592,1,0]}\'> <a rel="mw:ExtLink" href="//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources" data-parsoid=\'{"dsr":[475,592,80,1]}\'>Localise MediaWiki for your language</a></li></ul></body></html>',
1643 original: {
1644 html: {
1645 headers: {
1646 'content-type': 'text/html; profile="mediawiki.org/specs/html/1.1.1"',
1647 },
1648 body: "<!DOCTYPE html>\n<html prefix=\"dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/\" about=\"http://localhost/index.php/Special:Redirect/revision/1\"><head prefix=\"mwr: http://localhost/index.php/Special:Redirect/\"><meta property=\"mw:articleNamespace\" content=\"0\"/><link rel=\"dc:replaces\" resource=\"mwr:revision/0\"/><meta property=\"dc:modified\" content=\"2014-09-12T22:46:59.000Z\"/><meta about=\"mwr:user/0\" property=\"dc:title\" content=\"MediaWiki default\"/><link rel=\"dc:contributor\" resource=\"mwr:user/0\"/><meta property=\"mw:revisionSHA1\" content=\"8e0aa2f2a7829587801db67d0424d9b447e09867\"/><meta property=\"dc:description\" content=\"\"/><link rel=\"dc:isVersionOf\" href=\"http://localhost/index.php/Main_Page\"/><title>Main_Page</title><base href=\"http://localhost/index.php/\"/><link rel=\"stylesheet\" href=\"//localhost/load.php?modules=mediawiki.legacy.commonPrint,shared|mediawiki.skinning.elements|mediawiki.skinning.content|mediawiki.skinning.interface|skins.vector.styles|site|mediawiki.skinning.content.parsoid&amp;only=styles&amp;debug=true&amp;skin=vector\"/></head><body id=\"mwAA\" lang=\"en\" class=\"mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki\" dir=\"ltr\"><p id=\"mwAQ\"><strong id=\"mwAg\">MediaWiki has been successfully installed.</strong></p>\n\n<p id=\"mwAw\">Consult the <a rel=\"mw:ExtLink\" href=\"//meta.wikimedia.org/wiki/Help:Contents\" id=\"mwBA\">User's Guide</a> for information on using the wiki software.</p>\n\n<h2 id=\"mwBQ\"> Getting started </h2>\n<ul id=\"mwBg\"><li id=\"mwBw\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings\" id=\"mwCA\">Configuration settings list</a></li>\n<li id=\"mwCQ\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ\" id=\"mwCg\">MediaWiki FAQ</a></li>\n<li id=\"mwCw\"> <a rel=\"mw:ExtLink\" href=\"https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce\" id=\"mwDA\">MediaWiki release mailing list</a></li>\n<li id=\"mwDQ\"> <a rel=\"mw:ExtLink\" href=\"//www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources\" id=\"mwDg\">Localise MediaWiki for your language</a></li></ul></body></html>",
1649 },
1650 "data-parsoid": {
1651 headers: {
1652 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/0.0.1"',
1653 },
1654 body: {
1655 "counter": 14,
1656 "ids": {
1657 "mwAA": { "dsr": [0, 592, 0, 0] }, "mwAQ": { "dsr": [0, 59, 0, 0] }, "mwAg": { "stx": "html", "dsr": [0, 59, 8, 9] }, "mwAw": { "dsr": [61, 171, 0, 0] }, "mwBA": { "dsr": [73, 127, 41, 1] }, "mwBQ": { "dsr": [173, 194, 2, 2] }, "mwBg": { "dsr": [195, 592, 0, 0] }, "mwBw": { "dsr": [195, 300, 1, 0] }, "mwCA": { "dsr": [197, 300, 75, 1] }, "mwCQ": { "dsr": [301, 373, 1, 0] }, "mwCg": { "dsr": [303, 373, 56, 1] }, "mwCw": { "dsr": [374, 472, 1, 0] }, "mwDA": { "dsr": [376, 472, 65, 1] }, "mwDQ": { "dsr": [473, 592, 1, 0] }, "mwDg": { "dsr": [475, 592, 80, 1] },
1658 },
1659 },
1660 },
1661 },
1662 })
1663 .expect(validWikitextResponse())
1664 .end(done);
1665 });
1666
1667 it('should return http 400 if supplied data-parsoid is empty', function(done) {
1668 client.req
1669 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1670 .send({
1671 html: '<html><head></head><body><p>hi</p></body></html>',
1672 original: {
1673 html: {
1674 headers: {
1675 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1676 },
1677 body: '<html><head></head><body><p>ho</p></body></html>',
1678 },
1679 'data-parsoid': {
1680 headers: {
1681 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/' + defaultContentVersion + '"',
1682 },
1683 body: {},
1684 },
1685 },
1686 })
1687 .expect(400)
1688 .end(done);
1689 });
1690
1691 // FIXME: Pagebundle validation in general is needed
1692 it.skip('should return http 400 if supplied data-parsoid is a string', function(done) {
1693 client.req
1694 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1695 .send({
1696 html: '<html><head></head><body><p>hi</p></body></html>',
1697 original: {
1698 html: {
1699 headers: {
1700 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1701 },
1702 body: '<html><head></head><body><p>ho</p></body></html>',
1703 },
1704 'data-parsoid': {
1705 headers: {
1706 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/' + defaultContentVersion + '"',
1707 },
1708 body: 'Garbled text from RESTBase.',
1709 },
1710 },
1711 })
1712 .expect(400)
1713 .end(done);
1714 });
1715
1716 // The following three tests should all serialize as:
1717 // "<div>Selser test"
1718 // However, we're deliberately setting the original wikitext in
1719 // the first two to garbage so that when selser doesn't detect any
1720 // difference between the new and old html, it'll just reuse that
1721 // string and we have a reliable way of determining that selser
1722 // was used.
1723
1724 it('should use selser with supplied wikitext', function(done) {
1725 if (skipForNow) {
1726 return this.skip();
1727 } // Create Junk Page
1728 // New and old html are identical, which should produce no diffs
1729 // and reuse the original wikitext.
1730 client.req
1731 // Need to provide an oldid so that selser mode is enabled
1732 // Without an oldid, serialization falls back to non-selser wts.
1733 // The oldid is used to fetch wikitext, but if wikitext is provided
1734 // (as in this test), it is not used. So, for testing purposes,
1735 // we can use any old random id, as long as something is present.
1736 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1737 .send({
1738 html: "<html><body id=\"mwAA\"><div id=\"mwBB\">Selser test</div></body></html>",
1739 original: {
1740 title: "Junk Page",
1741 revid: 1234,
1742 wikitext: {
1743 body: "1. This is just some junk. See the comment above.",
1744 },
1745 html: {
1746 body: "<html><body id=\"mwAA\"><div id=\"mwBB\">Selser test</div></body></html>",
1747 headers: {
1748 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1749 },
1750 },
1751 "data-parsoid": {
1752 body: {
1753 "ids": {
1754 mwAA: {},
1755 mwBB: { "autoInsertedEnd": true, "stx": "html" },
1756 },
1757 },
1758 },
1759 },
1760 })
1761 .expect(validWikitextResponse(
1762 "1. This is just some junk. See the comment above."
1763 ))
1764 .end(done);
1765 });
1766
1767 it('should use selser with wikitext fetched from the mw api', function(done) {
1768 if (skipForNow) {
1769 return this.skip();
1770 } // Creat Junk Page
1771 // New and old html are identical, which should produce no diffs
1772 // and reuse the original wikitext.
1773 client.req
1774 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1775 .send({
1776 html: "<html><body id=\"mwAA\"><div id=\"mwBB\">Selser test</div></body></html>",
1777 original: {
1778 revid: 2,
1779 title: "Junk Page",
1780 html: {
1781 body: "<html><body id=\"mwAA\"><div id=\"mwBB\">Selser test</div></body></html>",
1782 headers: {
1783 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1784 },
1785 },
1786 "data-parsoid": {
1787 body: {
1788 "ids": {
1789 mwAA: {},
1790 mwBB: { "autoInsertedEnd": true, "stx": "html" },
1791 },
1792 },
1793 },
1794 },
1795 })
1796 .expect(validWikitextResponse(
1797 "2. This is just some junk. See the comment above."
1798 ))
1799 .end(done);
1800 });
1801
1802 it('should fallback to non-selective serialization', function(done) {
1803 // Without the original wikitext and an unavailable
1804 // TemplateFetch for the source (no revision id provided),
1805 // it should fallback to non-selective serialization.
1806 client.req
1807 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1808 .send({
1809 html: "<html><body id=\"mwAA\"><div id=\"mwBB\">Selser test</div></body></html>",
1810 original: {
1811 title: "Junk Page",
1812 html: {
1813 body: "<html><body id=\"mwAA\"><div id=\"mwBB\">Selser test</div></body></html>",
1814 headers: {
1815 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1816 },
1817 },
1818 "data-parsoid": {
1819 body: {
1820 "ids": {
1821 mwAA: {},
1822 mwBB: { "autoInsertedEnd": true, "stx": "html" },
1823 },
1824 },
1825 },
1826 },
1827 })
1828 .expect(validWikitextResponse(
1829 "<div>Selser test"
1830 ))
1831 .end(done);
1832 });
1833
1834 it('should apply data-parsoid to duplicated ids', function(done) {
1835 client.req
1836 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1837 .send({
1838 html: "<html><body id=\"mwAA\"><div id=\"mwBB\">data-parsoid test</div><div id=\"mwBB\">data-parsoid test</div></body></html>",
1839 original: {
1840 title: "Doesnotexist",
1841 html: {
1842 body: "<html><body id=\"mwAA\"><div id=\"mwBB\">data-parsoid test</div></body></html>",
1843 headers: {
1844 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
1845 },
1846 },
1847 "data-parsoid": {
1848 body: {
1849 "ids": {
1850 mwAA: {},
1851 mwBB: { "autoInsertedEnd": true, "stx": "html" },
1852 },
1853 },
1854 },
1855 },
1856 })
1857 .expect(validWikitextResponse(
1858 "<div>data-parsoid test<div>data-parsoid test"
1859 ))
1860 .end(done);
1861 });
1862
1863 it('should return a 400 for missing inline data-mw (2.x)', function(done) {
1864 client.req
1865 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1866 .send({
1867 html: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">hi</p>',
1868 original: {
1869 title: 'Doesnotexist',
1870 'data-parsoid': {
1871 body: {
1872 ids: { "mwAQ": { "pi": [[{ "k": "1" }]] } },
1873 },
1874 },
1875 html: {
1876 headers: {
1877 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/2.8.0"',
1878 },
1879 body: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>',
1880 },
1881 },
1882 })
1883 .expect(400)
1884 .end(done);
1885 });
1886
1887 it('should return a 400 for not supplying data-mw', function(done) {
1888 client.req
1889 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1890 .send({
1891 html: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">hi</p>',
1892 original: {
1893 title: 'Doesnotexist',
1894 'data-parsoid': {
1895 body: {
1896 ids: { "mwAQ": { "pi": [[{ "k": "1" }]] } },
1897 },
1898 },
1899 html: {
1900 headers: {
1901 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
1902 },
1903 body: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>',
1904 },
1905 },
1906 })
1907 .expect(400)
1908 .end(done);
1909 });
1910
1911 it('should apply original data-mw', function(done) {
1912 client.req
1913 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1914 .send({
1915 html: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">hi</p>',
1916 original: {
1917 title: 'Doesnotexist',
1918 'data-parsoid': {
1919 body: {
1920 ids: { "mwAQ": { "pi": [[{ "k": "1" }]] } },
1921 },
1922 },
1923 'data-mw': {
1924 body: {
1925 ids: { "mwAQ": { "parts": [{ "template": { "target": { "wt": "1x", "href": "./Template:1x" }, "params": { "1": { "wt": "hi" } }, "i": 0 } }] } },
1926 },
1927 },
1928 html: {
1929 headers: {
1930 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
1931 },
1932 body: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>',
1933 },
1934 },
1935 })
1936 .expect(validWikitextResponse('{{1x|hi}}'))
1937 .end(done);
1938 });
1939
1940 // Sanity check data-mw was applied in the previous test
1941 it('should return a 400 for missing modified data-mw', function(done) {
1942 client.req
1943 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1944 .send({
1945 html: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">hi</p>',
1946 original: {
1947 title: 'Doesnotexist',
1948 'data-parsoid': {
1949 body: {
1950 ids: { "mwAQ": { "pi": [[{ "k": "1" }]] } },
1951 },
1952 },
1953 'data-mw': {
1954 body: {
1955 ids: { "mwAQ": { } }, // Missing data-mw.parts!
1956 },
1957 },
1958 html: {
1959 headers: {
1960 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
1961 },
1962 body: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>',
1963 },
1964 },
1965 })
1966 .expect(400)
1967 .end(done);
1968 });
1969
1970 it('should give precedence to inline data-mw over original', function(done) {
1971 client.req
1972 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
1973 .send({
1974 html: '<p about="#mwt1" typeof="mw:Transclusion" data-mw=\'{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi"}},"i":0}}]}\' id="mwAQ">hi</p>',
1975 original: {
1976 title: 'Doesnotexist',
1977 'data-parsoid': {
1978 body: {
1979 ids: { "mwAQ": { "pi": [[{ "k": "1" }]] } },
1980 },
1981 },
1982 'data-mw': {
1983 body: {
1984 ids: { "mwAQ": { } }, // Missing data-mw.parts!
1985 },
1986 },
1987 html: {
1988 headers: {
1989 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
1990 },
1991 body: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>',
1992 },
1993 },
1994 })
1995 .expect(validWikitextResponse('{{1x|hi}}'))
1996 .end(done);
1997 });
1998
1999 it('should not apply original data-mw if modified is supplied', function(done) {
2000 client.req
2001 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
2002 .send({
2003 html: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">hi</p>',
2004 'data-mw': {
2005 body: {
2006 ids: { "mwAQ": { "parts": [{ "template": { "target": { "wt": "1x", "href": "./Template:1x" }, "params": { "1": { "wt": "hi" } }, "i": 0 } }] } },
2007 },
2008 },
2009 original: {
2010 title: 'Doesnotexist',
2011 'data-parsoid': {
2012 body: {
2013 ids: { "mwAQ": { "pi": [[{ "k": "1" }]] } },
2014 },
2015 },
2016 'data-mw': {
2017 body: {
2018 ids: { "mwAQ": { } }, // Missing data-mw.parts!
2019 },
2020 },
2021 html: {
2022 headers: {
2023 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
2024 },
2025 body: '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>',
2026 },
2027 },
2028 })
2029 .expect(validWikitextResponse('{{1x|hi}}'))
2030 .end(done);
2031 });
2032
2033 // The next three tests, although redundant with the above precedence
2034 // tests, are an attempt to show clients the semantics of separate
2035 // data-mw in the API. The main idea is,
2036 //
2037 // non-inline-data-mw = modified || original
2038 // inline-data-mw > non-inline-data-mw
2039
2040 it('should apply original data-mw when modified is absent (captions 1)', function(done) {
2041 client.req
2042 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
2043 .send({
2044 html: '<p><span class="mw-default-size" typeof="mw:File" id="mwAg"><a href="./File:Foobar.jpg" id="mwAw"><img resource="./File:Foobar.jpg" src="//upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg" data-file-width="240" data-file-height="28" data-file-type="bitmap" height="28" width="240" id="mwBA"/></a></span></p>',
2045 original: {
2046 title: 'Doesnotexist',
2047 'data-parsoid': {
2048 body: {
2049 ids: {
2050 "mwAg": { "optList": [{ "ck": "caption", "ak": "Testing 123" }] },
2051 "mwAw": { "a": { "href": "./File:Foobar.jpg" }, "sa": {} },
2052 "mwBA": { "a": { "resource": "./File:Foobar.jpg", "height": "28", "width": "240" },"sa": { "resource": "File:Foobar.jpg" } },
2053 },
2054 },
2055 },
2056 'data-mw': {
2057 body: {
2058 ids: {
2059 "mwAg": { "caption": "Testing 123" },
2060 },
2061 },
2062 },
2063 html: {
2064 headers: {
2065 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
2066 },
2067 body: '<p><span class="mw-default-size" typeof="mw:File" id="mwAg"><a href="./File:Foobar.jpg" id="mwAw"><img resource="./File:Foobar.jpg" src="//upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg" data-file-width="240" data-file-height="28" data-file-type="bitmap" height="28" width="240" id="mwBA"/></a></span></p>',
2068 },
2069 },
2070 })
2071 .expect(validWikitextResponse('[[File:Foobar.jpg|Testing 123]]'))
2072 .end(done);
2073 });
2074
2075 it('should give precedence to inline data-mw over modified (captions 2)', function(done) {
2076 client.req
2077 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
2078 .send({
2079 html: '<p><span class="mw-default-size" typeof="mw:File" data-mw="{}" id="mwAg"><a href="./File:Foobar.jpg" id="mwAw"><img resource="./File:Foobar.jpg" src="//upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg" data-file-width="240" data-file-height="28" data-file-type="bitmap" height="28" width="240" id="mwBA"/></a></span></p>',
2080 'data-mw': {
2081 body: {
2082 ids: {
2083 "mwAg": { "caption": "Testing 123" },
2084 },
2085 },
2086 },
2087 original: {
2088 title: 'Doesnotexist',
2089 'data-parsoid': {
2090 body: {
2091 ids: {
2092 "mwAg": { "optList": [{ "ck": "caption", "ak": "Testing 123" }] },
2093 "mwAw": { "a": { "href": "./File:Foobar.jpg" }, "sa": {} },
2094 "mwBA": { "a": { "resource": "./File:Foobar.jpg", "height": "28", "width": "240" },"sa": { "resource": "File:Foobar.jpg" } },
2095 },
2096 },
2097 },
2098 'data-mw': {
2099 body: {
2100 ids: {
2101 "mwAg": { "caption": "Testing 123" },
2102 },
2103 },
2104 },
2105 html: {
2106 headers: {
2107 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
2108 },
2109 body: '<p><span class="mw-default-size" typeof="mw:File" id="mwAg"><a href="./File:Foobar.jpg" id="mwAw"><img resource="./File:Foobar.jpg" src="//upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg" data-file-width="240" data-file-height="28" data-file-type="bitmap" height="28" width="240" id="mwBA"/></a></span></p>',
2110 },
2111 },
2112 })
2113 .expect(validWikitextResponse('[[File:Foobar.jpg]]'))
2114 .end(done);
2115 });
2116
2117 it('should give precedence to modified data-mw over original (captions 3)', function(done) {
2118 client.req
2119 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
2120 .send({
2121 html: '<p><span class="mw-default-size" typeof="mw:File" id="mwAg"><a href="./File:Foobar.jpg" id="mwAw"><img resource="./File:Foobar.jpg" src="//upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg" data-file-width="240" data-file-height="28" data-file-type="bitmap" height="28" width="240" id="mwBA"/></a></span></p>',
2122 'data-mw': {
2123 body: {
2124 ids: {
2125 "mwAg": {},
2126 },
2127 },
2128 },
2129 original: {
2130 title: 'Doesnotexist',
2131 'data-parsoid': {
2132 body: {
2133 ids: {
2134 "mwAg": { "optList": [{ "ck": "caption", "ak": "Testing 123" }] },
2135 "mwAw": { "a": { "href": "./File:Foobar.jpg" }, "sa": {} },
2136 "mwBA": { "a": { "resource": "./File:Foobar.jpg", "height": "28", "width": "240" },"sa": { "resource": "File:Foobar.jpg" } },
2137 },
2138 },
2139 },
2140 'data-mw': {
2141 body: {
2142 ids: {
2143 "mwAg": { "caption": "Testing 123" },
2144 },
2145 },
2146 },
2147 html: {
2148 headers: {
2149 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
2150 },
2151 body: '<p><span class="mw-default-size" typeof="mw:File" id="mwAg"><a href="./File:Foobar.jpg" id="mwAw"><img resource="./File:Foobar.jpg" src="//upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg" data-file-width="240" data-file-height="28" data-file-type="bitmap" height="28" width="240" id="mwBA"/></a></span></p>',
2152 },
2153 },
2154 })
2155 .expect(validWikitextResponse('[[File:Foobar.jpg]]'))
2156 .end(done);
2157 });
2158
2159 it('should apply extra normalizations', function(done) {
2160 client.req
2161 .post(mockDomain + '/v3/transform/html/to/wikitext/')
2162 .send({
2163 html: '<h2></h2>',
2164 original: { title: 'Doesnotexist' },
2165 })
2166 .expect(validWikitextResponse(
2167 ''
2168 ))
2169 .end(done);
2170 });
2171
2172 it('should return a request too large error', function(done) {
2173 if (skipForNow) {
2174 return this.skip();
2175 } // Set limits in config
2176 client.req
2177 .post(mockDomain + '/v3/transform/html/to/wikitext/')
2178 .send({
2179 original: {
2180 title: 'Large_Page',
2181 },
2182 html: "a".repeat(parsoidOptions.limits.html2wt.maxHTMLSize + 1),
2183 })
2184 .expect(413)
2185 .end(done);
2186 });
2187
2188 it('should fail to downgrade the original version for an unknown transition', function(done) {
2189 client.req
2190 .post(mockDomain + '/v3/transform/pagebundle/to/wikitext/')
2191 .send({
2192 html: '<!DOCTYPE html>\n<html><head><meta charset="utf-8"/><meta property="mw:htmlVersion" content="2.8.0"/></head><body id="mwAA" lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr">123</body></html>',
2193 original: {
2194 title: 'Doesnotexist',
2195 'data-parsoid': { body: { "ids": {} } },
2196 html: {
2197 headers: {
2198 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/2222.0.0"',
2199 },
2200 body: '<!DOCTYPE html>\n<html><head><meta charset="utf-8"/><meta property="mw:html:version" content="2222.0.0"/></head><body id="mwAA" lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr">123</body></html>',
2201 },
2202 },
2203 })
2204 .expect(400)
2205 .end(done);
2206 });
2207
2208 }); // end html2wt
2209
2210 describe('pb2pb', function() {
2211
2212 it('should require an original or previous version', function(done) {
2213 client.req
2214 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/Reuse_Page/100')
2215 .send({})
2216 .expect(400)
2217 .end(done);
2218 });
2219
2220 var previousRevHTML = {
2221 revid: 99,
2222 html: {
2223 headers: {
2224 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
2225 },
2226 body: '<p about="#mwt1" typeof="mw:Transclusion" data-mw=\'{"parts":[{"template":{"target":{"wt":"colours of the rainbow","href":"./Template:Colours_of_the_rainbow"},"params":{},"i":0}}]}\' id="mwAg">pink</p>',
2227 },
2228 "data-parsoid": {
2229 headers: {
2230 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/' + defaultContentVersion + '"',
2231 },
2232 body: {
2233 'counter': 2,
2234 'ids': {
2235 'mwAg': { 'pi': [[]], 'src': '{{colours of the rainbow}}' }, // artificially added src
2236 },
2237 },
2238 },
2239 };
2240
2241 it('should error when revision not found (transform, pb2pb)', function(done) {
2242 client.req
2243 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/Doesnotexist')
2244 .send({
2245 previous: previousRevHTML,
2246 })
2247 .expect(404)
2248 .end(done);
2249 });
2250
2251 // FIXME: Expansion reuse wasn't ported, see T98995
2252 it.skip('should accept the previous revision to reuse expansions', function(done) {
2253 client.req
2254 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/Reuse_Page/100')
2255 .send({
2256 previous: previousRevHTML,
2257 })
2258 .expect(validPageBundleResponse(function(doc) {
2259 doc.body.firstChild.textContent.should.match(/pink/);
2260 }))
2261 .end(done);
2262 });
2263
2264 var origHTML = Util.clone(previousRevHTML);
2265 origHTML.revid = 100;
2266
2267 // FIXME: Expansion reuse wasn't ported, see T98995
2268 it.skip('should accept the original and reuse certain expansions', function(done) {
2269 client.req
2270 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/Reuse_Page/100')
2271 .send({
2272 updates: {
2273 transclusions: true,
2274 },
2275 original: origHTML,
2276 })
2277 .expect(validPageBundleResponse(function(doc) {
2278 doc.body.firstChild.textContent.should.match(/purple/);
2279 }))
2280 .end(done);
2281 });
2282
2283 it('should refuse an unknown conversion (2.x -> 999.x)', function(done) {
2284 previousRevHTML.html.headers['content-type'].should.equal('text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/2.8.0"');
2285 client.req
2286 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/Reuse_Page/100')
2287 .set('Accept', 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/999.0.0"')
2288 .send({
2289 previous: previousRevHTML,
2290 })
2291 .expect(415)
2292 .end(done);
2293 });
2294
2295 it('should downgrade 999.x content to 2.x', function(done) {
2296 var contentVersion = '2.8.0';
2297 client.req
2298 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/')
2299 .set('Accept', 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/' + contentVersion + '"')
2300 .send({
2301 original: {
2302 title: 'Doesnotexist',
2303 'data-parsoid': {
2304 body: {
2305 ids: { "mwAQ": { "pi": [[{ "k": "1" }]] } },
2306 },
2307 },
2308 'data-mw': {
2309 body: {
2310 ids: { "mwAQ": { "parts": [{ "template": { "target": { "wt": "1x", "href": "./Template:1x" }, "params": { "1": { "wt": "hi" } }, "i": 0 } }] } },
2311 },
2312 },
2313 html: {
2314 headers: {
2315 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"',
2316 },
2317 body: '<!DOCTYPE html>\n<html><head><meta charset="utf-8"/><meta property="mw:htmlVersion" content="999.0.0"/></head><body><p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p></body></html>',
2318 },
2319 },
2320 })
2321 .expect(status200)
2322 .expect(acceptablePageBundleResponse(contentVersion, function(html) {
2323 // In < 999.x, data-mw is still inline.
2324 html.should.match(/\s+data-mw\s*=\s*['"]/);
2325 html.should.not.match(/\s+data-parsoid\s*=\s*['"]/);
2326 var doc = domino.createDocument(html);
2327 var meta = doc.querySelector('meta[property="mw:html:version"], meta[property="mw:htmlVersion"]');
2328 meta.getAttribute('content').should.equal(contentVersion);
2329 }))
2330 .end(done);
2331 });
2332
2333 it('should accept the original and update the redlinks', function(done) {
2334 if (skipForNow) {
2335 return this.skip();
2336 } // Create pages to fix redlinks count
2337 // NOTE: Keep this on an older version to show that it's preserved
2338 // through the transformation.
2339 var contentVersion = '2.0.0';
2340 client.req
2341 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/')
2342 .send({
2343 updates: {
2344 redlinks: true,
2345 },
2346 original: {
2347 title: 'Doesnotexist',
2348 'data-parsoid': {
2349 body: {
2350 ids: {},
2351 },
2352 },
2353 html: {
2354 headers: {
2355 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + contentVersion + '"',
2356 },
2357 body: '<p><a rel="mw:WikiLink" href="./Special:Version" title="Special:Version">Special:Version</a> <a rel="mw:WikiLink" href="./Doesnotexist" title="Doesnotexist">Doesnotexist</a> <a rel="mw:WikiLink" href="./Redirected" title="Redirected">Redirected</a></p>',
2358 },
2359 },
2360 })
2361 .expect(acceptablePageBundleResponse(contentVersion, function(html) {
2362 var doc = domino.createDocument(html);
2363 doc.body.querySelectorAll('a').length.should.equal(3);
2364 var redLinks = doc.body.querySelectorAll('.new');
2365 redLinks.length.should.equal(1);
2366 redLinks[0].getAttribute('title').should.equal('Doesnotexist');
2367 var redirects = doc.body.querySelectorAll('.mw-redirect');
2368 redirects.length.should.equal(1);
2369 redirects[0].getAttribute('title').should.equal('Redirected');
2370 }))
2371 .end(done);
2372 });
2373
2374 describe('Variant conversion', function() {
2375
2376 it('should return unconverted nl page if sr variant conversion is requested on nl page', function(done) {
2377 client.req
2378 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/MediaWiki:ok%2Fnl')
2379 .send({
2380 updates: {
2381 variant: { target: 'sr-el' },
2382 },
2383 original: {
2384 revid,
2385 html: {
2386 headers: {
2387 'content-type': 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
2388 },
2389 body: '<p>абвг abcd</p>',
2390 },
2391 },
2392 })
2393 .expect(status200)
2394 .expect(validPageBundleResponse(function(doc) {
2395 doc.body.textContent.should.equal('абвг abcd');
2396 }))
2397 .end(done);
2398 });
2399
2400 it('should accept the original and do variant conversion (given oldid)', function(done) {
2401 if (skipForNow) {
2402 return this.skip();
2403 } // Enabled language conversion
2404 client.req
2405 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/')
2406 .send({
2407 updates: {
2408 variant: { target: 'sr-el' },
2409 },
2410 original: {
2411 revid: 104, /* sets the pagelanguage */
2412 html: {
2413 headers: {
2414 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
2415 },
2416 body: '<p>абвг abcd x</p>',
2417 },
2418 },
2419 })
2420 .expect(status200)
2421 .expect((res) => {
2422 // We don't actually require the result to have data-parsoid
2423 // if the input didn't have data-parsoid; hack the result
2424 // in order to make validPageBundleResponse() pass.
2425 res.body['data-parsoid'].body = {};
2426 })
2427 .expect(validPageBundleResponse(function(doc) {
2428 doc.body.textContent.should.equal('abvg abcd x');
2429 }))
2430 .expect((res) => {
2431 const headers = res.body.html.headers;
2432 headers.should.have.property('content-language');
2433 headers['content-language'].should.equal('sr-el');
2434 headers.should.have.property('vary');
2435 headers.vary.should.match(/\bAccept-Language\b/i);
2436 })
2437 .end(done);
2438 });
2439
2440 it('should accept the original and do variant conversion (given pagelanguage)', function(done) {
2441 if (skipForNow) {
2442 return this.skip();
2443 } // Enabled language conversion
2444 client.req
2445 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/')
2446 .set('Content-Language', 'sr')
2447 .set('Accept-Language', 'sr-el')
2448 .send({
2449 updates: {
2450 variant: { /* target implicit from accept-language */ },
2451 },
2452 original: {
2453 html: {
2454 headers: {
2455 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
2456 },
2457 body: '<p>абвг abcd</p>',
2458 },
2459 },
2460 })
2461 .expect(status200)
2462 .expect((res) => {
2463 // We don't actually require the result to have data-parsoid
2464 // if the input didn't have data-parsoid; hack the result
2465 // in order to make validPageBundleResponse() pass.
2466 res.body['data-parsoid'].body = {};
2467 })
2468 .expect(validPageBundleResponse(function(doc) {
2469 doc.body.textContent.should.equal('abvg abcd');
2470 }))
2471 .expect((res) => {
2472 const headers = res.body.html.headers;
2473 headers.should.have.property('content-language');
2474 headers['content-language'].should.equal('sr-el');
2475 headers.should.have.property('vary');
2476 headers.vary.should.match(/\bAccept-Language\b/i);
2477 })
2478 .end(done);
2479 });
2480
2481 it('should not perform variant conversion w/ invalid variant (given pagelanguage)', function(done) {
2482 client.req
2483 .post(mockDomain + '/v3/transform/pagebundle/to/pagebundle/')
2484 .set('Content-Language', 'sr')
2485 .set('Accept-Language', 'sr-BOGUS')
2486 .send({
2487 updates: {
2488 variant: { /* target implicit from accept-language */ },
2489 },
2490 original: {
2491 html: {
2492 headers: {
2493 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"',
2494 },
2495 body: '<p>абвг abcd</p>',
2496 },
2497 },
2498 })
2499 .expect(status200)
2500 .expect((res) => {
2501 // We don't actually require the result to have data-parsoid
2502 // if the input didn't have data-parsoid; hack the result
2503 // in order to make validPageBundleResponse() pass.
2504 res.body['data-parsoid'].body = {};
2505 })
2506 .expect(validPageBundleResponse(function(doc) {
2507 doc.body.textContent.should.equal('абвг abcd');
2508 }))
2509 .expect((res) => {
2510 const headers = res.body.html.headers;
2511 headers.should.have.property('content-language');
2512 headers['content-language'].should.equal('sr');
2513 headers.should.have.property('vary');
2514 headers.vary.should.match(/\bAccept-Language\b/i);
2515 })
2516 .end(done);
2517 });
2518
2519 });
2520
2521 }); // end pb2pb
2522
2523 describe( 'roundtrip-test', function () {
2524 // This mirrors the behavior of the runTests function in roundtrip-test.js
2525
2526 const transformOptions = {
2527 // For compatibility with Parsoid/PHP service, per roundtrip-test.js
2528 offsetType: 'ucs2'
2529 };
2530
2531 it( 'Roundtrip should convert wikitext to HTML and back, with selser working', async () => {
2532 // get the wikitext of the page
2533 const { text: oldWt } = await client.req
2534 .get( mockDomain + `/v3/page/wikitext/${ pageEncoded }` );
2535
2536 // First, fetch the HTML for the requested page's wikitext
2537 const wt2html = await client.req
2538 .post( mockDomain + `/v3/transform/wikitext/to/pagebundle/${ pageEncoded }` )
2539 .send( Object.assign( {
2540 wikitext: oldWt,
2541 }, transformOptions ) );
2542
2543 assert.equal( 200, wt2html.statusCode, wt2html.text );
2544
2545 // Now, request the wikitext for the obtained HTML, without providing the original HTML
2546 const pb2wt1 = await client.req
2547 .post( mockDomain + `/v3/transform/pagebundle/to/wikitext/${ pageEncoded }` )
2548 .send( Object.assign( {
2549 html: wt2html.body.html,
2550 }, transformOptions ) );
2551
2552 assert.equal( 200, pb2wt1.statusCode, pb2wt1.text );
2553
2554 // This might fail, since we are not applying selser.
2555 // We are trusting that the conversion back to wikitext will be clean.
2556 assert.equal( pb2wt1.text, oldWt );
2557
2558 // Now, request the wikitext for the obtained HTML, with Selser
2559 var newDocument = DOMUtils.parseHTML( wt2html.body.html.body );
2560 var newNode = newDocument.createComment('rtSelserEditTestComment');
2561 newDocument.body.appendChild(newNode);
2562
2563 const pb2wt2 = await client.req
2564 .post( mockDomain + `/v3/transform/pagebundle/to/wikitext/${ pageEncoded }` )
2565 .send( {
2566 html: newDocument.outerHTML,
2567 oldid: revid,
2568 original: {
2569 'data-parsoid': wt2html.body['data-parsoid'],
2570 'data-mw': wt2html.body['data-mw'],
2571 wikitext: { body: oldWt },
2572 html: wt2html.body.html,
2573 },
2574 ...transformOptions
2575 } );
2576
2577 assert.equal( 200, pb2wt2.statusCode, pb2wt2.text );
2578
2579 // Check that the comment was included in the wikitext
2580 assert.include( pb2wt2.text, 'rtSelserEditTestComment' );
2581
2582 // Remove the selser trigger comment
2583 const actual2 = pb2wt2.text.replace(/<!--rtSelserEditTestComment-->\n*$/, '');
2584
2585 assert.equal( actual2, oldWt );
2586 } );
2587
2588 } );
2589
2590 describe( 'ETags', function () {
2591
2592 it( '/transform/html must accept the ETag in the If-Match header, if one is returned by /page/html (T238849)', async () => {
2593 const { statusCode: status1, headers: headers1, text: text1 } = await client.req
2594 .get( mockDomain + `/v3/page/html/${ page }/${ revid }` )
2595 .query( { stash: 'yes' } );
2596
2597 assert.deepEqual( status1, 200, text1 );
2598
2599 if ( !headers1.etag ) {
2600 // This is a structure test that is asserting one of two acceptable situations:
2601 // Either, the page endpoint doesn't return an ETag. This implies that the
2602 // HTML wasn't stored anywhere, so it can't be re-used.
2603 // Or the transform endpoint accepts the ETag returned by the page endpoint.
2604 // This ensures that clients can loop through any ETags they receive.
2605 return;
2606 }
2607
2608 // The request above should have stashed a rendering associated with the ETag it
2609 // returned. Pass the ETag in the If-Match header.
2610 const { statusCode: status2, text: text2 } = await client.req
2611 .post( mockDomain + `/v3/transform/html/to/wikitext/${ page }/${ revid }` )
2612 .set( 'If-Match', headers1.etag )
2613 .send( {
2614 html: text1
2615 } );
2616
2617 // Just check we got a 200. The returned wikitext may or may not be "dirty".
2618 assert.deepEqual( status2, 200, text2 );
2619 } );
2620
2621 } );
2622 });