WordPress.org

Make WordPress Core

Ticket #18549: 18549_tests.diff

File 18549_tests.diff, 10.7 KB (added by gitlost, 6 years ago)

Unittests.

  • tests/phpunit/tests/formatting/WPTexturize.php

     
    8080         */
    8181        function test_quotes() {
    8282                $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"'));
    83                 //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"'));
    84                 //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link and a period</a>&#8221;.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".'));
     83                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"'));
     84                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link and a period</a>&#8221;.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".'));
    8585                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221; and a space.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>" and a space.'));
    8686                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a> and some text quoted&#8221;', wptexturize('Here is "<a href="http://example.com">a test with a link</a> and some text quoted"'));
    87                 //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.'));
    88                 //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.'));
    89                 //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.'));
    90                 //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;&#8230; and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.'));
    91                 //$this->assertEquals('Here is &#8220;a test <a href="http://example.com">with a link</a>&#8221;.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".'));
    92                 //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.'));
     87                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.'));
     88                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.'));
     89                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.'));
     90                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;&#8230; and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.'));
     91                $this->assertEquals('Here is &#8220;a test <a href="http://example.com">with a link</a>&#8221;.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".'));
     92                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.'));
    9393                $this->assertEquals('A test with a finishing number, &#8220;like 23&#8221;.', wptexturize('A test with a finishing number, "like 23".'));
    9494                $this->assertEquals('A test with a number, &#8220;like 62&#8221;, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.'));
    9595        }
     
    144144         */
    145145        function test_other_html() {
    146146                $this->assertEquals('&#8216;<strong>', wptexturize("'<strong>"));
    147                 //$this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',"));
    148                 //$this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",'));
     147                $this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',"));
     148                $this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",'));
    149149        }
    150150
    151151        function test_x() {
     
    14401440                        ),
    14411441                        array(
    14421442                                '[Let\'s get crazy<input>[caption code="<a href=\'?a[]=100\'>hello</a>"]</input>world]', // caption shortcode is invalid here because it contains [] chars.
    1443                                 '[Let&#8217;s get crazy<input>[caption code=&#8221;<a href=\'?a[]=100\'>hello</a>&#8220;]</input>world]',
     1443                                //'[Let&#8217;s get crazy<input>[caption code=&#8221;<a href=\'?a[]=100\'>hello</a>&#8220;]</input>world]', // Incompatibility... (was seeing "] which went to open quote)
     1444                                '[Let&#8217;s get crazy<input>[caption code=&#8221;<a href=\'?a[]=100\'>hello</a>&#8221;]</input>world]', // Now sees [caption code="hello"] which goes to 2 closing quotes.
    14441445                        ),
    14451446                        array(
    14461447                                '<> ... <>',
     
    17621763                                "word word', she said",
    17631764                                "word word!closeq1!, she said",
    17641765                        ),
     1766                        array(
     1767                                '\'<a href="#"><small>word</small></a> "<i>42.00</i>" <b>word</b> <big>\'42\'</big> <em>42"</em> <sup>\'2\'</sup><br>"<i>21</i>" <i><b>2</b>x</i>21 <abbr>w</abbr>ord 0.<small>5</small>x<span>8</span>4<strong> \'</strong>4<var>t2\'',
     1768                                '!openq1!<a href="#"><small>word</small></a> !openq2!<i>42.00</i>!closeq2! <b>word</b> <big>!apos!42!closeq1!</big> <em>42!prime2!</em> <sup>!openq1!2!closeq1!</sup><br>!openq2!<i>21</i>!closeq2! <i><b>2</b>&#215;</i>21 <abbr>w</abbr>ord 0.<small>5</small>&#215;<span>8</span>4<strong> !openq1!</strong>4<var>t2!closeq1!',
     1769                        ),
    17651770                );
    17661771        }
    17671772
     
    20482053                        ),
    20492054                );
    20502055        }
    2051 }
    2052  No newline at end of file
     2056
     2057        /**
     2058         * Test that double quotes and apostrophes close correctly in the presence of inline html tags.
     2059         *
     2060         * @ticket 18549
     2061         * @dataProvider data_inline_end_tags
     2062         */
     2063        function test_inline_end_tags( $input, $output ) {
     2064                return $this->assertEquals( $output, wptexturize( $input ) );
     2065        }
     2066
     2067        function data_inline_end_tags() {
     2068                return array(
     2069                        array(
     2070                                'The word is "<a href="http://example.com/">quoted</a>".',
     2071                                'The word is &#8220;<a href="http://example.com/">quoted</a>&#8221;.',
     2072                        ),
     2073                        array(
     2074                                'The word is \'<a href="http://example.com/">quoted</a>\'',
     2075                                'The word is &#8216;<a href="http://example.com/">quoted</a>&#8217;',
     2076                        ),
     2077                        array(
     2078                                'The word is \'<a href="http://example.com/">quoted.</a>\'',
     2079                                'The word is &#8216;<a href="http://example.com/">quoted.</a>&#8217;',
     2080                        ),
     2081                        array(
     2082                                'The word is \'<a href="http://example.com/">quoted</a>\'.',
     2083                                'The word is &#8216;<a href="http://example.com/">quoted</a>&#8217;.',
     2084                        ),
     2085                        array(
     2086                                'The word is not \'<a href="http://example.com/">quot</a>\'d',
     2087                                'The word is not &#8216;<a href="http://example.com/">quot</a>&#8217;d',
     2088                        ),
     2089                        array(
     2090                                '<em>John</em>\'s',
     2091                                '<em>John</em>&#8217;s',
     2092                        ),
     2093                        array(
     2094                                '\'<em>John</em>\'s\'',
     2095                                '&#8216;<em>John</em>&#8217;s&#8217;',
     2096                        ),
     2097                        array(
     2098                                '"<em>John</em>\'s"',
     2099                                '&#8220;<em>John</em>&#8217;s&#8221;',
     2100                        ),
     2101                        array(
     2102                                '<em>"John"</em>\'s',
     2103                                //'<em>&#8220;John&#8221;</em>&#8217;s', // Should be but...
     2104                                '<em>&#8220;John&#8221;</em>&#8216;s', // Wrong: the ' in the stripped "John"'s seen as an opening single quote.
     2105                        ),
     2106                        array(
     2107                                '<em>\'John\'</em>\'s',
     2108                                //'<em>&#8216;John&#8217;</em>&#8217;s', // Should be but...
     2109                                '<em>&#8216;John&#8221;</em>s', // Wrong: the '' in the stripped 'John''s seen as a closing double tick quote.
     2110                        ),
     2111                        array(
     2112                                '<strong>Read more: </strong>"<a href="http://blah.com/test">Something (else)</a>"</p>',
     2113                                '<strong>Read more: </strong>&#8220;<a href="http://blah.com/test">Something (else)</a>&#8221;</p>',
     2114                        ),
     2115
     2116                );
     2117        }
     2118
     2119        /**
     2120         * Test low-level wptexturize_replace_xxx routines.
     2121         * @ticket wptexturize_replace_xxx
     2122         */
     2123        function test_wptexturize_replace() {
     2124                $orig_str = '<a href="#">0<abbr>1</abbr></a>2<b>2</b>345<big>5</big>6<br>77<dfn></em>8<i><samp>9</samp>A<small>B</small>CDE<span></span>F<strong>G</sub>[H<sup>]<var>I</var>';
     2125
     2126                $str = $orig_str;
     2127                wptexturize_replace_init( $str, '/<[^>]*>|\[H[^\]]*\]/' );
     2128                $this->assertEquals( '0122345567789ABCDEFGI', $str );
     2129
     2130                wptexturize_replace_final( $str );
     2131                $this->assertEquals( $orig_str, $str );
     2132
     2133                wptexturize_replace_init( $str, '/<[^>]*>|\[H[^\]]*\]/' );
     2134                $this->assertEquals( '0122345567789ABCDEFGI', $str );
     2135
     2136                wptexturize_replace_str( $str, '5', 'EF' );
     2137                $this->assertEquals( '012234EFEF67789ABCDEFGI', $str );
     2138
     2139                wptexturize_replace_regex( $str, '/2/', '2BB2' );
     2140                $this->assertEquals( '012BB22BB234EFEF67789ABCDEFGI', $str );
     2141
     2142                wptexturize_replace_regex( $str, '/(3)4/', '$1FOUR' );
     2143                $this->assertEquals( '012BB22BB23FOUREFEF67789ABCDEFGI', $str );
     2144
     2145                wptexturize_replace_str( $str, '8', 'B' );
     2146                $this->assertEquals( '012BB22BB23FOUREFEF677B9ABCDEFGI', $str );
     2147
     2148                wptexturize_replace_regex( $str, '/7/', '7EFEN' );
     2149                $this->assertEquals( '012BB22BB23FOUREFEF67EFEN7EFENB9ABCDEFGI', $str );
     2150
     2151                wptexturize_replace_str( $str, '6', '666' );
     2152                $this->assertEquals( '012BB22BB23FOUREFEF6667EFEN7EFENB9ABCDEFGI', $str );
     2153
     2154                wptexturize_replace_str( $str, '1', '12' );
     2155                $this->assertEquals( '0122BB22BB23FOUREFEF6667EFEN7EFENB9ABCDEFGI', $str );
     2156
     2157                wptexturize_replace_str( $str, 'BC', 'BCBC' );
     2158                $this->assertEquals( '0122BB22BB23FOUREFEF6667EFEN7EFENB9ABCBCDEFGI', $str );
     2159
     2160                wptexturize_replace_regex( $str, '/3(FO)U/', 'THREE$1EWE' );
     2161                $this->assertEquals( '0122BB22BB2THREEFOEWEREFEF6667EFEN7EFENB9ABCBCDEFGI', $str );
     2162
     2163                wptexturize_replace_regex( $str, '/(E)F/', '$1' );
     2164                $this->assertEquals( '0122BB22BB2THREEOEWEREE6667EEN7EENB9ABCBCDEGI', $str );
     2165
     2166                wptexturize_replace_regex( $str, '/G/', '' );
     2167                $this->assertEquals( '0122BB22BB2THREEOEWEREE6667EEN7EENB9ABCBCDEI', $str );
     2168
     2169                wptexturize_replace_final( $str );
     2170                $this->assertEquals( '<a href="#">0<abbr>12</abbr></a>2BB2<b>2BB2</b>THREEOEWERE<big>E</big>666<br>7EEN7EEN<dfn></em>B<i><samp>9</samp>A<small>BCBC</small>DE<span></span><strong></sub>[H<sup>]<var>I</var>', $str );
     2171        }
     2172}