Merge "clientpool: refactor Redis authentication error handling"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiComparePagesTest.php
index 9399ef8..0428335 100644 (file)
@@ -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 ) ) {
@@ -151,8 +154,8 @@ class ApiComparePagesTest extends ApiTestCase {
        }
 
        public static function provideDiff() {
+               // phpcs:disable Generic.Files.LineLength.TooLong
                return [
-                       // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
                        'Basic diff, titles' => [
                                [
                                        'fromtitle' => 'ApiComparePagesTest A',
@@ -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' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
+                                                       . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
+                                                       . '<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"
+                                                       . '<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",
+                                               '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',
@@ -604,8 +647,7 @@ class ApiComparePagesTest extends ApiTestCase {
                                [],
                                'missingcontent'
                        ],
-
-                       // @codingStandardsIgnoreEnd
                ];
+               // phpcs:enable
        }
 }