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/theme/themeDir.php

    r41610 r42343  
    1717        $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
    1818
    19         add_filter('theme_root', array($this, '_theme_root'));
    20         add_filter( 'stylesheet_root', array($this, '_theme_root') );
    21         add_filter( 'template_root', array($this, '_theme_root') );
     19        add_filter( 'theme_root', array( $this, '_theme_root' ) );
     20        add_filter( 'stylesheet_root', array( $this, '_theme_root' ) );
     21        add_filter( 'template_root', array( $this, '_theme_root' ) );
    2222        // clear caches
    2323        wp_clean_themes_cache();
     
    2727    function tearDown() {
    2828        $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
    29         remove_filter('theme_root', array($this, '_theme_root'));
    30         remove_filter( 'stylesheet_root', array($this, '_theme_root') );
    31         remove_filter( 'template_root', array($this, '_theme_root') );
     29        remove_filter( 'theme_root', array( $this, '_theme_root' ) );
     30        remove_filter( 'stylesheet_root', array( $this, '_theme_root' ) );
     31        remove_filter( 'template_root', array( $this, '_theme_root' ) );
    3232        wp_clean_themes_cache();
    3333        unset( $GLOBALS['wp_themes'] );
     
    3636
    3737    // replace the normal theme root dir with our premade test dir
    38     function _theme_root($dir) {
     38    function _theme_root( $dir ) {
    3939        return $this->theme_root;
    4040    }
     
    4646    function test_theme_default() {
    4747        $themes = get_themes();
    48         $theme = get_theme('WordPress Default');
     48        $theme  = get_theme( 'WordPress Default' );
    4949        $this->assertEquals( $themes['WordPress Default'], $theme );
    5050
    51         $this->assertFalse( empty($theme) );
     51        $this->assertFalse( empty( $theme ) );
    5252
    5353        #echo gen_tests_array('theme', $theme);
     
    6565        $this->assertContains( $this->theme_root . '/default/style.css', $theme['Stylesheet Files'] );
    6666
    67         $this->assertEquals( $this->theme_root.'/default', $theme['Template Dir'] );
    68         $this->assertEquals( $this->theme_root.'/default', $theme['Stylesheet Dir'] );
     67        $this->assertEquals( $this->theme_root . '/default', $theme['Template Dir'] );
     68        $this->assertEquals( $this->theme_root . '/default', $theme['Stylesheet Dir'] );
    6969        $this->assertEquals( 'publish', $theme['Status'] );
    7070        $this->assertEquals( '', $theme['Parent Theme'] );
     
    7676     */
    7777    function test_theme_sandbox() {
    78         $theme = get_theme('Sandbox');
    79 
    80         $this->assertFalse( empty($theme) );
     78        $theme = get_theme( 'Sandbox' );
     79
     80        $this->assertFalse( empty( $theme ) );
    8181
    8282        #echo gen_tests_array('theme', $theme);
     
    9292        $template_files = $theme['Template Files'];
    9393
    94         $this->assertEquals( $this->theme_root.'/sandbox/functions.php', reset( $template_files ) );
    95         $this->assertEquals( $this->theme_root.'/sandbox/index.php', next( $template_files ) );
     94        $this->assertEquals( $this->theme_root . '/sandbox/functions.php', reset( $template_files ) );
     95        $this->assertEquals( $this->theme_root . '/sandbox/index.php', next( $template_files ) );
    9696
    9797        $stylesheet_files = $theme['Stylesheet Files'];
    9898
    99         $this->assertEquals( $this->theme_root.'/sandbox/style.css', reset( $stylesheet_files ) );
    100 
    101         $this->assertEquals( $this->theme_root.'/sandbox', $theme['Template Dir'] );
    102         $this->assertEquals( $this->theme_root.'/sandbox', $theme['Stylesheet Dir'] );
     99        $this->assertEquals( $this->theme_root . '/sandbox/style.css', reset( $stylesheet_files ) );
     100
     101        $this->assertEquals( $this->theme_root . '/sandbox', $theme['Template Dir'] );
     102        $this->assertEquals( $this->theme_root . '/sandbox', $theme['Stylesheet Dir'] );
    103103        $this->assertEquals( 'publish', $theme['Status'] );
    104104        $this->assertEquals( '', $theme['Parent Theme'] );
     
    115115
    116116        $theme = $themes['Stylesheet Only'];
    117         $this->assertFalse( empty($theme) );
     117        $this->assertFalse( empty( $theme ) );
    118118
    119119        #echo gen_tests_array('theme', $theme);
     
    126126        $this->assertEquals( 'sandbox', $theme['Template'] );
    127127        $this->assertEquals( 'stylesheetonly', $theme['Stylesheet'] );
    128         $this->assertContains( $this->theme_root.'/sandbox/functions.php', $theme['Template Files'] );
    129         $this->assertContains( $this->theme_root.'/sandbox/index.php', $theme['Template Files'] );
    130 
    131         $this->assertContains( $this->theme_root.'/stylesheetonly/style.css', $theme['Stylesheet Files']);
    132 
    133         $this->assertEquals( $this->theme_root.'/sandbox', $theme['Template Dir'] );
    134         $this->assertEquals( $this->theme_root.'/stylesheetonly', $theme['Stylesheet Dir'] );
     128        $this->assertContains( $this->theme_root . '/sandbox/functions.php', $theme['Template Files'] );
     129        $this->assertContains( $this->theme_root . '/sandbox/index.php', $theme['Template Files'] );
     130
     131        $this->assertContains( $this->theme_root . '/stylesheetonly/style.css', $theme['Stylesheet Files'] );
     132
     133        $this->assertEquals( $this->theme_root . '/sandbox', $theme['Template Dir'] );
     134        $this->assertEquals( $this->theme_root . '/stylesheetonly', $theme['Stylesheet Dir'] );
    135135        $this->assertEquals( 'publish', $theme['Status'] );
    136136        $this->assertEquals( 'Sandbox', $theme['Parent Theme'] );
     
    146146        // Ignore themes in the default /themes directory.
    147147        foreach ( $themes as $theme_name => $theme ) {
    148             if ( $theme->get_theme_root() != $this->theme_root )
     148            if ( $theme->get_theme_root() != $this->theme_root ) {
    149149                unset( $themes[ $theme_name ] );
     150            }
    150151        }
    151152
    152         $theme_names = array_keys($themes);
    153         $expected = array(
     153        $theme_names = array_keys( $themes );
     154        $expected    = array(
    154155            'WordPress Default',
    155156            'Sandbox',
     
    157158            'My Theme',
    158159            'My Theme/theme1', // duplicate theme should be given a unique name
    159             'My Subdir Theme',// theme in a subdirectory should work
    160             'Page Template Child Theme',// theme which inherits page templates
     160            'My Subdir Theme', // theme in a subdirectory should work
     161            'Page Template Child Theme', // theme which inherits page templates
    161162            'Page Template Theme', // theme with page templates for other test code
    162163            'Theme with Spaces in the Directory',
     
    165166        );
    166167
    167         sort($theme_names);
    168         sort($expected);
    169 
    170         $this->assertEquals($expected, $theme_names);
     168        sort( $theme_names );
     169        sort( $expected );
     170
     171        $this->assertEquals( $expected, $theme_names );
    171172    }
    172173
     
    176177     */
    177178    function test_broken_themes() {
    178         $themes   = get_themes();
     179        $themes = get_themes();
    179180
    180181        $expected = array(
     
    191192        );
    192193
    193         $this->assertEquals($expected, get_broken_themes() );
     194        $this->assertEquals( $expected, get_broken_themes() );
    194195    }
    195196
     
    206207
    207208        $theme = $themes['Page Template Theme'];
    208         $this->assertFalse( empty($theme) );
     209        $this->assertFalse( empty( $theme ) );
    209210
    210211        $templates = $theme['Template Files'];
    211         $this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates));
     212        $this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates ) );
    212213    }
    213214
Note: See TracChangeset for help on using the changeset viewer.