WordPress.org

Make WordPress Core

Changeset 578 in tests


Ignore:
Timestamp:
03/15/12 13:44:34 (3 years ago)
Author:
nacin
Message:

Fix [UT570] and add a few early unit tests for #WP20103 / WP_Theme.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_theme.php

    r570 r578  
    33// test wp-includes/theme.php 
    44class TestDefaultThemes extends WPTestCase { 
     5 
     6    var $theme_slug = 'twentyeleven'; 
     7    var $theme_name = 'Twenty Eleven'; 
     8 
    59    function setUp() { 
    610        parent::setUp(); 
    711        unset($GLOBALS['wp_themes']); 
    8         unset($GLOBALS['wp_broken_themes']); 
     12    } 
     13 
     14    function test_wp_get_themes_default() { 
     15        $themes = wp_get_themes(); 
     16        $this->assertInstanceOf( 'WP_Theme', $themes[ $this->theme_slug ] ); 
     17        $this->assertEquals( $themes[ $this->theme_slug ], wp_get_theme( $this->theme_slug ) ); 
     18        $this->assertEquals( $this->theme_name, $themes[ $this->theme_slug ]->get('Name') ); 
    919    } 
    1020 
    1121    function test_get_themes_default() { 
    1222        $themes = get_themes(); 
    13         // one theme is included by default: Twenty Eleven 
    14         $this->assertInstanceOf( 'WP_Theme', $themes['Twenty Eleven']); 
     23        $this->assertInstanceOf( 'WP_Theme', $themes[ $this->theme_name ] ); 
     24        $this->assertEquals( $themes[ $this->theme_name ], get_theme( $this->theme_name ) ); 
     25 
     26        $this->assertEquals( $this->theme_name, $themes[ $this->theme_name ]['Name'] ); 
     27        $this->assertEquals( $this->theme_name, $themes[ $this->theme_name ]->Name ); 
     28        $this->assertEquals( $this->theme_name, $themes[ $this->theme_name ]->name ); 
     29    } 
     30 
     31    function test_get_theme() {  
     32        $themes = get_themes(); 
     33        foreach (array_keys($themes) as $name) { 
     34                $theme = get_theme($name); 
     35                // WP_Theme implements ArrayAccess. Even ArrayObject returns false for is_array(). 
     36                $this->assertFalse( is_array( $theme ) ); 
     37                $this->assertInstanceOf( 'WP_Theme', $theme ); 
     38                $this->assertEquals($theme, $themes[$name]); 
     39        } 
     40    } 
     41 
     42    function test_wp_get_theme() { 
     43        $themes = wp_get_themes(); 
     44        foreach ( $themes as $theme ) { 
     45            $this->assertInstanceOf( 'WP_Theme', $theme ); 
     46            $this->assertFalse( $theme->errors() ); 
     47            $_theme = wp_get_theme( $theme->get_stylesheet() ); 
     48            // This primes internal WP_Theme caches for the next assertion (headers_sanitized, textdomain_loaded) 
     49            $this->assertEquals( $theme->get('Name'), $_theme->get('Name') ); 
     50            $this->assertEquals( $theme, $_theme ); 
     51        } 
    1552    } 
    1653 
    1754    function test_get_themes_contents() { 
    18         $themes = wp_get_themes(); 
     55        $themes = get_themes(); 
    1956 
    2057        // Generic tests that should hold true for any theme 
    2158        foreach ($themes as $k=>$theme) { 
    22             $this->assertEquals($theme['Template'], $k); 
     59            $this->assertEquals($theme['Name'], $k); 
    2360            $this->assertTrue(!empty($theme['Title'])); 
    2461 
     
    73110            $this->assertTrue(is_dir($dir . $theme['Stylesheet Dir'])); 
    74111 
    75             $this->assertEquals('public', $theme['Status']); 
     112            $this->assertEquals('publish', $theme['Status']); 
    76113 
    77114            $this->assertTrue(is_file($dir . $theme['Stylesheet Dir'] . '/' . $theme['Screenshot'])); 
    78115            $this->assertTrue(is_readable($dir . $theme['Stylesheet Dir'] . '/' . $theme['Screenshot'])); 
    79         } 
    80     } 
    81  
    82     function test_get_theme() { 
    83         $themes = wp_get_themes(); 
    84         foreach ( $themes as $theme ) { 
    85             $_theme = wp_get_theme( $theme->get_stylesheet() ); 
    86             $this->assertInstanceOf( 'WP_Theme', $_theme ); 
    87             $this->assertFalse( $_theme->errors() ); 
    88116        } 
    89117    } 
     
    165193        update_option('stylesheet', $style); 
    166194 
    167         $theme =  wp_get_theme(); 
    168         $this->assertEquals( $style, $theme->__toString() ); 
    169         $this->assertTrue( false !== $theme->errors() ); 
     195        $theme = wp_get_theme(); 
     196        $this->assertEquals( $style, (string) $theme ); 
     197        $this->assertNotSame( false, $theme->errors() ); 
    170198 
    171199        // these return the bogus name - perhaps not ideal behaviour? 
     
    305333 
    306334    function test_broken_themes() { 
    307         global $wp_broken_themes; 
    308335        $themes = get_themes(); 
    309336        $expected = array('broken-theme' => array('Name' => 'broken-theme', 'Title' => 'broken-theme', 'Description' => __('Stylesheet is missing.'))); 
    310337 
    311         $this->assertEquals($expected, $wp_broken_themes); 
     338        $this->assertEquals($expected, get_broken_themes() ); 
    312339    } 
    313340 
Note: See TracChangeset for help on using the changeset viewer.