aboutsummaryrefslogtreecommitdiffstats
path: root/tests/api-testing/REST/content.v1/Page.js
blob: 49a103fff2f0f1882817511084df02426cbb8867 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
'use strict';

const { action, assert, REST, utils } = require( 'api-testing' );
const url = require( 'url' );

let pathPrefix = 'rest.php/content/v1';

// Parse a URL-ref, which may or may not contain a protocol and host.
// WHATWG URL currently doesn't support partial URLs, see https://github.com/whatwg/url/issues/531
function parseURL( ref ) {
	const urlObj = new url.URL( ref, 'http://fake-host' );
	const urlRec = {
		protocol: urlObj.protocol,
		host: urlObj.host,
		hostname: urlObj.hostname,
		port: urlObj.port,
		pathname: urlObj.pathname,
		search: urlObj.search,
		hash: urlObj.hash
	};

	if ( urlRec.hostname === 'fake-host' ) {
		urlRec.host = '';
		urlRec.hostname = '';
		urlRec.port = '';
	}

	return urlRec;
}

describe( 'Page Source', () => {
	const page = utils.title( 'PageSource_' );
	const pageWithSpaces = page.replace( '_', ' ' );
	const variantPage = utils.title( 'PageSourceVariant' );
	const fallbackVariantPage = 'MediaWiki:Tog-underline/sh-latn';

	// Create a page (or "agepay") for the pig latin variant test.
	const agepayHash = utils.title( '' ).replace( /\d/g, 'x' ).toLowerCase(); // only lower-case letters.
	const agepay = 'Page' + agepayHash; // will not exist
	const atinlayAgepay = 'Age' + agepayHash + 'pay'; // will exist

	const redirectPage = utils.title( 'Redirect ' );
	const redirectedPage = redirectPage.replace( 'Redirect', 'Redirected' );

	let client;
	let mindy;
	const baseEditText = "''Edit 1'' and '''Edit 2'''";

	before( async () => {
		client = new REST( pathPrefix );

		mindy = await action.mindy();
		await mindy.edit( page, { text: baseEditText } );
		await mindy.edit( atinlayAgepay, { text: baseEditText } );

		// Setup page with redirects
		await mindy.edit( redirectPage, { text: `Original name is ${ redirectPage }` } );
		const token = await mindy.token();
		await mindy.action( 'move', {
			from: redirectPage,
			to: redirectedPage,
			token
		}, true );
	} );

	describe( 'GET /page/{title}', () => {
		it( 'Title normalization should return permanent redirect (301)', async () => {
			const redirectDbKey = utils.dbkey( redirectPage );
			const { status, text, headers } = await client.get( `/page/${ redirectPage }`, { flavor: 'edit' } );
			const { host, search, pathname } = parseURL( headers.location );
			assert.include( search, 'flavor=edit' );
			assert.deepEqual( host, '' );
			assert.include( pathname, `/page/${ redirectDbKey }` );
			assert.deepEqual( status, 301, text );
		} );

		it( 'When a wiki redirect exists, it should be present in the body response', async () => {
			const redirectPageDbkey = utils.dbkey( redirectPage );
			const redirectedPageDbKey = utils.dbkey( redirectedPage );
			const { status, body: { redirect_target }, text, headers } =
				await client.get( `/page/${ redirectPageDbkey }` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.match( redirect_target, new RegExp( `/page/${ encodeURIComponent( redirectedPageDbKey ) }$` ) );
		} );

		it( 'Should successfully return page source and metadata for Wikitext page', async () => {
			const { status, body, text, headers } = await client.get( `/page/${ page }` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.match( headers.vary, /\bx-restbase-compat\b/ );
			assert.containsAllKeys( body, [ 'latest', 'id', 'key', 'license', 'title', 'content_model', 'source' ] );
			assert.nestedPropertyVal( body, 'content_model', 'wikitext' );
			assert.nestedPropertyVal( body, 'title', pageWithSpaces );
			assert.nestedPropertyVal( body, 'key', utils.dbkey( page ) );
			assert.nestedPropertyVal( body, 'source', baseEditText );
		} );
		it( 'Should return 404 error for non-existent page', async () => {
			const dummyPageTitle = utils.title( 'DummyPage_' );
			const { status } = await client.get( `/page/${ dummyPageTitle }` );
			assert.deepEqual( status, 404 );
		} );
		it( 'Should return 404 error for invalid titles', async () => {
			const badTitle = '::X::';
			const { status } = await client.get( `/page/${ badTitle }` );
			assert.deepEqual( status, 404 );
		} );
		it( 'Should return 404 error for special pages', async () => {
			const badTitle = 'Special:Blankpage';
			const { status } = await client.get( `/page/${ badTitle }` );
			assert.deepEqual( status, 404 );
		} );
		it( 'Should have appropriate response headers', async () => {
			const preEditResponse = await client.get( `/page/${ page }` );
			const preEditDate = new Date( preEditResponse.body.latest.timestamp );
			const preEditEtag = preEditResponse.headers.etag;

			await mindy.edit( page, { text: "'''Edit 3'''" } );
			const postEditResponse = await client.get( `/page/${ page }` );
			const postEditDate = new Date( postEditResponse.body.latest.timestamp );
			const postEditHeaders = postEditResponse.headers;
			const postEditEtag = postEditResponse.headers.etag;

			assert.containsAllKeys( postEditHeaders, [ 'etag' ] );
			assert.deepEqual( postEditHeaders[ 'last-modified' ], postEditDate.toGMTString() );
			assert.match( postEditHeaders[ 'cache-control' ], /^max-age=\d/ );
			assert.strictEqual( isNaN( preEditDate.getTime() ), false );
			assert.strictEqual( isNaN( postEditDate.getTime() ), false );
			assert.notEqual( preEditDate, postEditDate );
			assert.notEqual( preEditEtag, postEditEtag );
		} );
	} );

	describe( 'GET /page/{title}/bare', () => {
		it( 'Title normalization should return permanent redirect (301)', async () => {
			const { status, text, headers } = await client.get( `/page/${ redirectPage }/bare`, { flavor: 'edit' } );
			const { search } = parseURL( headers.location );
			assert.include( search, 'flavor=edit' );
			assert.deepEqual( status, 301, text );
		} );

		it( 'When a wiki redirect exists, it should be present in the body response', async () => {
			const redirectPageDbkey = utils.dbkey( redirectPage );
			const redirectedPageDbKey = utils.dbkey( redirectedPage );
			const { status, body: { redirect_target }, text, headers } =
				await client.get( `/page/${ redirectPageDbkey }/bare` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.match( redirect_target, new RegExp( `/page/${ encodeURIComponent( redirectedPageDbKey ) }/bare$` ) );
		} );

		it( 'Should successfully return page bare', async () => {
			const { status, body, text, headers } = await client.get( `/page/${ page }/bare` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.containsAllKeys( body, [ 'latest', 'id', 'key', 'license', 'title', 'content_model', 'html_url' ] );
			assert.nestedPropertyVal( body, 'content_model', 'wikitext' );
			assert.nestedPropertyVal( body, 'title', pageWithSpaces );
			assert.nestedPropertyVal( body, 'key', utils.dbkey( page ) );
			assert.match( body.html_url, new RegExp( `/page/${ encodeURIComponent( pageWithSpaces ) }/html$` ) );
		} );
		it( 'Should return 404 error for non-existent page, even if a variant exists', async () => {
			const agepayDbkey = utils.dbkey( agepay );
			const { status } = await client.get( `/page/${ agepayDbkey }/bare` );
			assert.deepEqual( status, 404 );
		} );
		it( 'Should have appropriate response headers', async () => {
			const preEditResponse = await client.get( `/page/${ page }/bare` );
			const preEditDate = new Date( preEditResponse.body.latest.timestamp );
			const preEditEtag = preEditResponse.headers.etag;

			await mindy.edit( page, { text: "'''Edit 4'''" } );
			const postEditResponse = await client.get( `/page/${ page }/bare` );
			const postEditDate = new Date( postEditResponse.body.latest.timestamp );
			const postEditHeaders = postEditResponse.headers;
			const postEditEtag = postEditResponse.headers.etag;

			assert.containsAllKeys( postEditHeaders, [ 'etag' ] );
			assert.deepEqual( postEditHeaders[ 'last-modified' ], postEditDate.toGMTString() );
			assert.match( postEditHeaders[ 'cache-control' ], /^max-age=\d/ );
			assert.strictEqual( isNaN( preEditDate.getTime() ), false );
			assert.strictEqual( isNaN( postEditDate.getTime() ), false );
			assert.notEqual( preEditDate, postEditDate );
			assert.notEqual( preEditEtag, postEditEtag );
		} );
	} );

	describe( 'GET /page/{title}/bare with x-restbase-compat', () => {
		it( 'Should successfully return restbase-compatible revision meta-data', async () => {
			const { status, body, text, headers } = await client
				.get( `/page/${ page }/bare` )
				.set( 'x-restbase-compat', 'true' );

			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.match( headers.vary, /\bx-restbase-compat\b/ );
			assert.containsAllKeys( body.items[ 0 ], [ 'title', 'page_id', 'rev', 'tid', 'namespace', 'user_id',
				'user_text', 'timestamp', 'comment', 'tags', 'restrictions', 'page_language', 'redirect' ] );

			assert.deepEqual( body.items[ 0 ].title, utils.dbkey( page ) );
			assert.isAbove( body.items[ 0 ].page_id, 0 );
			assert.isAbove( body.items[ 0 ].rev, 0 );
		} );

		it( 'Should successfully return restbase-compatible errors', async () => {
			const dummyPageTitle = utils.title( 'DummyPage_' );
			const { status, body, text, headers } = await client
				.get( `/page/${ dummyPageTitle }/bare` )
				.set( 'x-restbase-compat', 'true' );

			assert.deepEqual( status, 404, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.containsAllKeys( body, [ 'type', 'title', 'method', 'detail', 'uri' ] );
		} );
	} );

	describe( 'GET /page/{title}/html', () => {
		it( 'Title normalization should return permanent redirect (301)', async () => {
			const { status, text, headers } = await client.get( `/page/${ redirectPage }/html`, { flavor: 'edit' } );
			const { search } = parseURL( headers.location );
			assert.include( search, 'flavor=edit' );
			assert.deepEqual( status, 301, text );
		} );

		it( 'Wiki redirects should return temporary redirect (307)', async () => {
			const redirectPageDbkey = utils.dbkey( redirectPage );
			const redirectedPageDbkey = utils.dbkey( redirectedPage );
			const { status, text, headers } = await client.get( `/page/${ redirectPageDbkey }/html`, { flavor: 'edit' } );
			const { host, pathname, search } = parseURL( headers.location );
			assert.include( search, 'flavor=edit' );
			assert.include( pathname, `/page/${ redirectedPageDbkey }` );
			assert.deepEqual( host, '' );
			assert.deepEqual( status, 307, text );
		} );

		it( 'Variant redirects should return temporary redirect (307)', async () => {
			const agepayDbkey = utils.dbkey( agepay );
			const atinlayAgepayDbkey = utils.dbkey( atinlayAgepay );
			const { status, text, headers } = await client.get( `/page/${ agepayDbkey }/html` );
			assert.deepEqual( status, 307, text );
			assert.include( headers.location, atinlayAgepayDbkey );
		} );

		it( 'Bypass wiki redirects with query param redirect=no', async () => {
			const redirectPageDbkey = utils.dbkey( redirectPage );
			const { status, text, headers } = await client.get(
				`/page/${ redirectPageDbkey }/html`,
				{ redirect: 'no' }
			);
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^text\/html/ );
		} );

		it( 'Bypass variant redirects with query param redirect=no', async () => {
			const agepayDbkey = utils.dbkey( agepay );
			const { status, headers } = await client.get(
				`/page/${ agepayDbkey }/html`,
				{ redirect: 'no' }
			);
			assert.deepEqual( status, 404 );
			// rest-nonexistent-title error object returned instead of HTML
			assert.match( headers[ 'content-type' ], /^application\/json/ );
		} );

		it( 'Should successfully return page HTML', async () => {
			const { status, headers, text } = await client.get( `/page/${ page }/html` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^text\/html/ );
			assert.match( text, /<html\b/ );
			assert.match( text, /Edit \w+<\/b>/ );
		} );
		it( 'Should successfully return page HTML for a system message', async () => {
			const msg = 'MediaWiki:Newpage-desc';
			const { status, headers, text } = await client.get( `/page/${ msg }/html` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^text\/html/ );
			assert.match( text, /<html\b/ );
			assert.match( text, /Start a new page/ );
		} );
		it( 'Should return 404 error for non-existent page', async () => {
			const dummyPageTitle = utils.title( 'DummyPage_' );
			const { status } = await client.get( `/page/${ dummyPageTitle }/html` );
			assert.deepEqual( status, 404 );
		} );
		it( 'Should have appropriate response headers', async () => {
			const preEditResponse = await client.get( `/page/${ page }/html` );
			const preEditDate = new Date( preEditResponse.headers[ 'last-modified' ] );
			const preEditEtag = preEditResponse.headers.etag;

			await mindy.edit( page, { text: "'''Edit XYZ'''" } );
			const postEditResponse = await client.get( `/page/${ page }/html` );
			const postEditDate = new Date( postEditResponse.headers[ 'last-modified' ] );
			const postEditHeaders = postEditResponse.headers;
			const postEditEtag = postEditResponse.headers.etag;

			assert.containsAllKeys( postEditHeaders, [ 'etag', 'cache-control', 'last-modified' ] );
			assert.match( postEditHeaders[ 'cache-control' ], /^max-age=\d/ );
			assert.strictEqual( isNaN( preEditDate.getTime() ), false );
			assert.strictEqual( isNaN( postEditDate.getTime() ), false );
			assert.notEqual( preEditDate, postEditDate );
			assert.notEqual( preEditEtag, postEditEtag );
			assert.match( postEditHeaders.etag, /^".*"$/, 'ETag must be present and not marked weak' );
		} );
		it( 'Should perform variant conversion', async () => {
			await mindy.edit( variantPage, { text: '<p>test language conversion</p>' } );
			const { headers, text } = await client.get( `/page/${ variantPage }/html`, null, {
				'accept-language': 'en-x-piglatin'
			} );

			assert.match( text, /esttay anguagelay onversioncay/ );
			assert.match( headers[ 'content-type' ], /^text\/html/ );
			assert.match( headers.vary, /\bAccept-Language\b/i );
			assert.match( headers[ 'content-language' ], /en-x-piglatin/i );
			assert.match( headers.etag, /en-x-piglatin/i );
		} );
		it( 'Should perform fallback variant conversion', async () => {
			await mindy.edit( fallbackVariantPage, { text: 'Podvlačenje linkova:' } );
			const { headers, text } = await client.get( `/page/${ encodeURIComponent( fallbackVariantPage ) }/html`, null, {
				'accept-language': 'sh-cyrl'
			} );

			assert.match( text, /Подвлачење линкова:/ );
			assert.match( headers[ 'content-type' ], /^text\/html/ );
			assert.match( headers.vary, /\bAccept-Language\b/i );
			assert.match( headers[ 'content-language' ], /sh-cyrl/i );
			assert.match( headers.etag, /sh-cyrl/i );
		} );
	} );

	describe( 'GET /page/{title}/html with x-restbase-compat', () => {
		it( 'Should successfully return restbase-compatible errors', async () => {
			const dummyPageTitle = utils.title( 'DummyPage_' );
			const { status, body, text, headers } = await client
				.get( `/page/${ dummyPageTitle }/html` )
				.set( 'x-restbase-compat', 'true' );

			assert.deepEqual( status, 404, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.containsAllKeys( body, [ 'type', 'title', 'method', 'detail', 'uri' ] );
		} );
	} );

	describe( 'GET /page/{title}/with_html', () => {
		it( 'Title normalization should return permanent redirect (301)', async () => {
			const { status, text, headers } = await client.get( `/page/${ redirectPage }/with_html`, { flavor: 'edit' } );
			const { search } = parseURL( headers.location );
			assert.include( search, 'flavor=edit' );
			assert.deepEqual( status, 301, text );
		} );

		it( 'Wiki redirects should return temporary redirect (307)', async () => {
			const redirectPageDbkey = utils.dbkey( redirectPage );
			const { status, text, headers } = await client.get( `/page/${ redirectPageDbkey }/with_html`, { flavor: 'edit' } );
			const { search } = parseURL( headers.location );
			assert.include( search, 'flavor=edit' );
			assert.deepEqual( status, 307, text );
		} );

		it( 'Bypass redirects with query param redirect=no', async () => {
			const redirectPageDbkey = utils.dbkey( redirectPage );
			const redirectedPageDbKey = utils.dbkey( redirectedPage );
			const { status, body: { redirect_target }, text, headers } = await client.get(
				`/page/${ redirectPageDbkey }/with_html`,
				{ redirect: 'no' }
			);
			assert.match( redirect_target, new RegExp( `/page/${ encodeURIComponent( redirectedPageDbKey ) }/with_html` ) );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
		} );

		it( 'Should successfully return page HTML and metadata for Wikitext page', async () => {
			const { status, body, text, headers } = await client.get( `/page/${ page }/with_html` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.containsAllKeys( body, [ 'latest', 'id', 'key', 'license', 'title', 'content_model', 'html' ] );
			assert.nestedPropertyVal( body, 'content_model', 'wikitext' );
			assert.nestedPropertyVal( body, 'title', pageWithSpaces );
			assert.nestedPropertyVal( body, 'key', utils.dbkey( page ) );
			assert.match( body.html, /<html\b/ );
			assert.match( body.html, /Edit \w+<\/b>/ );
		} );
		it( 'Should successfully return page HTML and metadata for a system message', async () => {
			const msg = 'MediaWiki:Newpage-desc';
			const { status, body, text, headers } = await client.get( `/page/${ msg }/with_html` );
			assert.deepEqual( status, 200, text );
			assert.match( headers[ 'content-type' ], /^application\/json/ );
			assert.containsAllKeys( body, [ 'latest', 'id', 'key', 'license', 'title', 'content_model', 'html' ] );
			assert.nestedPropertyVal( body, 'content_model', 'wikitext' );
			assert.nestedPropertyVal( body, 'title', msg );
			assert.nestedPropertyVal( body, 'key', utils.dbkey( msg ) );
			assert.nestedPropertyVal( body, 'id', 0 );
			assert.nestedPropertyVal( body.latest, 'id', 0 );
			assert.match( body.html, /<html\b/ );
			assert.match( body.html, /Start a new page/ );
		} );
		it( 'Should return 404 error for non-existent page', async () => {
			const dummyPageTitle = utils.title( 'DummyPage_' );
			const { status } = await client.get( `/page/${ dummyPageTitle }/with_html` );
			assert.deepEqual( status, 404 );
		} );
		it( 'Should have appropriate response headers', async () => {
			const preEditResponse = await client.get( `/page/${ page }/with_html` );
			const preEditRevDate = new Date( preEditResponse.body.latest.timestamp );
			const preEditEtag = preEditResponse.headers.etag;

			await mindy.edit( page, { text: "'''Edit ABCD'''" } );
			const postEditResponse = await client.get( `/page/${ page }/with_html` );
			const postEditRevDate = new Date( postEditResponse.body.latest.timestamp );
			const postEditHeaders = postEditResponse.headers;
			const postEditEtag = postEditResponse.headers.etag;

			assert.containsAllKeys( postEditHeaders, [ 'etag', 'last-modified' ] );
			const postEditHeaderDate = new Date( postEditHeaders[ 'last-modified' ] );

			// The last-modified date is the render timestamp, which may be newer than the revision
			assert.strictEqual( postEditRevDate.valueOf() <= postEditHeaderDate.valueOf(), true );
			assert.match( postEditHeaders[ 'cache-control' ], /^max-age=\d/ );
			assert.strictEqual( isNaN( preEditRevDate.getTime() ), false );
			assert.strictEqual( isNaN( postEditRevDate.getTime() ), false );
			assert.notEqual( preEditRevDate, postEditRevDate );
			assert.notEqual( preEditEtag, postEditEtag );
		} );
		it( 'Should perform variant conversion', async () => {
			await mindy.edit( variantPage, { text: '<p>test language conversion</p>' } );
			const { headers, text } = await client.get( `/page/${ variantPage }/html`, null, {
				'accept-language': 'en-x-piglatin'
			} );

			assert.match( text, /esttay anguagelay onversioncay/ );
			assert.match( headers[ 'content-type' ], /^text\/html/ );
			assert.match( headers.vary, /\bAccept-Language\b/i );
			assert.match( headers.etag, /en-x-piglatin/i );

			// Since with_html returns JSON, content language is not set
			// but if its set, we expect it to be set correctly.
			const contentLanguageHeader = headers[ 'content-language' ];
			if ( contentLanguageHeader ) {
				assert.match( headers[ 'content-language' ], /en-x-piglatin/i );
			}
		} );
		it( 'Should perform fallback variant conversion', async () => {
			await mindy.edit( fallbackVariantPage, { text: 'Podvlačenje linkova:' } );
			const { headers, text } = await client.get( `/page/${ encodeURIComponent( fallbackVariantPage ) }/html`, null, {
				'accept-language': 'sh-cyrl'
			} );

			assert.match( text, /Подвлачење линкова:/ );
			assert.match( headers[ 'content-type' ], /^text\/html/ );
			assert.match( headers.vary, /\bAccept-Language\b/i );
			assert.match( headers.etag, /sh-cyrl/i );

			// Since with_html returns JSON, content language is not set
			// but if its set, we expect it to be set correctly.
			const contentLanguageHeader = headers[ 'content-language' ];
			if ( contentLanguageHeader ) {
				assert.match( headers[ 'content-language' ], /sh-cyrl/i );
			}
		} );
	} );
} );

// eslint-disable-next-line mocha/no-exports
exports.init = function ( pp ) {
	// Allow testing both legacy and module paths using the same tests
	pathPrefix = pp;
};