X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiComparePagesTest.php;h=155a08ed06117088437a2583589809ad5d0f9131;hb=3d2ed18dded19ad165f45f53905494d04904bebe;hp=989d6bb53655bdb1c57693cc8512a5f4af8eb995;hpb=b95ca29602793f39191c06cd6941e3f32ab1bbb8;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiComparePagesTest.php b/tests/phpunit/includes/api/ApiComparePagesTest.php index 989d6bb536..30e1d0c618 100644 --- a/tests/phpunit/includes/api/ApiComparePagesTest.php +++ b/tests/phpunit/includes/api/ApiComparePagesTest.php @@ -29,7 +29,7 @@ class ApiComparePagesTest extends ApiTestCase { $status = $page->doEditContent( $content, 'Test for ApiComparePagesTest: ' . $text, 0, false, $user ); - if ( !$status->isOk() ) { + if ( !$status->isOK() ) { $this->fail( "Failed to create $title: " . $status->getWikiText( false, false, 'en' ) ); } return $status->value['revision']->getId(); @@ -70,6 +70,12 @@ class ApiComparePagesTest extends ApiTestCase { 'page', [ 'page_latest' => 0 ], [ 'page_id' => self::$repl['pageE'] ] ); + self::$repl['revF1'] = $this->addPage( 'F', "== Section 1 ==\nF 1.1\n\n== Section 2 ==\nF 1.2" ); + self::$repl['pageF'] = Title::newFromText( 'ApiComparePagesTest F' )->getArticleId(); + + self::$repl['revG1'] = $this->addPage( 'G', "== Section 1 ==\nG 1.1", CONTENT_MODEL_TEXT ); + self::$repl['pageG'] = Title::newFromText( 'ApiComparePagesTest G' )->getArticleId(); + WikiPage::factory( Title::newFromText( 'ApiComparePagesTest C' ) ) ->doDeleteArticleReal( 'Test for ApiComparePagesTest' ); @@ -110,7 +116,7 @@ class ApiComparePagesTest extends ApiTestCase { $value = self::$repl[$m[1]]; } else { $value = preg_replace_callback( '/{{REPL:(.+?)}}/', function ( $m ) { - return isset( self::$repl[$m[1]] ) ? self::$repl[$m[1]] : $m[0]; + return self::$repl[$m[1]] ?? $m[0]; }, $value ); } } elseif ( is_array( $value ) || is_object( $value ) ) { @@ -129,6 +135,7 @@ class ApiComparePagesTest extends ApiTestCase { $params += [ 'action' => 'compare', + 'errorformat' => 'none', ]; $user = $sysop @@ -150,9 +157,28 @@ class ApiComparePagesTest extends ApiTestCase { } } + private static function makeDeprecationWarnings( ...$params ) { + $warn = []; + foreach ( $params as $p ) { + $warn[] = [ + 'code' => 'deprecation', + 'data' => [ 'feature' => "action=compare&{$p}" ], + 'module' => 'compare', + ]; + if ( count( $warn ) === 1 ) { + $warn[] = [ + 'code' => 'deprecation-help', + 'module' => 'main', + ]; + } + } + + return $warn; + } + public static function provideDiff() { + // phpcs:disable Generic.Files.LineLength.TooLong return [ - // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong 'Basic diff, titles' => [ [ 'fromtitle' => 'ApiComparePagesTest A', @@ -266,10 +292,12 @@ class ApiComparePagesTest extends ApiTestCase { ], 'Basic diff, text' => [ [ - 'fromtext' => 'From text', - 'fromcontentmodel' => 'wikitext', - 'totext' => 'To text {{subst:PAGENAME}}', - 'tocontentmodel' => 'wikitext', + 'fromslots' => 'main', + 'fromtext-main' => 'From text', + 'fromcontentmodel-main' => 'wikitext', + 'toslots' => 'main', + 'totext-main' => 'To text {{subst:PAGENAME}}', + 'tocontentmodel-main' => 'wikitext', ], [ 'compare' => [ @@ -281,9 +309,11 @@ class ApiComparePagesTest extends ApiTestCase { ], 'Basic diff, text 2' => [ [ - 'fromtext' => 'From text', - 'totext' => 'To text {{subst:PAGENAME}}', - 'tocontentmodel' => 'wikitext', + 'fromslots' => 'main', + 'fromtext-main' => 'From text', + 'toslots' => 'main', + 'totext-main' => 'To text {{subst:PAGENAME}}', + 'tocontentmodel-main' => 'wikitext', ], [ 'compare' => [ @@ -295,15 +325,13 @@ class ApiComparePagesTest extends ApiTestCase { ], 'Basic diff, guessed model' => [ [ - 'fromtext' => 'From text', - 'totext' => 'To text', + 'fromslots' => 'main', + 'fromtext-main' => 'From text', + 'toslots' => 'main', + 'totext-main' => 'To text', ], [ - 'warnings' => [ - 'compare' => [ - 'warnings' => 'No content model could be determined, assuming wikitext.', - ], - ], + 'warnings' => [ [ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ] ], 'compare' => [ 'body' => 'Line 1:' . "\n" . 'Line 1:' . "\n" @@ -313,9 +341,11 @@ class ApiComparePagesTest extends ApiTestCase { ], 'Basic diff, text with title and PST' => [ [ - 'fromtext' => 'From text', + 'fromslots' => 'main', + 'fromtext-main' => 'From text', 'totitle' => 'Test', - 'totext' => 'To text {{subst:PAGENAME}}', + 'toslots' => 'main', + 'totext-main' => 'To text {{subst:PAGENAME}}', 'topst' => true, ], [ @@ -328,9 +358,11 @@ class ApiComparePagesTest extends ApiTestCase { ], 'Basic diff, text with page ID and PST' => [ [ - 'fromtext' => 'From text', + 'fromslots' => 'main', + 'fromtext-main' => 'From text', 'toid' => '{{REPL:pageB}}', - 'totext' => 'To text {{subst:PAGENAME}}', + 'toslots' => 'main', + 'totext-main' => 'To text {{subst:PAGENAME}}', 'topst' => true, ], [ @@ -343,9 +375,11 @@ class ApiComparePagesTest extends ApiTestCase { ], 'Basic diff, text with revision and PST' => [ [ - 'fromtext' => 'From text', + 'fromslots' => 'main', + 'fromtext-main' => 'From text', 'torev' => '{{REPL:revB2}}', - 'totext' => 'To text {{subst:PAGENAME}}', + 'toslots' => 'main', + 'totext-main' => 'To text {{subst:PAGENAME}}', 'topst' => true, ], [ @@ -358,9 +392,11 @@ class ApiComparePagesTest extends ApiTestCase { ], 'Basic diff, text with deleted revision and PST' => [ [ - 'fromtext' => 'From text', + 'fromslots' => 'main', + 'fromtext-main' => 'From text', 'torev' => '{{REPL:revC2}}', - 'totext' => 'To text {{subst:PAGENAME}}', + 'toslots' => 'main', + 'totext-main' => 'To text {{subst:PAGENAME}}', 'topst' => true, ], [ @@ -372,6 +408,29 @@ class ApiComparePagesTest extends ApiTestCase { ], false, true ], + 'Basic diff, test with sections' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'fromslots' => 'main', + 'fromtext-main' => "== Section 2 ==\nFrom text?", + 'fromsection-main' => 2, + 'totitle' => 'ApiComparePagesTest F', + 'toslots' => 'main', + 'totext-main' => "== Section 1 ==\nTo text?", + 'tosection-main' => 1, + ], + [ + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . ' 
== Section 1 ==
 
== Section 1 ==
' . "\n" + . '−
F 1.1
+
To text?
' . "\n" + . '  ' . "\n" + . ' 
== Section 2 ==
 
== Section 2 ==
' . "\n" + . '−
From text?
+
F 1.2
' . "\n", + ] + ], + ], 'Diff with all props' => [ [ 'fromrev' => '{{REPL:revB1}}', @@ -494,6 +553,197 @@ class ApiComparePagesTest extends ApiTestCase { ] ], ], + 'Diff for specific slots' => [ + // @todo Use a page with multiple slots here + [ + 'fromrev' => '{{REPL:revA1}}', + 'torev' => '{{REPL:revA3}}', + 'prop' => 'diff', + 'slots' => 'main', + ], + [ + 'compare' => [ + 'bodies' => [ + 'main' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
A 1
+
A 3
' . "\n", + ], + ], + ], + ], + // @todo Add a test for diffing with a deleted slot. Deleting 'main' doesn't work. + + 'Basic diff, deprecated text' => [ + [ + 'fromtext' => 'From text', + 'fromcontentmodel' => 'wikitext', + 'totext' => 'To text {{subst:PAGENAME}}', + 'tocontentmodel' => 'wikitext', + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'fromcontentmodel', 'totext', 'tocontentmodel' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
From text
+
To text {{subst:PAGENAME}}
' . "\n", + ] + ], + ], + 'Basic diff, deprecated text 2' => [ + [ + 'fromtext' => 'From text', + 'totext' => 'To text {{subst:PAGENAME}}', + 'tocontentmodel' => 'wikitext', + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext', 'tocontentmodel' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
From text
+
To text {{subst:PAGENAME}}
' . "\n", + ] + ], + ], + 'Basic diff, deprecated text, guessed model' => [ + [ + 'fromtext' => 'From text', + 'totext' => 'To text', + ], + [ + 'warnings' => array_merge( self::makeDeprecationWarnings( 'fromtext', 'totext' ), [ + [ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ], + ] ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
From text
+
To text
' . "\n", + ] + ], + ], + 'Basic diff, deprecated text with title and PST' => [ + [ + 'fromtext' => 'From text', + 'totitle' => 'Test', + 'totext' => 'To text {{subst:PAGENAME}}', + 'topst' => true, + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
From text
+
To text Test
' . "\n", + ] + ], + ], + 'Basic diff, deprecated text with page ID and PST' => [ + [ + 'fromtext' => 'From text', + 'toid' => '{{REPL:pageB}}', + 'totext' => 'To text {{subst:PAGENAME}}', + 'topst' => true, + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
From text
+
To text ApiComparePagesTest B
' . "\n", + ] + ], + ], + 'Basic diff, deprecated text with revision and PST' => [ + [ + 'fromtext' => 'From text', + 'torev' => '{{REPL:revB2}}', + 'totext' => 'To text {{subst:PAGENAME}}', + 'topst' => true, + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
From text
+
To text ApiComparePagesTest B
' . "\n", + ] + ], + ], + 'Basic diff, deprecated text with deleted revision and PST' => [ + [ + 'fromtext' => 'From text', + 'torev' => '{{REPL:revC2}}', + 'totext' => 'To text {{subst:PAGENAME}}', + 'topst' => true, + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
From text
+
To text ApiComparePagesTest C
' . "\n", + ] + ], + false, true + ], + 'Basic diff, test with deprecated sections' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'fromsection' => 1, + 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?", + 'tosection' => 2, + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromsection', 'totext', 'tosection' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
== Section 1 ==
+
== Section 2 ==
' . "\n" + . '−
F 1.1
+
To text?
' . "\n", + 'fromid' => '{{REPL:pageF}}', + 'fromrevid' => '{{REPL:revF1}}', + 'fromns' => '0', + 'fromtitle' => 'ApiComparePagesTest F', + ] + ], + ], + 'Basic diff, test with deprecated sections and revdel, non-sysop' => [ + [ + 'fromrev' => '{{REPL:revB2}}', + 'fromsection' => 0, + 'torev' => '{{REPL:revB4}}', + 'tosection' => 0, + ], + [], + 'missingcontent' + ], + 'Basic diff, test with deprecated sections and revdel, sysop' => [ + [ + 'fromrev' => '{{REPL:revB2}}', + 'fromsection' => 0, + 'torev' => '{{REPL:revB4}}', + 'tosection' => 0, + ], + [ + 'warnings' => self::makeDeprecationWarnings( 'fromsection', 'tosection' ), + 'compare' => [ + 'body' => 'Line 1:' . "\n" + . 'Line 1:' . "\n" + . '−
B 2
+
B 4
' . "\n", + 'fromid' => '{{REPL:pageB}}', + 'fromrevid' => '{{REPL:revB2}}', + 'fromns' => 0, + 'fromtitle' => 'ApiComparePagesTest B', + 'fromtexthidden' => true, + 'fromuserhidden' => true, + 'fromcommenthidden' => true, + 'toid' => '{{REPL:pageB}}', + 'torevid' => '{{REPL:revB4}}', + 'tons' => 0, + 'totitle' => 'ApiComparePagesTest B', + ] + ], + false, true, + ], 'Error, missing title' => [ [ @@ -568,6 +818,26 @@ class ApiComparePagesTest extends ApiTestCase { [], 'compare-no-title', ], + 'Error, test with invalid from section ID' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'fromsection' => 5, + 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?", + 'tosection' => 2, + ], + [], + 'nosuchfromsection', + ], + 'Error, test with invalid to section ID' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'fromsection' => 1, + 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?", + 'tosection' => 5, + ], + [], + 'nosuchtosection', + ], 'Error, Relative diff, no from revision' => [ [ 'fromtext' => 'Foo', @@ -604,8 +874,69 @@ class ApiComparePagesTest extends ApiTestCase { [], 'missingcontent' ], - - // @codingStandardsIgnoreEnd + 'Error, Relative diff, no prev' => [ + [ + 'fromrev' => '{{REPL:revA1}}', + 'torelative' => 'prev', + 'prop' => 'ids', + ], + [], + 'baddiff' + ], + 'Error, Relative diff, no next' => [ + [ + 'fromrev' => '{{REPL:revA4}}', + 'torelative' => 'next', + 'prop' => 'ids', + ], + [], + 'baddiff' + ], + 'Error, section diff with no revision' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'toslots' => 'main', + 'totext-main' => "== Section 1 ==\nTo text?", + 'tosection-main' => 1, + ], + [], + 'compare-notorevision', + ], + 'Error, section diff with revdeleted revision' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'torev' => '{{REPL:revB2}}', + 'toslots' => 'main', + 'totext-main' => "== Section 1 ==\nTo text?", + 'tosection-main' => 1, + ], + [], + 'missingcontent', + ], + 'Error, section diff with a content model not supporting sections' => [ + [ + 'fromtitle' => 'ApiComparePagesTest G', + 'torev' => '{{REPL:revG1}}', + 'toslots' => 'main', + 'totext-main' => "== Section 1 ==\nTo text?", + 'tosection-main' => 1, + ], + [], + 'sectionsnotsupported', + ], + 'Error, section diff with bad content model' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'torev' => '{{REPL:revF1}}', + 'toslots' => 'main', + 'totext-main' => "== Section 1 ==\nTo text?", + 'tosection-main' => 1, + 'tocontentmodel-main' => CONTENT_MODEL_TEXT, + ], + [], + 'sectionreplacefailed', + ], ]; + // phpcs:enable } }