7 * @covers ApiComparePages
9 class ApiComparePagesTest
extends ApiTestCase
{
11 protected static $repl = [];
13 protected function addPage( $page, $text, $model = CONTENT_MODEL_WIKITEXT
) {
14 $title = Title
::newFromText( 'ApiComparePagesTest ' . $page );
15 $content = ContentHandler
::makeContent( $text, $title, $model );
17 $page = WikiPage
::factory( $title );
18 $user = static::getTestSysop()->getUser();
19 $status = $page->doEditContent(
20 $content, 'Test for ApiComparePagesTest: ' . $text, 0, false, $user
22 if ( !$status->isOK() ) {
23 $this->fail( "Failed to create $title: " . $status->getWikiText( false, false, 'en' ) );
25 return $status->value
['revision']->getId();
28 public function addDBDataOnce() {
29 $user = static::getTestSysop()->getUser();
30 self
::$repl['creator'] = $user->getName();
31 self
::$repl['creatorid'] = $user->getId();
33 self
::$repl['revA1'] = $this->addPage( 'A', 'A 1' );
34 self
::$repl['revA2'] = $this->addPage( 'A', 'A 2' );
35 self
::$repl['revA3'] = $this->addPage( 'A', 'A 3' );
36 self
::$repl['revA4'] = $this->addPage( 'A', 'A 4' );
37 self
::$repl['pageA'] = Title
::newFromText( 'ApiComparePagesTest A' )->getArticleID();
39 self
::$repl['revB1'] = $this->addPage( 'B', 'B 1' );
40 self
::$repl['revB2'] = $this->addPage( 'B', 'B 2' );
41 self
::$repl['revB3'] = $this->addPage( 'B', 'B 3' );
42 self
::$repl['revB4'] = $this->addPage( 'B', 'B 4' );
43 self
::$repl['pageB'] = Title
::newFromText( 'ApiComparePagesTest B' )->getArticleID();
45 self
::$repl['revC1'] = $this->addPage( 'C', 'C 1' );
46 self
::$repl['revC2'] = $this->addPage( 'C', 'C 2' );
47 self
::$repl['revC3'] = $this->addPage( 'C', 'C 3' );
48 self
::$repl['pageC'] = Title
::newFromText( 'ApiComparePagesTest C' )->getArticleID();
50 $id = $this->addPage( 'D', 'D 1' );
51 self
::$repl['pageD'] = Title
::newFromText( 'ApiComparePagesTest D' )->getArticleID();
52 wfGetDB( DB_MASTER
)->delete( 'revision', [ 'rev_id' => $id ] );
54 self
::$repl['revE1'] = $this->addPage( 'E', 'E 1' );
55 self
::$repl['revE2'] = $this->addPage( 'E', 'E 2' );
56 self
::$repl['revE3'] = $this->addPage( 'E', 'E 3' );
57 self
::$repl['revE4'] = $this->addPage( 'E', 'E 4' );
58 self
::$repl['pageE'] = Title
::newFromText( 'ApiComparePagesTest E' )->getArticleID();
59 wfGetDB( DB_MASTER
)->update(
60 'page', [ 'page_latest' => 0 ], [ 'page_id' => self
::$repl['pageE'] ]
63 self
::$repl['revF1'] = $this->addPage( 'F', "== Section 1 ==\nF 1.1\n\n== Section 2 ==\nF 1.2" );
64 self
::$repl['pageF'] = Title
::newFromText( 'ApiComparePagesTest F' )->getArticleID();
66 self
::$repl['revG1'] = $this->addPage( 'G', "== Section 1 ==\nG 1.1", CONTENT_MODEL_TEXT
);
67 self
::$repl['pageG'] = Title
::newFromText( 'ApiComparePagesTest G' )->getArticleID();
69 WikiPage
::factory( Title
::newFromText( 'ApiComparePagesTest C' ) )
70 ->doDeleteArticleReal( 'Test for ApiComparePagesTest' );
72 RevisionDeleter
::createList(
74 RequestContext
::getMain(),
75 Title
::newFromText( 'ApiComparePagesTest B' ),
76 [ self
::$repl['revB2'] ]
79 Revision
::DELETED_TEXT
=> 1,
80 Revision
::DELETED_USER
=> 1,
81 Revision
::DELETED_COMMENT
=> 1,
83 'comment' => 'Test for ApiComparePages',
86 RevisionDeleter
::createList(
88 RequestContext
::getMain(),
89 Title
::newFromText( 'ApiComparePagesTest B' ),
90 [ self
::$repl['revB3'] ]
93 Revision
::DELETED_USER
=> 1,
94 Revision
::DELETED_COMMENT
=> 1,
95 Revision
::DELETED_RESTRICTED
=> 1,
97 'comment' => 'Test for ApiComparePages',
100 Title
::clearCaches(); // Otherwise it has the wrong latest revision for some reason
103 protected function doReplacements( &$value ) {
104 if ( is_string( $value ) ) {
105 if ( preg_match( '/^{{REPL:(.+?)}}$/', $value, $m ) ) {
106 $value = self
::$repl[$m[1]];
108 $value = preg_replace_callback( '/{{REPL:(.+?)}}/', function ( $m ) {
109 return self
::$repl[$m[1]] ??
$m[0];
112 } elseif ( is_array( $value ) ||
is_object( $value ) ) {
113 foreach ( $value as &$v ) {
114 $this->doReplacements( $v );
121 * @dataProvider provideDiff
123 public function testDiff( $params, $expect, $exceptionCode = false, $sysop = false ) {
124 $this->doReplacements( $params );
127 'action' => 'compare',
128 'errorformat' => 'none',
132 ?
static::getTestSysop()->getUser()
133 : static::getTestUser()->getUser();
134 if ( $exceptionCode ) {
136 $this->doApiRequest( $params, null, false, $user );
137 $this->fail( 'Expected exception not thrown' );
138 } catch ( ApiUsageException
$ex ) {
139 $this->assertTrue( $this->apiExceptionHasCode( $ex, $exceptionCode ),
140 "Exception with code $exceptionCode" );
143 $apiResult = $this->doApiRequest( $params, null, false, $user );
144 $apiResult = $apiResult[0];
145 $this->doReplacements( $expect );
146 $this->assertEquals( $expect, $apiResult );
150 private static function makeDeprecationWarnings( ...$params ) {
152 foreach ( $params as $p ) {
154 'code' => 'deprecation',
155 'data' => [ 'feature' => "action=compare&{$p}" ],
156 'module' => 'compare',
158 if ( count( $warn ) === 1 ) {
160 'code' => 'deprecation-help',
169 public static function provideDiff() {
170 // phpcs:disable Generic.Files.LineLength.TooLong
172 'Basic diff, titles' => [
174 'fromtitle' => 'ApiComparePagesTest A',
175 'totitle' => 'ApiComparePagesTest B',
179 'fromid' => '{{REPL:pageA}}',
180 'fromrevid' => '{{REPL:revA4}}',
182 'fromtitle' => 'ApiComparePagesTest A',
183 'toid' => '{{REPL:pageB}}',
184 'torevid' => '{{REPL:revB4}}',
186 'totitle' => 'ApiComparePagesTest B',
187 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
188 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
189 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>4</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">B </ins>4</div></td></tr>' . "\n",
193 'Basic diff, page IDs' => [
195 'fromid' => '{{REPL:pageA}}',
196 'toid' => '{{REPL:pageB}}',
200 'fromid' => '{{REPL:pageA}}',
201 'fromrevid' => '{{REPL:revA4}}',
203 'fromtitle' => 'ApiComparePagesTest A',
204 'toid' => '{{REPL:pageB}}',
205 'torevid' => '{{REPL:revB4}}',
207 'totitle' => 'ApiComparePagesTest B',
208 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
209 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
210 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>4</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">B </ins>4</div></td></tr>' . "\n",
214 'Basic diff, revision IDs' => [
216 'fromrev' => '{{REPL:revA2}}',
217 'torev' => '{{REPL:revA3}}',
221 'fromid' => '{{REPL:pageA}}',
222 'fromrevid' => '{{REPL:revA2}}',
224 'fromtitle' => 'ApiComparePagesTest A',
225 'toid' => '{{REPL:pageA}}',
226 'torevid' => '{{REPL:revA3}}',
228 'totitle' => 'ApiComparePagesTest A',
229 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
230 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
231 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>A <del class="diffchange diffchange-inline">2</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>A <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
235 'Basic diff, deleted revision ID as sysop' => [
237 'fromrev' => '{{REPL:revA2}}',
238 'torev' => '{{REPL:revC2}}',
242 'fromid' => '{{REPL:pageA}}',
243 'fromrevid' => '{{REPL:revA2}}',
245 'fromtitle' => 'ApiComparePagesTest A',
247 'torevid' => '{{REPL:revC2}}',
249 'totitle' => 'ApiComparePagesTest C',
251 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
252 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
253 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>2</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">C </ins>2</div></td></tr>' . "\n",
258 'Basic diff, revdel as sysop' => [
260 'fromrev' => '{{REPL:revA2}}',
261 'torev' => '{{REPL:revB2}}',
265 'fromid' => '{{REPL:pageA}}',
266 'fromrevid' => '{{REPL:revA2}}',
268 'fromtitle' => 'ApiComparePagesTest A',
269 'toid' => '{{REPL:pageB}}',
270 'torevid' => '{{REPL:revB2}}',
272 'totitle' => 'ApiComparePagesTest B',
273 'totexthidden' => true,
274 'touserhidden' => true,
275 'tocommenthidden' => true,
276 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
277 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
278 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>2</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">B </ins>2</div></td></tr>' . "\n",
283 'Basic diff, text' => [
285 'fromslots' => 'main',
286 'fromtext-main' => 'From text',
287 'fromcontentmodel-main' => 'wikitext',
289 'totext-main' => 'To text {{subst:PAGENAME}}',
290 'tocontentmodel-main' => 'wikitext',
294 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
295 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
296 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
300 'Basic diff, text 2' => [
302 'fromslots' => 'main',
303 'fromtext-main' => 'From text',
305 'totext-main' => 'To text {{subst:PAGENAME}}',
306 'tocontentmodel-main' => 'wikitext',
310 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
311 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
312 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
316 'Basic diff, guessed model' => [
318 'fromslots' => 'main',
319 'fromtext-main' => 'From text',
321 'totext-main' => 'To text',
324 'warnings' => [ [ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ] ],
326 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
327 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
328 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text</div></td></tr>' . "\n",
332 'Basic diff, text with title and PST' => [
334 'fromslots' => 'main',
335 'fromtext-main' => 'From text',
338 'totext-main' => 'To text {{subst:PAGENAME}}',
343 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
344 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
345 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">Test</ins></div></td></tr>' . "\n",
349 'Basic diff, text with page ID and PST' => [
351 'fromslots' => 'main',
352 'fromtext-main' => 'From text',
353 'toid' => '{{REPL:pageB}}',
355 'totext-main' => 'To text {{subst:PAGENAME}}',
360 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
361 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
362 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
366 'Basic diff, text with revision and PST' => [
368 'fromslots' => 'main',
369 'fromtext-main' => 'From text',
370 'torev' => '{{REPL:revB2}}',
372 'totext-main' => 'To text {{subst:PAGENAME}}',
377 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
378 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
379 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
383 'Basic diff, text with deleted revision and PST' => [
385 'fromslots' => 'main',
386 'fromtext-main' => 'From text',
387 'torev' => '{{REPL:revC2}}',
389 'totext-main' => 'To text {{subst:PAGENAME}}',
394 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
395 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
396 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest C</ins></div></td></tr>' . "\n",
401 'Basic diff, test with sections' => [
403 'fromtitle' => 'ApiComparePagesTest F',
404 'fromslots' => 'main',
405 'fromtext-main' => "== Section 2 ==\nFrom text?",
406 'fromsection-main' => 2,
407 'totitle' => 'ApiComparePagesTest F',
409 'totext-main' => "== Section 1 ==\nTo text?",
410 'tosection-main' => 1,
414 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
415 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
416 . '<tr><td class=\'diff-marker\'>Â </td><td class=\'diff-context\'><div>== Section 1 ==</div></td><td class=\'diff-marker\'>Â </td><td class=\'diff-context\'><div>== Section 1 ==</div></td></tr>' . "\n"
417 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">F 1.1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To text?</ins></div></td></tr>' . "\n"
418 . '<tr><td class=\'diff-marker\'>Â </td><td class=\'diff-context\'></td><td class=\'diff-marker\'>Â </td><td class=\'diff-context\'></td></tr>' . "\n"
419 . '<tr><td class=\'diff-marker\'>Â </td><td class=\'diff-context\'><div>== Section 2 ==</div></td><td class=\'diff-marker\'>Â </td><td class=\'diff-context\'><div>== Section 2 ==</div></td></tr>' . "\n"
420 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From text?</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">F 1.2</ins></div></td></tr>' . "\n",
424 'Diff with all props' => [
426 'fromrev' => '{{REPL:revB1}}',
427 'torev' => '{{REPL:revB3}}',
428 'totitle' => 'ApiComparePagesTest B',
429 'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size'
433 'fromid' => '{{REPL:pageB}}',
434 'fromrevid' => '{{REPL:revB1}}',
436 'fromtitle' => 'ApiComparePagesTest B',
438 'fromuser' => '{{REPL:creator}}',
439 'fromuserid' => '{{REPL:creatorid}}',
440 'fromcomment' => 'Test for ApiComparePagesTest: B 1',
441 'fromparsedcomment' => 'Test for ApiComparePagesTest: B 1',
442 'toid' => '{{REPL:pageB}}',
443 'torevid' => '{{REPL:revB3}}',
445 'totitle' => 'ApiComparePagesTest B',
447 'touserhidden' => true,
448 'tocommenthidden' => true,
449 'tosuppressed' => true,
450 'next' => '{{REPL:revB4}}',
452 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
453 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
454 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>B <del class="diffchange diffchange-inline">1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>B <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
458 'Diff with all props as sysop' => [
460 'fromrev' => '{{REPL:revB2}}',
461 'torev' => '{{REPL:revB3}}',
462 'totitle' => 'ApiComparePagesTest B',
463 'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size'
467 'fromid' => '{{REPL:pageB}}',
468 'fromrevid' => '{{REPL:revB2}}',
470 'fromtitle' => 'ApiComparePagesTest B',
472 'fromtexthidden' => true,
473 'fromuserhidden' => true,
474 'fromuser' => '{{REPL:creator}}',
475 'fromuserid' => '{{REPL:creatorid}}',
476 'fromcommenthidden' => true,
477 'fromcomment' => 'Test for ApiComparePagesTest: B 2',
478 'fromparsedcomment' => 'Test for ApiComparePagesTest: B 2',
479 'toid' => '{{REPL:pageB}}',
480 'torevid' => '{{REPL:revB3}}',
482 'totitle' => 'ApiComparePagesTest B',
484 'touserhidden' => true,
485 'tocommenthidden' => true,
486 'tosuppressed' => true,
487 'prev' => '{{REPL:revB1}}',
488 'next' => '{{REPL:revB4}}',
490 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
491 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
492 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>B <del class="diffchange diffchange-inline">2</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>B <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
497 'Relative diff, cur' => [
499 'fromrev' => '{{REPL:revA2}}',
500 'torelative' => 'cur',
505 'fromid' => '{{REPL:pageA}}',
506 'fromrevid' => '{{REPL:revA2}}',
507 'toid' => '{{REPL:pageA}}',
508 'torevid' => '{{REPL:revA4}}',
512 'Relative diff, next' => [
514 'fromrev' => '{{REPL:revE2}}',
515 'torelative' => 'next',
520 'fromid' => '{{REPL:pageE}}',
521 'fromrevid' => '{{REPL:revE2}}',
522 'toid' => '{{REPL:pageE}}',
523 'torevid' => '{{REPL:revE3}}',
524 'prev' => '{{REPL:revE1}}',
525 'next' => '{{REPL:revE4}}',
529 'Relative diff, prev' => [
531 'fromrev' => '{{REPL:revE3}}',
532 'torelative' => 'prev',
537 'fromid' => '{{REPL:pageE}}',
538 'fromrevid' => '{{REPL:revE2}}',
539 'toid' => '{{REPL:pageE}}',
540 'torevid' => '{{REPL:revE3}}',
541 'prev' => '{{REPL:revE1}}',
542 'next' => '{{REPL:revE4}}',
546 'Relative diff, no prev' => [
548 'fromrev' => '{{REPL:revA1}}',
549 'torelative' => 'prev',
550 'prop' => 'ids|rel|diff|title|user|comment',
555 'code' => 'compare-no-prev',
556 'module' => 'compare',
560 'toid' => '{{REPL:pageA}}',
561 'torevid' => '{{REPL:revA1}}',
563 'totitle' => 'ApiComparePagesTest A',
564 'touser' => '{{REPL:creator}}',
565 'touserid' => '{{REPL:creatorid}}',
566 'tocomment' => 'Test for ApiComparePagesTest: A 1',
567 'toparsedcomment' => 'Test for ApiComparePagesTest: A 1',
568 'next' => '{{REPL:revA2}}',
569 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
570 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
571 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div> </div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">A 1</ins></div></td></tr>' . "\n",
575 'Relative diff, no next' => [
577 'fromrev' => '{{REPL:revA4}}',
578 'torelative' => 'next',
579 'prop' => 'ids|rel|diff|title|user|comment',
584 'code' => 'compare-no-next',
585 'module' => 'compare',
589 'fromid' => '{{REPL:pageA}}',
590 'fromrevid' => '{{REPL:revA4}}',
592 'fromtitle' => 'ApiComparePagesTest A',
593 'fromuser' => '{{REPL:creator}}',
594 'fromuserid' => '{{REPL:creatorid}}',
595 'fromcomment' => 'Test for ApiComparePagesTest: A 4',
596 'fromparsedcomment' => 'Test for ApiComparePagesTest: A 4',
597 'prev' => '{{REPL:revA3}}',
602 'Diff for specific slots' => [
603 // @todo Use a page with multiple slots here
605 'fromrev' => '{{REPL:revA1}}',
606 'torev' => '{{REPL:revA3}}',
613 'main' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
614 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
615 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>A <del class="diffchange diffchange-inline">1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>A <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
620 // @todo Add a test for diffing with a deleted slot. Deleting 'main' doesn't work.
622 'Basic diff, deprecated text' => [
624 'fromtext' => 'From text',
625 'fromcontentmodel' => 'wikitext',
626 'totext' => 'To text {{subst:PAGENAME}}',
627 'tocontentmodel' => 'wikitext',
630 'warnings' => self
::makeDeprecationWarnings( 'fromtext', 'fromcontentmodel', 'totext', 'tocontentmodel' ),
632 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
633 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
634 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
638 'Basic diff, deprecated text 2' => [
640 'fromtext' => 'From text',
641 'totext' => 'To text {{subst:PAGENAME}}',
642 'tocontentmodel' => 'wikitext',
645 'warnings' => self
::makeDeprecationWarnings( 'fromtext', 'totext', 'tocontentmodel' ),
647 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
648 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
649 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
653 'Basic diff, deprecated text, guessed model' => [
655 'fromtext' => 'From text',
656 'totext' => 'To text',
659 'warnings' => array_merge( self
::makeDeprecationWarnings( 'fromtext', 'totext' ), [
660 [ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ],
663 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
664 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
665 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text</div></td></tr>' . "\n",
669 'Basic diff, deprecated text with title and PST' => [
671 'fromtext' => 'From text',
673 'totext' => 'To text {{subst:PAGENAME}}',
677 'warnings' => self
::makeDeprecationWarnings( 'fromtext', 'totext' ),
679 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
680 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
681 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">Test</ins></div></td></tr>' . "\n",
685 'Basic diff, deprecated text with page ID and PST' => [
687 'fromtext' => 'From text',
688 'toid' => '{{REPL:pageB}}',
689 'totext' => 'To text {{subst:PAGENAME}}',
693 'warnings' => self
::makeDeprecationWarnings( 'fromtext', 'totext' ),
695 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
696 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
697 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
701 'Basic diff, deprecated text with revision and PST' => [
703 'fromtext' => 'From text',
704 'torev' => '{{REPL:revB2}}',
705 'totext' => 'To text {{subst:PAGENAME}}',
709 'warnings' => self
::makeDeprecationWarnings( 'fromtext', 'totext' ),
711 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
712 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
713 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
717 'Basic diff, deprecated text with deleted revision and PST' => [
719 'fromtext' => 'From text',
720 'torev' => '{{REPL:revC2}}',
721 'totext' => 'To text {{subst:PAGENAME}}',
725 'warnings' => self
::makeDeprecationWarnings( 'fromtext', 'totext' ),
727 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
728 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
729 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest C</ins></div></td></tr>' . "\n",
734 'Basic diff, test with deprecated sections' => [
736 'fromtitle' => 'ApiComparePagesTest F',
738 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?",
742 'warnings' => self
::makeDeprecationWarnings( 'fromsection', 'totext', 'tosection' ),
744 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
745 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
746 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>== Section <del class="diffchange diffchange-inline">1 </del>==</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>== Section <ins class="diffchange diffchange-inline">2 </ins>==</div></td></tr>' . "\n"
747 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">F 1.1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To text?</ins></div></td></tr>' . "\n",
748 'fromid' => '{{REPL:pageF}}',
749 'fromrevid' => '{{REPL:revF1}}',
751 'fromtitle' => 'ApiComparePagesTest F',
755 'Basic diff, test with deprecated sections and revdel, non-sysop' => [
757 'fromrev' => '{{REPL:revB2}}',
759 'torev' => '{{REPL:revB4}}',
765 'Basic diff, test with deprecated sections and revdel, sysop' => [
767 'fromrev' => '{{REPL:revB2}}',
769 'torev' => '{{REPL:revB4}}',
773 'warnings' => self
::makeDeprecationWarnings( 'fromsection', 'tosection' ),
775 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
776 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
777 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>B <del class="diffchange diffchange-inline">2</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>B <ins class="diffchange diffchange-inline">4</ins></div></td></tr>' . "\n",
778 'fromid' => '{{REPL:pageB}}',
779 'fromrevid' => '{{REPL:revB2}}',
781 'fromtitle' => 'ApiComparePagesTest B',
782 'fromtexthidden' => true,
783 'fromuserhidden' => true,
784 'fromcommenthidden' => true,
785 'toid' => '{{REPL:pageB}}',
786 'torevid' => '{{REPL:revB4}}',
788 'totitle' => 'ApiComparePagesTest B',
794 'Error, missing title' => [
796 'fromtitle' => 'ApiComparePagesTest X',
797 'totitle' => 'ApiComparePagesTest B',
802 'Error, invalid title' => [
804 'fromtitle' => '<bad>',
805 'totitle' => 'ApiComparePagesTest B',
810 'Error, missing page ID' => [
813 'totitle' => 'ApiComparePagesTest B',
818 'Error, page with missing revision' => [
820 'fromtitle' => 'ApiComparePagesTest D',
821 'totitle' => 'ApiComparePagesTest B',
826 'Error, page with no revision' => [
828 'fromtitle' => 'ApiComparePagesTest E',
829 'totitle' => 'ApiComparePagesTest B',
834 'Error, bad rev ID' => [
836 'fromrev' => 8817900,
837 'totitle' => 'ApiComparePagesTest B',
842 'Error, deleted revision ID, non-sysop' => [
844 'fromrev' => '{{REPL:revA2}}',
845 'torev' => '{{REPL:revC2}}',
850 'Error, deleted revision ID and torelative=prev' => [
852 'fromrev' => '{{REPL:revC2}}',
853 'torelative' => 'prev',
856 'compare-relative-to-deleted', true
858 'Error, deleted revision ID and torelative=next' => [
860 'fromrev' => '{{REPL:revC2}}',
861 'torelative' => 'next',
864 'compare-relative-to-deleted', true
866 'Deleted revision ID and torelative=cur' => [
868 'fromrev' => '{{REPL:revC2}}',
869 'torelative' => 'cur',
874 'Error, revision-deleted content' => [
876 'fromrev' => '{{REPL:revA2}}',
877 'torev' => '{{REPL:revB2}}',
882 'Error, text with no title and PST' => [
884 'fromtext' => 'From text',
885 'totext' => 'To text {{subst:PAGENAME}}',
891 'Error, test with invalid from section ID' => [
893 'fromtitle' => 'ApiComparePagesTest F',
895 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?",
901 'Error, test with invalid to section ID' => [
903 'fromtitle' => 'ApiComparePagesTest F',
905 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?",
911 'Error, Relative diff, no from revision' => [
914 'torelative' => 'cur',
918 'compare-relative-to-nothing'
920 'Error, Relative diff, cur with no current revision' => [
922 'fromrev' => '{{REPL:revE2}}',
923 'torelative' => 'cur',
929 'Error, Relative diff, next revdeleted' => [
931 'fromrev' => '{{REPL:revB1}}',
932 'torelative' => 'next',
938 'Error, Relative diff, prev revdeleted' => [
940 'fromrev' => '{{REPL:revB3}}',
941 'torelative' => 'prev',
947 'Error, section diff with no revision' => [
949 'fromtitle' => 'ApiComparePagesTest F',
951 'totext-main' => "== Section 1 ==\nTo text?",
952 'tosection-main' => 1,
955 'compare-notorevision',
957 'Error, section diff with revdeleted revision' => [
959 'fromtitle' => 'ApiComparePagesTest F',
960 'torev' => '{{REPL:revB2}}',
962 'totext-main' => "== Section 1 ==\nTo text?",
963 'tosection-main' => 1,
968 'Error, section diff with a content model not supporting sections' => [
970 'fromtitle' => 'ApiComparePagesTest G',
971 'torev' => '{{REPL:revG1}}',
973 'totext-main' => "== Section 1 ==\nTo text?",
974 'tosection-main' => 1,
977 'sectionsnotsupported',
979 'Error, section diff with bad content model' => [
981 'fromtitle' => 'ApiComparePagesTest F',
982 'torev' => '{{REPL:revF1}}',
984 'totext-main' => "== Section 1 ==\nTo text?",
985 'tosection-main' => 1,
986 'tocontentmodel-main' => CONTENT_MODEL_TEXT
,
989 'sectionreplacefailed',
991 'Error, deleting the main slot' => [
993 'fromtitle' => 'ApiComparePagesTest A',
994 'totitle' => 'ApiComparePagesTest A',
998 'compare-maintextrequired',
1000 // @todo Add a test for using 'tosection-foo' without 'totext-foo' (can't do it with main)