Make WordPress Core

Changeset 494 in tests


Ignore:
Timestamp:
01/05/2012 06:03:20 PM (13 years ago)
Author:
duck_
Message:

Add tests for CDATA sections containing the closing sequence "]]>". See #WP15203.

Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_import_wp.php

    r407 r494  
    142142                array( 'key' => '_wp_page_template', 'value' => 'default' )
    143143            ), $result['posts'][1]['postmeta'], $message );
     144        }
     145    }
     146
     147    /**
     148     * Test the WXR parser's ability to correctly retrieve content from CDATA
     149     * sections that contain escaped closing tags ("]]>" -> "]]]]><![CDATA[>").
     150     *
     151     * @link http://core.trac.wordpress.org/ticket/15203
     152     */
     153    function test_escaped_cdata_closing_sequence() {
     154        $file = DIR_TESTDATA . '/export/crazy-cdata-escaped.xml';
     155
     156        foreach( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
     157            $message = 'Parser ' . $p;
     158            $parser = new $p;
     159            $result = $parser->parse( $file );
     160
     161            $post = $result['posts'][0];
     162            $this->assertEquals( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'], $message );
     163            foreach ( $post['postmeta'] as $meta ) {
     164                switch ( $meta['key'] ) {
     165                    case 'Plain string': $value = 'Foo'; break;
     166                    case 'Closing CDATA': $value = ']]>'; break;
     167                    case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break;
     168                    default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
     169                }
     170                $this->assertEquals( $value, $meta['value'], $message );
     171            }
     172        }
     173    }
     174
     175    /**
     176     * Ensure that the regex parser can still parse invalid CDATA blocks (i.e. those
     177     * with "]]>" unescaped within a CDATA section).
     178     */
     179    function test_unescaped_cdata_closing_sequence() {
     180        $file = DIR_TESTDATA . '/export/crazy-cdata.xml';
     181
     182        $parser = new WXR_Parser_Regex;
     183        $result = $parser->parse( $file );
     184
     185        $post = $result['posts'][0];
     186        $this->assertEquals( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'], $message );
     187        foreach ( $post['postmeta'] as $meta ) {
     188            switch ( $meta['key'] ) {
     189                case 'Plain string': $value = 'Foo'; break;
     190                case 'Closing CDATA': $value = ']]>'; break;
     191                case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break;
     192                default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
     193            }
     194            $this->assertEquals( $value, $meta['value'], $message );
    144195        }
    145196    }
Note: See TracChangeset for help on using the changeset viewer.