Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/admin/includesTheme.php

    r41975 r42343  
    99        $this->theme_root = DIR_TESTDATA . '/themedir1';
    1010
    11         $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
     11        $this->orig_theme_dir            = $GLOBALS['wp_theme_directories'];
    1212        $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
    1313
    14         add_filter('theme_root', array($this, '_theme_root'));
    15         add_filter( 'stylesheet_root', array($this, '_theme_root') );
    16         add_filter( 'template_root', array($this, '_theme_root') );
     14        add_filter( 'theme_root', array( $this, '_theme_root' ) );
     15        add_filter( 'stylesheet_root', array( $this, '_theme_root' ) );
     16        add_filter( 'template_root', array( $this, '_theme_root' ) );
    1717
    1818        // clear caches
     
    2323    function tearDown() {
    2424        $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
    25         remove_filter('theme_root', array($this, '_theme_root'));
    26         remove_filter( 'stylesheet_root', array($this, '_theme_root') );
    27         remove_filter( 'template_root', array($this, '_theme_root') );
     25        remove_filter( 'theme_root', array( $this, '_theme_root' ) );
     26        remove_filter( 'stylesheet_root', array( $this, '_theme_root' ) );
     27        remove_filter( 'template_root', array( $this, '_theme_root' ) );
    2828
    2929        wp_clean_themes_cache();
     
    3333
    3434    // replace the normal theme root dir with our premade test dir
    35     function _theme_root($dir) {
     35    function _theme_root( $dir ) {
    3636        return $this->theme_root;
    3737    }
     
    4949        switch_theme( $theme['Template'], $theme['Stylesheet'] );
    5050
    51         $this->assertEqualSetsWithIndex( array(
    52             'Top Level'                           => 'template-top-level.php',
    53             'Sub Dir'                             => 'subdir/template-sub-dir.php',
    54             'This Template Header Is On One Line' => 'template-header.php',
    55         ), get_page_templates() );
     51        $this->assertEqualSetsWithIndex(
     52            array(
     53                'Top Level'                           => 'template-top-level.php',
     54                'Sub Dir'                             => 'subdir/template-sub-dir.php',
     55                'This Template Header Is On One Line' => 'template-header.php',
     56            ), get_page_templates()
     57        );
    5658
    5759        $theme = wp_get_theme( 'page-templates' );
     
    6062        switch_theme( $theme['Template'], $theme['Stylesheet'] );
    6163
    62         $this->assertEqualSetsWithIndex( array(
    63             'Top Level'                           => 'template-top-level.php',
    64             'Sub Dir'                             => 'subdir/template-sub-dir.php',
    65             'This Template Header Is On One Line' => 'template-header.php',
    66         ), get_page_templates() );
     64        $this->assertEqualSetsWithIndex(
     65            array(
     66                'Top Level'                           => 'template-top-level.php',
     67                'Sub Dir'                             => 'subdir/template-sub-dir.php',
     68                'This Template Header Is On One Line' => 'template-header.php',
     69            ), get_page_templates()
     70        );
    6771    }
    6872
     
    7680        switch_theme( $theme['Template'], $theme['Stylesheet'] );
    7781
    78         $this->assertEqualSetsWithIndex( array(
    79             'Top Level' => 'template-top-level-post-types.php',
    80             'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
    81         ), get_page_templates( null, 'foo' ) );
    82         $this->assertEqualSetsWithIndex( array(
    83             'Top Level' => 'template-top-level-post-types.php',
    84             'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
    85         ), get_page_templates( null, 'post' ) );
     82        $this->assertEqualSetsWithIndex(
     83            array(
     84                'Top Level' => 'template-top-level-post-types.php',
     85                'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
     86            ), get_page_templates( null, 'foo' )
     87        );
     88        $this->assertEqualSetsWithIndex(
     89            array(
     90                'Top Level' => 'template-top-level-post-types.php',
     91                'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
     92            ), get_page_templates( null, 'post' )
     93        );
    8694        $this->assertEquals( array(), get_page_templates( null, 'bar' ) );
    8795    }
     
    96104        switch_theme( $theme['Template'], $theme['Stylesheet'] );
    97105
    98         $this->assertEqualSetsWithIndex( array(
    99             'No Trailing Period' => '38766/no-trailing-period-post-types.php',
    100             'Trailing Period.' => '38766/trailing-period-post-types.php',
    101             'Trailing Comma,' => '38766/trailing-comma-post-types.php',
    102             'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
    103             'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
    104             'Tilde in Post Type.' => '38766/tilde-post-types.php',
    105         ), get_page_templates( null, 'period' ) );
    106         $this->assertEqualSetsWithIndex( array(
    107             'No Trailing Period' => '38766/no-trailing-period-post-types.php',
    108             'Trailing Period.' => '38766/trailing-period-post-types.php',
    109             'Trailing Comma,' => '38766/trailing-comma-post-types.php',
    110             'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
    111             'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
    112         ), get_page_templates( null, 'full-stop' ) );
     106        $this->assertEqualSetsWithIndex(
     107            array(
     108                'No Trailing Period'            => '38766/no-trailing-period-post-types.php',
     109                'Trailing Period.'              => '38766/trailing-period-post-types.php',
     110                'Trailing Comma,'               => '38766/trailing-comma-post-types.php',
     111                'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
     112                'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
     113                'Tilde in Post Type.'           => '38766/tilde-post-types.php',
     114            ), get_page_templates( null, 'period' )
     115        );
     116        $this->assertEqualSetsWithIndex(
     117            array(
     118                'No Trailing Period'            => '38766/no-trailing-period-post-types.php',
     119                'Trailing Period.'              => '38766/trailing-period-post-types.php',
     120                'Trailing Comma,'               => '38766/trailing-comma-post-types.php',
     121                'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
     122                'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
     123            ), get_page_templates( null, 'full-stop' )
     124        );
    113125    }
    114126
     
    122134        switch_theme( $theme['Template'], $theme['Stylesheet'] );
    123135
    124         $this->assertEqualSetsWithIndex( array(
    125             'Top Level'                  => 'template-top-level-post-types.php',
    126             'Sub Dir'                    => 'subdir/template-sub-dir-post-types.php',
    127             'Top Level In A Child Theme' => 'template-top-level-post-types-child.php',
    128             'Sub Dir In A Child Theme'   => 'subdir/template-sub-dir-post-types-child.php',
    129         ), get_page_templates( null, 'foo' ) );
    130 
    131         $this->assertEqualSetsWithIndex( array(
    132             'Top Level' => 'template-top-level-post-types.php',
    133             'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
    134         ), get_page_templates( null, 'post' ) );
    135 
    136         $this->assertEqualSetsWithIndex( array(
    137             'Top Level'                           => 'template-top-level.php',
    138             'Sub Dir'                             => 'subdir/template-sub-dir.php',
    139             'This Template Header Is On One Line' => 'template-header.php',
    140         ), get_page_templates() );
     136        $this->assertEqualSetsWithIndex(
     137            array(
     138                'Top Level'                  => 'template-top-level-post-types.php',
     139                'Sub Dir'                    => 'subdir/template-sub-dir-post-types.php',
     140                'Top Level In A Child Theme' => 'template-top-level-post-types-child.php',
     141                'Sub Dir In A Child Theme'   => 'subdir/template-sub-dir-post-types-child.php',
     142            ), get_page_templates( null, 'foo' )
     143        );
     144
     145        $this->assertEqualSetsWithIndex(
     146            array(
     147                'Top Level' => 'template-top-level-post-types.php',
     148                'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
     149            ), get_page_templates( null, 'post' )
     150        );
     151
     152        $this->assertEqualSetsWithIndex(
     153            array(
     154                'Top Level'                           => 'template-top-level.php',
     155                'Sub Dir'                             => 'subdir/template-sub-dir.php',
     156                'This Template Header Is On One Line' => 'template-header.php',
     157            ), get_page_templates()
     158        );
    141159
    142160        $this->assertEquals( array(), get_page_templates( null, 'bar' ) );
     
    154172        $post_templates = $theme->get_post_templates();
    155173
    156         $this->assertEqualSetsWithIndex( array(
    157             'template-top-level-post-types.php'            => 'Top Level',
    158             'subdir/template-sub-dir-post-types.php'       => 'Sub Dir',
    159             'template-top-level-post-types-child.php'      => 'Top Level In A Child Theme',
    160             'subdir/template-sub-dir-post-types-child.php' => 'Sub Dir In A Child Theme',
    161         ), $post_templates['foo'] );
    162 
    163         $this->assertEqualSetsWithIndex( array(
    164             'template-top-level-post-types.php'      => 'Top Level',
    165             'subdir/template-sub-dir-post-types.php' => 'Sub Dir',
    166         ), $post_templates['post'] );
    167 
    168         $this->assertEqualSetsWithIndex( array(
    169             'template-top-level.php'      => 'Top Level',
    170             'subdir/template-sub-dir.php' => 'Sub Dir',
    171             'template-header.php'         => 'This Template Header Is On One Line',
    172         ), $post_templates['page'] );
     174        $this->assertEqualSetsWithIndex(
     175            array(
     176                'template-top-level-post-types.php'       => 'Top Level',
     177                'subdir/template-sub-dir-post-types.php'  => 'Sub Dir',
     178                'template-top-level-post-types-child.php' => 'Top Level In A Child Theme',
     179                'subdir/template-sub-dir-post-types-child.php' => 'Sub Dir In A Child Theme',
     180            ), $post_templates['foo']
     181        );
     182
     183        $this->assertEqualSetsWithIndex(
     184            array(
     185                'template-top-level-post-types.php'      => 'Top Level',
     186                'subdir/template-sub-dir-post-types.php' => 'Sub Dir',
     187            ), $post_templates['post']
     188        );
     189
     190        $this->assertEqualSetsWithIndex(
     191            array(
     192                'template-top-level.php'      => 'Top Level',
     193                'subdir/template-sub-dir.php' => 'Sub Dir',
     194                'template-header.php'         => 'This Template Header Is On One Line',
     195            ), $post_templates['page']
     196        );
    173197    }
    174198
Note: See TracChangeset for help on using the changeset viewer.