WordPress.org

Make WordPress Core

Changeset 46612


Ignore:
Timestamp:
10/29/2019 02:26:41 PM (6 weeks ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Ignore EOL differences in tests using multiline string assertions.

Unix vs. Windows EOL style mismatches can cause misleading failures in tests using the heredoc syntax (<<<) or multiline strings as the expected result.

Fixes #31432. See #42594, #47411.

Location:
trunk/tests/phpunit
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r46586 r46612  
    634634    public function assertDiscardWhitespace( $expected, $actual ) {
    635635        $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) );
     636    }
     637
     638    /**
     639     * Asserts that two values are equal, with EOL differences discarded.
     640     *
     641     * @since 5.4.0
     642     *
     643     * @param string $expected The expected value.
     644     * @param string $actual   The actual value.
     645     */
     646    public function assertEqualsIgnoreEOL( $expected, $actual ) {
     647        $this->assertEquals( str_replace( "\r\n", "\n", $expected ), str_replace( "\r\n", "\n", $actual ) );
    636648    }
    637649
  • trunk/tests/phpunit/tests/blocks/render.php

    r46586 r46612  
    6161        $actual_html = do_blocks( $original_html );
    6262
    63         $this->assertEquals( $expected_html, $actual_html );
     63        $this->assertEqualsIgnoreEOL( $expected_html, $actual_html );
    6464    }
    6565
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r46586 r46612  
    847847        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
    848848
    849         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     849        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    850850    }
    851851
     
    872872        $expected .= "<script type='text/javascript' src='/wp-content/plugins/my-plugin/js/script.js'></script>\n";
    873873
    874         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     874        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    875875    }
    876876
     
    897897        $expected .= "<script type='text/javascript' src='/wp-content/themes/my-theme/js/script.js'></script>\n";
    898898
    899         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     899        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    900900    }
    901901
     
    922922        $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js'></script>\n";
    923923
    924         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     924        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    925925    }
    926926
     
    962962        $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js'></script>\n";
    963963
    964         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     964        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    965965    }
    966966
     
    989989        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
    990990
    991         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     991        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    992992    }
    993993
     
    10171017        $expected .= "<script type='text/javascript' src='/wp-includes/js/script2.js'></script>\n";
    10181018
    1019         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     1019        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    10201020    }
    10211021
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r46586 r46612  
    273273        wp_add_inline_style( 'handle', 'a { color: blue; }' );
    274274
    275         $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
     275        $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_styles' ) );
    276276    }
    277277
  • trunk/tests/phpunit/tests/formatting/Autop.php

    r46586 r46612  
    503503line 5</p>';
    504504
    505         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     505        $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    506506    }
    507507
     
    522522<p>line 2</p>';
    523523
    524         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     524        $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    525525    }
    526526
     
    544544     * @ticket 39307
    545545     */
    546     function test_that_wpautop_doses_not_add_extra_closing_p_in_figure() {
     546    function test_that_wpautop_does_not_add_extra_closing_p_in_figure() {
    547547        $content1  = '<figure><img src="example.jpg" /><figcaption>Caption</figcaption></figure>';
    548548        $expected1 = $content1;
     
    557557
    558558        $this->assertEquals( $expected1, trim( wpautop( $content1 ) ) );
    559         $this->assertEquals( $expected2, trim( wpautop( $content2 ) ) );
     559        $this->assertEqualsIgnoreEOL( $expected2, trim( wpautop( $content2 ) ) );
    560560    }
    561561
     
    585585        $expected = '<p>' . $content . '</p>';
    586586
    587         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     587        $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    588588    }
    589589
     
    601601        $expected = '<p>' . $content . '</p>';
    602602
    603         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     603        $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    604604    }
    605605}
  • trunk/tests/phpunit/tests/formatting/EscUrl.php

    r46586 r46612  
    210210I thought you might want to sign up for this newsletter
    211211EOT;
     212        $body       = str_replace( "\r\n", "\n", $body );
    212213        $email_link = 'mailto:?body=' . rawurlencode( $body );
    213214        $email_link = esc_url( $email_link );
     
    224225I thought you might want to sign up for this newsletter
    225226EOT;
     227        $body       = str_replace( "\r\n", "\n", $body );
    226228        $email_link = 'http://example.com/mailto:?body=' . rawurlencode( $body );
    227229        $email_link = esc_url( $email_link );
  • trunk/tests/phpunit/tests/formatting/SanitizeTextField.php

    r46586 r46612  
    138138        }
    139139        $this->assertEquals( $expected_oneline, sanitize_text_field( $string ) );
    140         $this->assertEquals( $expected_multiline, sanitize_textarea_field( $string ) );
     140        $this->assertEqualsIgnoreEOL( $expected_multiline, sanitize_textarea_field( $string ) );
    141141
    142142    }
  • trunk/tests/phpunit/tests/functions/getArchives.php

    r46586 r46612  
    7272    <li><a href='$link5'>$title5</a></li>
    7373EOF;
    74         $this->assertEquals(
     74        $this->assertEqualsIgnoreEOL(
    7575            $expected['limit'],
    7676            trim(
     
    154154    <li><a href='{$this->month_url}'>$date_full</a></li>
    155155EOF;
    156         $this->assertEquals(
     156        $this->assertEqualsIgnoreEOL(
    157157            $expected['order_asc'],
    158158            trim(
     
    170170    <li><a href='{$oct_url}'>October 2012</a></li>
    171171EOF;
    172         $this->assertEquals(
     172        $this->assertEqualsIgnoreEOL(
    173173            $expected['order_desc'],
    174174            trim(
  • trunk/tests/phpunit/tests/general/paginateLinks.php

    r46586 r46612  
    2626
    2727        $links = paginate_links( array( 'total' => 50 ) );
    28         $this->assertEquals( $expected, $links );
     28        $this->assertEqualsIgnoreEOL( $expected, $links );
    2929    }
    3030
     
    4949            )
    5050        );
    51         $this->assertEquals( $expected, $links );
     51        $this->assertEqualsIgnoreEOL( $expected, $links );
    5252    }
    5353
     
    7474            )
    7575        );
    76         $this->assertEquals( $expected, $links );
     76        $this->assertEqualsIgnoreEOL( $expected, $links );
    7777    }
    7878
     
    101101            )
    102102        );
    103         $this->assertEquals( $expected, $links );
     103        $this->assertEqualsIgnoreEOL( $expected, $links );
    104104    }
    105105
  • trunk/tests/phpunit/tests/media.php

    r46586 r46612  
    12501250
    12511251        $result = apply_filters( 'the_content', $content );
    1252         $this->assertEquals( $expected, $result );
     1252        $this->assertEqualsIgnoreEOL( $expected, $result );
    12531253    }
    12541254
  • trunk/tests/phpunit/tests/pomo/po.php

    r46586 r46612  
    2323http://wordpress.org/
    2424';
     25        $this->mail    = str_replace( "\r\n", "\n", $this->mail );
    2526        $this->po_mail = '""
    2627"Your new WordPress blog has been successfully set up at:\n"
     
    6465        $this->assertEquals( '"Categories can be selectively converted to tags using the <a href=\\"%s\\">category to tag converter</a>."', $po->poify( $src ) );
    6566
    66         $this->assertEquals( $this->po_mail, $po->poify( $this->mail ) );
     67        $this->assertEqualsIgnoreEOL( $this->po_mail, $po->poify( $this->mail ) );
    6768    }
    6869
     
    7576        // wordwrapped
    7677        $this->assertEquals( 'babadyado', $po->unpoify( "\"\"\n\"baba\"\n\"dyado\"" ) );
    77         $this->assertEquals( $this->mail, $po->unpoify( $this->po_mail ) );
     78        $this->assertEqualsIgnoreEOL( $this->mail, $po->unpoify( $this->po_mail ) );
    7879    }
    7980
     
    8990            )
    9091        );
    91         $this->assertEquals(
     92        $this->assertEqualsIgnoreEOL(
    9293            'msgid "baba"
    9394msgid_plural "babas"
     
    102103            )
    103104        );
    104         $this->assertEquals(
     105        $this->assertEqualsIgnoreEOL(
    105106            '#  baba
    106107#  dyado
     
    115116            )
    116117        );
    117         $this->assertEquals(
     118        $this->assertEqualsIgnoreEOL(
    118119            '#. baba
    119120msgid "baba"
     
    128129            )
    129130        );
    130         $this->assertEquals(
     131        $this->assertEqualsIgnoreEOL(
    131132            '#. baba
    132133#: 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
     
    159160            )
    160161        );
    161         $this->assertEquals(
     162        $this->assertEqualsIgnoreEOL(
    162163            'msgid "baba"
    163164msgid_plural "babas"
     
    173174            )
    174175        );
    175         $this->assertEquals(
     176        $this->assertEqualsIgnoreEOL(
    176177            'msgid "baba"
    177178msgid_plural "babas"
     
    191192            )
    192193        );
    193         $this->assertEquals(
     194        $this->assertEqualsIgnoreEOL(
    194195            '#, fuzzy, php-format
    195196msgctxt "ctxt"
  • trunk/tests/phpunit/tests/post/listPages.php

    r46586 r46612  
    135135</ul></li>';
    136136
    137         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     137        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    138138    }
    139139
     
    149149</ul></li>';
    150150
    151         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     151        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    152152    }
    153153
     
    165165</ul></li>';
    166166
    167         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     167        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    168168    }
    169169
     
    199199</ul></li>';
    200200
    201         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     201        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    202202    }
    203203
     
    213213</ul></li>';
    214214
    215         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     215        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    216216    }
    217217
     
    241241</ul></li>';
    242242
    243         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     243        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    244244    }
    245245
     
    256256</ul></li>';
    257257
    258         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     258        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    259259    }
    260260
     
    269269<li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a></li>
    270270</ul></li>';
     271        $expected = str_replace( "\r\n", "\n", $expected );
    271272        $this->expectOutputString( $expected );
    272273        wp_list_pages( $args );
     
    282283</ul></li>';
    283284
    284         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     285        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    285286    }
    286287
     
    294295</ul></li>';
    295296
    296         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     297        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    297298    }
    298299
     
    327328</ul></li>';
    328329
    329         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     330        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    330331    }
    331332
     
    359360</ul></li>';
    360361
    361         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     362        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    362363    }
    363364
     
    391392</ul></li>';
    392393
    393         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     394        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    394395    }
    395396
     
    405406</ul></li>';
    406407
    407         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     408        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    408409    }
    409410
     
    423424</ul></li>';
    424425
    425         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     426        $this->assertEqualsIgnoreEOL( $expected, wp_list_pages( $args ) );
    426427    }
    427428
     
    434435        $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a><ul class=\'children\'><li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a></li><li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2</a></li><li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3</a></li></ul></li><li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a><ul class=\'children\'><li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1</a></li><li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2</a></li><li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3</a></li></ul></li><li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a><ul class=\'children\'><li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">Child 1</a></li><li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">Child 2</a></li><li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">Child 3</a></li></ul></li></ul></li>';
    435436
    436         $this->AssertEquals( $expected, wp_list_pages( $args ) );
     437        $this->assertEquals( $expected, wp_list_pages( $args ) );
    437438    }
    438439}
  • trunk/tests/phpunit/tests/post/template.php

    r46586 r46612  
    165165
    166166        $output = wp_dropdown_pages( array( 'echo' => 0 ) );
    167         $this->assertEquals( $lineage, $output );
     167        $this->assertEqualsIgnoreEOL( $lineage, $output );
    168168
    169169        $depth = <<<DEPTH
     
    180180            )
    181181        );
    182         $this->assertEquals( $depth, $output );
     182        $this->assertEqualsIgnoreEOL( $depth, $output );
    183183
    184184        $option_none = <<<NONE
     
    198198            )
    199199        );
    200         $this->assertEquals( $option_none, $output );
     200        $this->assertEqualsIgnoreEOL( $option_none, $output );
    201201
    202202        $option_no_change = <<<NO
     
    208208
    209209NO;
    210         $output           = wp_dropdown_pages(
     210
     211        $output = wp_dropdown_pages(
    211212            array(
    212213                'echo'                  => 0,
     
    217218            )
    218219        );
    219         $this->assertEquals( $option_no_change, $output );
     220        $this->assertEqualsIgnoreEOL( $option_no_change, $output );
    220221    }
    221222
Note: See TracChangeset for help on using the changeset viewer.