Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/import/parser.php

    r41169 r42343  
    1010        parent::setUp();
    1111
    12         if ( ! defined( 'WP_IMPORTING' ) )
     12        if ( ! defined( 'WP_IMPORTING' ) ) {
    1313            define( 'WP_IMPORTING', true );
    14 
    15         if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
     14        }
     15
     16        if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
    1617            define( 'WP_LOAD_IMPORTERS', true );
     18        }
    1719
    1820        if ( ! file_exists( DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' ) ) {
     
    2931        foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) {
    3032            $parser = new $p;
    31             $result = $parser->parse($file);
     33            $result = $parser->parse( $file );
    3234            $this->assertWPError( $result );
    3335            $this->assertEquals( 'There was an error when reading this WXR file', $result->get_error_message() );
     
    5456        foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
    5557            $message = $p . ' failed';
    56             $parser = new $p;
    57             $result = $parser->parse( $file );
     58            $parser  = new $p;
     59            $result  = $parser->parse( $file );
    5860
    5961            $this->assertTrue( is_array( $result ), $message );
    6062            $this->assertEquals( 'http://localhost/', $result['base_url'], $message );
    61             $this->assertEquals( array(
    62                 'author_id' => 2,
    63                 'author_login' => 'john',
    64                 'author_email' => 'johndoe@example.org',
    65                 'author_display_name' => 'John Doe',
    66                 'author_first_name' => 'John',
    67                 'author_last_name' => 'Doe'
    68             ), $result['authors']['john'], $message );
    69             $this->assertEquals( array(
    70                 'term_id' => 3,
    71                 'category_nicename' => 'alpha',
    72                 'category_parent' => '',
    73                 'cat_name' => 'alpha',
    74                 'category_description' => 'The alpha category'
    75             ), $result['categories'][0], $message );
    76             $this->assertEquals( array(
    77                 'term_id' => 22,
    78                 'tag_slug' => 'clippable',
    79                 'tag_name' => 'Clippable',
    80                 'tag_description' => 'The Clippable post_tag'
    81             ), $result['tags'][0], $message );
    82             $this->assertEquals( array(
    83                 'term_id' => 40,
    84                 'term_taxonomy' => 'post_tax',
    85                 'slug' => 'bieup',
    86                 'term_parent' => '',
    87                 'term_name' => 'bieup',
    88                 'term_description' => 'The bieup post_tax'
    89             ), $result['terms'][0], $message );
    90 
    91             $this->assertEquals( 2, count($result['posts']), $message );
    92             $this->assertEquals( 19, count($result['posts'][0]), $message );
    93             $this->assertEquals( 18, count($result['posts'][1]), $message );
    94             $this->assertEquals( array(
    95                 array( 'name' => 'alpha', 'slug' => 'alpha', 'domain' => 'category' ),
    96                 array( 'name' => 'Clippable', 'slug' => 'clippable', 'domain' => 'post_tag' ),
    97                 array( 'name' => 'bieup', 'slug' => 'bieup', 'domain' => 'post_tax' )
    98             ), $result['posts'][0]['terms'], $message );
    99             $this->assertEquals( array(
    100                 array( 'key' => '_wp_page_template', 'value' => 'default' )
    101             ), $result['posts'][1]['postmeta'], $message );
     63            $this->assertEquals(
     64                array(
     65                    'author_id'           => 2,
     66                    'author_login'        => 'john',
     67                    'author_email'        => 'johndoe@example.org',
     68                    'author_display_name' => 'John Doe',
     69                    'author_first_name'   => 'John',
     70                    'author_last_name'    => 'Doe',
     71                ), $result['authors']['john'], $message
     72            );
     73            $this->assertEquals(
     74                array(
     75                    'term_id'              => 3,
     76                    'category_nicename'    => 'alpha',
     77                    'category_parent'      => '',
     78                    'cat_name'             => 'alpha',
     79                    'category_description' => 'The alpha category',
     80                ), $result['categories'][0], $message
     81            );
     82            $this->assertEquals(
     83                array(
     84                    'term_id'         => 22,
     85                    'tag_slug'        => 'clippable',
     86                    'tag_name'        => 'Clippable',
     87                    'tag_description' => 'The Clippable post_tag',
     88                ), $result['tags'][0], $message
     89            );
     90            $this->assertEquals(
     91                array(
     92                    'term_id'          => 40,
     93                    'term_taxonomy'    => 'post_tax',
     94                    'slug'             => 'bieup',
     95                    'term_parent'      => '',
     96                    'term_name'        => 'bieup',
     97                    'term_description' => 'The bieup post_tax',
     98                ), $result['terms'][0], $message
     99            );
     100
     101            $this->assertEquals( 2, count( $result['posts'] ), $message );
     102            $this->assertEquals( 19, count( $result['posts'][0] ), $message );
     103            $this->assertEquals( 18, count( $result['posts'][1] ), $message );
     104            $this->assertEquals(
     105                array(
     106                    array(
     107                        'name'   => 'alpha',
     108                        'slug'   => 'alpha',
     109                        'domain' => 'category',
     110                    ),
     111                    array(
     112                        'name'   => 'Clippable',
     113                        'slug'   => 'clippable',
     114                        'domain' => 'post_tag',
     115                    ),
     116                    array(
     117                        'name'   => 'bieup',
     118                        'slug'   => 'bieup',
     119                        'domain' => 'post_tax',
     120                    ),
     121                ), $result['posts'][0]['terms'], $message
     122            );
     123            $this->assertEquals(
     124                array(
     125                    array(
     126                        'key'   => '_wp_page_template',
     127                        'value' => 'default',
     128                    ),
     129                ), $result['posts'][1]['postmeta'], $message
     130            );
    102131        }
    103132    }
     
    108137        foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
    109138            $message = $p . ' failed';
    110             $parser = new $p;
    111             $result = $parser->parse( $file );
     139            $parser  = new $p;
     140            $result  = $parser->parse( $file );
    112141
    113142            $this->assertTrue( is_array( $result ), $message );
     
    120149            $this->assertEquals( $result['tags'][0]['tag_name'], 'chicken', $message );
    121150
    122             $this->assertEquals( 6, count($result['posts']), $message );
    123             $this->assertEquals( 19, count($result['posts'][0]), $message );
    124             $this->assertEquals( 18, count($result['posts'][1]), $message );
    125 
    126             $this->assertEquals( array(
    127                 array( 'name' => 'Uncategorized', 'slug' => 'uncategorized', 'domain' => 'category' )
    128             ), $result['posts'][0]['terms'], $message );
    129             $this->assertEquals( array(
    130                 array( 'name' => 'alpha', 'slug' => 'alpha', 'domain' => 'category' ),
    131                 array( 'name' => 'news', 'slug' => 'news', 'domain' => 'tag' ),
    132                 array( 'name' => 'roar', 'slug' => 'roar', 'domain' => 'tag' )
    133             ), $result['posts'][2]['terms'], $message );
    134             $this->assertEquals( array(
    135                 array( 'name' => 'chicken', 'slug' => 'chicken', 'domain' => 'tag' ),
    136                 array( 'name' => 'child', 'slug' => 'child', 'domain' => 'category' ),
    137                 array( 'name' => 'face', 'slug' => 'face', 'domain' => 'tag' )
    138             ), $result['posts'][3]['terms'], $message );
    139 
    140             $this->assertEquals( array(
    141                 array( 'key' => '_wp_page_template', 'value' => 'default' )
    142             ), $result['posts'][1]['postmeta'], $message );
     151            $this->assertEquals( 6, count( $result['posts'] ), $message );
     152            $this->assertEquals( 19, count( $result['posts'][0] ), $message );
     153            $this->assertEquals( 18, count( $result['posts'][1] ), $message );
     154
     155            $this->assertEquals(
     156                array(
     157                    array(
     158                        'name'   => 'Uncategorized',
     159                        'slug'   => 'uncategorized',
     160                        'domain' => 'category',
     161                    ),
     162                ), $result['posts'][0]['terms'], $message
     163            );
     164            $this->assertEquals(
     165                array(
     166                    array(
     167                        'name'   => 'alpha',
     168                        'slug'   => 'alpha',
     169                        'domain' => 'category',
     170                    ),
     171                    array(
     172                        'name'   => 'news',
     173                        'slug'   => 'news',
     174                        'domain' => 'tag',
     175                    ),
     176                    array(
     177                        'name'   => 'roar',
     178                        'slug'   => 'roar',
     179                        'domain' => 'tag',
     180                    ),
     181                ), $result['posts'][2]['terms'], $message
     182            );
     183            $this->assertEquals(
     184                array(
     185                    array(
     186                        'name'   => 'chicken',
     187                        'slug'   => 'chicken',
     188                        'domain' => 'tag',
     189                    ),
     190                    array(
     191                        'name'   => 'child',
     192                        'slug'   => 'child',
     193                        'domain' => 'category',
     194                    ),
     195                    array(
     196                        'name'   => 'face',
     197                        'slug'   => 'face',
     198                        'domain' => 'tag',
     199                    ),
     200                ), $result['posts'][3]['terms'], $message
     201            );
     202
     203            $this->assertEquals(
     204                array(
     205                    array(
     206                        'key'   => '_wp_page_template',
     207                        'value' => 'default',
     208                    ),
     209                ), $result['posts'][1]['postmeta'], $message
     210            );
    143211        }
    144212    }
     
    153221        $file = DIR_TESTDATA . '/export/crazy-cdata-escaped.xml';
    154222
    155         foreach( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
     223        foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
    156224            $message = 'Parser ' . $p;
    157             $parser = new $p;
    158             $result = $parser->parse( $file );
     225            $parser  = new $p;
     226            $result  = $parser->parse( $file );
    159227
    160228            $post = $result['posts'][0];
     
    162230            foreach ( $post['postmeta'] as $meta ) {
    163231                switch ( $meta['key'] ) {
    164                     case 'Plain string': $value = 'Foo'; break;
    165                     case 'Closing CDATA': $value = ']]>'; break;
    166                     case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break;
    167                     default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
     232                    case 'Plain string':
     233                        $value = 'Foo';
     234                        break;
     235                    case 'Closing CDATA':
     236                        $value = ']]>';
     237                        break;
     238                    case 'Alot of CDATA':
     239                        $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>';
     240                        break;
     241                    default:
     242                        $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
    168243                }
    169244                $this->assertEquals( $value, $meta['value'], $message );
     
    186261        foreach ( $post['postmeta'] as $meta ) {
    187262            switch ( $meta['key'] ) {
    188                 case 'Plain string': $value = 'Foo'; break;
    189                 case 'Closing CDATA': $value = ']]>'; break;
    190                 case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break;
    191                 default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
     263                case 'Plain string':
     264                    $value = 'Foo';
     265                    break;
     266                case 'Closing CDATA':
     267                    $value = ']]>';
     268                    break;
     269                case 'Alot of CDATA':
     270                    $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>';
     271                    break;
     272                default:
     273                    $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
    192274            }
    193275            $this->assertEquals( $value, $meta['value'] );
Note: See TracChangeset for help on using the changeset viewer.