X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiComparePagesTest.php;h=04283357c68e9e16a98336040605fbfc81f7cc12;hb=dd59b8d4fcd1d03f4d73b08f3f1e5f9a9da6f74e;hp=155a08ed06117088437a2583589809ad5d0f9131;hpb=67a299b06ceda2128f06a5d3c2ba9a87c96b577b;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiComparePagesTest.php b/tests/phpunit/includes/api/ApiComparePagesTest.php index 155a08ed06..04283357c6 100644 --- a/tests/phpunit/includes/api/ApiComparePagesTest.php +++ b/tests/phpunit/includes/api/ApiComparePagesTest.php @@ -70,6 +70,9 @@ 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(); + WikiPage::factory( Title::newFromText( 'ApiComparePagesTest C' ) ) ->doDeleteArticleReal( 'Test for ApiComparePagesTest' ); @@ -110,7 +113,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 ) ) { @@ -372,6 +375,26 @@ class ApiComparePagesTest extends ApiTestCase { ], false, true ], + 'Basic diff, test with sections' => [ + [ + 'fromtitle' => 'ApiComparePagesTest F', + 'fromsection' => 1, + 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?", + 'tosection' => 2, + ], + [ + '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', + ] + ], + ], 'Diff with all props' => [ [ 'fromrev' => '{{REPL:revB1}}', @@ -568,6 +591,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',