WordPress.org

Make WordPress Core

Changeset 909 in tests for trunk/tests/theme.php


Ignore:
Timestamp:
07/19/2012 01:52:37 AM (10 years ago)
Author:
nacin
Message:

Complete the renaming described in [904].

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/tests/theme.php

    r903 r909  
    66 * @group themes
    77 */
    8 class TestDefaultThemes extends WP_UnitTestCase {
     8class Tests_Theme extends WP_UnitTestCase {
    99
    1010    var $theme_slug = 'twentyeleven';
     
    243243    }
    244244}
    245 
    246 /**
    247  * Test functions that fetch stuff from the theme directory
    248  *
    249  * @group themes
    250  */
    251 class TestThemeDir extends WP_UnitTestCase {
    252     function setUp() {
    253         parent::setUp();
    254         $this->theme_root = DIR_TESTDATA . '/themedir1';
    255 
    256         $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
    257 
    258         // /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
    259         $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
    260 
    261         add_filter('theme_root', array(&$this, '_theme_root'));
    262         add_filter( 'stylesheet_root', array(&$this, '_theme_root') );
    263         add_filter( 'template_root', array(&$this, '_theme_root') );
    264         // clear caches
    265         wp_clean_themes_cache();
    266         unset( $GLOBALS['wp_themes'] );
    267     }
    268 
    269     function tearDown() {
    270         $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
    271         remove_filter('theme_root', array(&$this, '_theme_root'));
    272         remove_filter( 'stylesheet_root', array(&$this, '_theme_root') );
    273         remove_filter( 'template_root', array(&$this, '_theme_root') );
    274         wp_clean_themes_cache();
    275         unset( $GLOBALS['wp_themes'] );
    276         parent::tearDown();
    277     }
    278 
    279     // replace the normal theme root dir with our premade test dir
    280     function _theme_root($dir) {
    281         return $this->theme_root;
    282     }
    283 
    284     function test_theme_default() {
    285         $themes = get_themes();
    286         $theme = get_theme('WordPress Default');
    287         $this->assertEquals( $themes['WordPress Default'], $theme );
    288 
    289         $this->assertFalse( empty($theme) );
    290 
    291         #echo gen_tests_array('theme', $theme);
    292 
    293         $this->assertEquals( 'WordPress Default', $theme['Name'] );
    294         $this->assertEquals( 'WordPress Default', $theme['Title'] );
    295         $this->assertEquals( 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.', $theme['Description'] );
    296         $this->assertEquals( '<a href="http://binarybonsai.com/" title="Visit author homepage">Michael Heilemann</a>', $theme['Author'] );
    297         $this->assertEquals( '1.6', $theme['Version'] );
    298         $this->assertEquals( 'default', $theme['Template'] );
    299         $this->assertEquals( 'default', $theme['Stylesheet'] );
    300 
    301         $this->assertContains( $this->theme_root . '/default/functions.php', $theme['Template Files'] );
    302         $this->assertContains( $this->theme_root . '/default/index.php', $theme['Template Files'] );
    303         $this->assertContains( $this->theme_root . '/default/style.css', $theme['Stylesheet Files'] );
    304 
    305         $this->assertEquals( $this->theme_root.'/default', $theme['Template Dir'] );
    306         $this->assertEquals( $this->theme_root.'/default', $theme['Stylesheet Dir'] );
    307         $this->assertEquals( 'publish', $theme['Status'] );
    308         $this->assertEquals( '', $theme['Parent Theme'] );
    309     }
    310 
    311     function test_theme_sandbox() {
    312         $theme = get_theme('Sandbox');
    313 
    314         $this->assertFalse( empty($theme) );
    315 
    316         #echo gen_tests_array('theme', $theme);
    317 
    318         $this->assertEquals( 'Sandbox', $theme['Name'] );
    319         $this->assertEquals( 'Sandbox', $theme['Title'] );
    320         $this->assertEquals( 'A theme with powerful, semantic CSS selectors and the ability to add new skins.', $theme['Description'] );
    321         $this->assertEquals( '<a href="http://andy.wordpress.com/">Andy Skelton</a> &amp; <a href="http://www.plaintxt.org/">Scott Allan Wallick</a>', $theme['Author'] );
    322         $this->assertEquals( '0.6.1-wpcom', $theme['Version'] );
    323         $this->assertEquals( 'sandbox', $theme['Template'] );
    324         $this->assertEquals( 'sandbox', $theme['Stylesheet'] );
    325         $this->assertEquals( $this->theme_root.'/sandbox/functions.php', reset($theme['Template Files']) );
    326         $this->assertEquals( $this->theme_root.'/sandbox/index.php', next($theme['Template Files']) );
    327 
    328         $this->assertEquals( $this->theme_root.'/sandbox/style.css', reset($theme['Stylesheet Files']) );
    329 
    330         $this->assertEquals( $this->theme_root.'/sandbox', $theme['Template Dir'] );
    331         $this->assertEquals( $this->theme_root.'/sandbox', $theme['Stylesheet Dir'] );
    332         $this->assertEquals( 'publish', $theme['Status'] );
    333         $this->assertEquals( '', $theme['Parent Theme'] );
    334 
    335     }
    336 
    337     // a css only theme
    338     function test_theme_stylesheet_only() {
    339         $themes = get_themes();
    340 
    341         $theme = $themes['Stylesheet Only'];
    342         $this->assertFalse( empty($theme) );
    343 
    344         #echo gen_tests_array('theme', $theme);
    345 
    346         $this->assertEquals( 'Stylesheet Only', $theme['Name'] );
    347         $this->assertEquals( 'Stylesheet Only', $theme['Title'] );
    348         $this->assertEquals( 'A three-column widget-ready theme in dark blue.', $theme['Description'] );
    349         $this->assertEquals( '<a href="http://www.example.com/" title="Visit author homepage">Henry Crun</a>', $theme['Author'] );
    350         $this->assertEquals( '1.0', $theme['Version'] );
    351         $this->assertEquals( 'sandbox', $theme['Template'] );
    352         $this->assertEquals( 'stylesheetonly', $theme['Stylesheet'] );
    353         $this->assertContains( $this->theme_root.'/sandbox/functions.php', $theme['Template Files'] );
    354         $this->assertContains( $this->theme_root.'/sandbox/index.php', $theme['Template Files'] );
    355 
    356         $this->assertContains( $this->theme_root.'/stylesheetonly/style.css', $theme['Stylesheet Files']);
    357 
    358         $this->assertEquals( $this->theme_root.'/sandbox', $theme['Template Dir'] );
    359         $this->assertEquals( $this->theme_root.'/stylesheetonly', $theme['Stylesheet Dir'] );
    360         $this->assertEquals( 'publish', $theme['Status'] );
    361         $this->assertEquals( 'Sandbox', $theme['Parent Theme'] );
    362 
    363     }
    364 
    365     function test_theme_list() {
    366         $themes = get_themes();
    367 
    368         // Ignore themes in the default /themes directory.
    369         foreach ( $themes as $theme_name => $theme ) {
    370             if ( $theme->get_theme_root() != $this->theme_root )
    371                 unset( $themes[ $theme_name ] );
    372         }
    373 
    374         $theme_names = array_keys($themes);
    375         $expected = array(
    376             'WordPress Default',
    377             'Sandbox',
    378             'Stylesheet Only',
    379             'My Theme',
    380             'My Theme/theme1', // duplicate theme should be given a unique name
    381             'My Subdir Theme',// theme in a subdirectory should work
    382             'Page Template Theme', // theme with page templates for other test code
    383         );
    384 
    385         sort($theme_names);
    386         sort($expected);
    387 
    388         $this->assertEquals($expected, $theme_names);
    389     }
    390 
    391     function test_broken_themes() {
    392         $themes = get_themes();
    393         $expected = array('broken-theme' => array('Name' => 'broken-theme', 'Title' => 'broken-theme', 'Description' => __('Stylesheet is missing.')));
    394 
    395         $this->assertEquals($expected, get_broken_themes() );
    396     }
    397 
    398     function test_wp_get_theme_with_non_default_theme_root() {
    399         $this->assertFalse( wp_get_theme( 'sandbox', $this->theme_root )->errors() );
    400         $this->assertFalse( wp_get_theme( 'sandbox' )->errors() );
    401     }
    402 
    403     function test_page_templates() {
    404         $themes = get_themes();
    405 
    406         $theme = $themes['Page Template Theme'];
    407         $this->assertFalse( empty($theme) );
    408 
    409         $templates = $theme['Template Files'];
    410         $this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates));
    411     }
    412 
    413     function test_get_theme_data_top_level() {
    414         $theme_data = get_theme_data( DIR_TESTDATA . '/themedir1/theme1/style.css' );
    415 
    416         $this->assertEquals( 'My Theme', $theme_data['Name'] );
    417         $this->assertEquals( 'http://example.org/', $theme_data['URI'] );
    418         $this->assertEquals( 'An example theme', $theme_data['Description'] );
    419         $this->assertEquals( '<a href="http://example.com/" title="Visit author homepage">Minnie Bannister</a>', $theme_data['Author'] );
    420         $this->assertEquals( 'http://example.com/', $theme_data['AuthorURI'] );
    421         $this->assertEquals( '1.3', $theme_data['Version'] );
    422         $this->assertEquals( '', $theme_data['Template'] );
    423         $this->assertEquals( 'publish', $theme_data['Status'] );
    424         $this->assertEquals( array(), $theme_data['Tags'] );
    425         $this->assertEquals( 'My Theme', $theme_data['Title'] );
    426         $this->assertEquals( 'Minnie Bannister', $theme_data['AuthorName'] );
    427     }
    428 
    429     function test_get_theme_data_subdir() {
    430         $theme_data = get_theme_data( $this->theme_root . '/subdir/theme2/style.css' );
    431 
    432         $this->assertEquals( 'My Subdir Theme', $theme_data['Name'] );
    433         $this->assertEquals( 'http://example.org/', $theme_data['URI'] );
    434         $this->assertEquals( 'An example theme in a sub directory', $theme_data['Description'] );
    435         $this->assertEquals( '<a href="http://wordpress.org/" title="Visit author homepage">Mr. WordPress</a>', $theme_data['Author'] );
    436         $this->assertEquals( 'http://wordpress.org/', $theme_data['AuthorURI'] );
    437         $this->assertEquals( '0.1', $theme_data['Version'] );
    438         $this->assertEquals( '', $theme_data['Template'] );
    439         $this->assertEquals( 'publish', $theme_data['Status'] );
    440         $this->assertEquals( array(), $theme_data['Tags'] );
    441         $this->assertEquals( 'My Subdir Theme', $theme_data['Title'] );
    442         $this->assertEquals( 'Mr. WordPress', $theme_data['AuthorName'] );
    443     }
    444 
    445 }
    446 
    447 /**
    448  * @group themes
    449  */
    450 class TestLargeThemeDir extends WP_UnitTestCase {
    451     function setUp() {
    452         parent::setUp();
    453         $this->theme_root = DIR_TESTDATA . '/wpcom-themes';
    454 
    455         $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
    456         $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
    457 
    458         add_filter('theme_root', array(&$this, '_theme_root'));
    459 
    460         // clear caches
    461         wp_clean_themes_cache();
    462         unset( $GLOBALS['wp_themes'] );
    463     }
    464 
    465     function tearDown() {
    466         $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
    467         remove_filter('theme_root', array(&$this, '_theme_root'));
    468         wp_clean_themes_cache();
    469         unset( $GLOBALS['wp_themes'] );
    470         parent::tearDown();
    471     }
    472 
    473     // replace the normal theme root dir with our premade test dir
    474     function _theme_root($dir) {
    475         return $this->theme_root;
    476     }
    477 
    478     function _filter_out_themes_not_in_root( &$themes ) {
    479         foreach ( $themes as $key => $theme ) {
    480             if ( $theme->get_theme_root() != $this->theme_root )
    481                 unset( $themes[ $key ] );
    482         }
    483     }
    484 
    485     function test_theme_list() {
    486         $themes = get_themes();
    487         $this->_filter_out_themes_not_in_root( $themes );
    488         $theme_names = array_keys( $themes );
    489         $this->assertEquals(87, count( $theme_names ) );
    490         $length = strlen( serialize( $themes ) );
    491 
    492         //2.9 pre [12226]
    493         $this->assertLessThanOrEqual(387283, $length );
    494         //2.8.5
    495         $this->assertLessThanOrEqual(368319, $length );
    496         //2.9 post [12226]
    497         $this->assertLessThanOrEqual(261998, $length );
    498         //3.4 post [20029], #20103
    499         $this->assertLessThanOrEqual(100000, $length );
    500     }
    501 
    502     /**
    503      * Reducing in-memory size further.
    504      *
    505      * @ticket 11214
    506      */
    507     function test_smaller_storage() {
    508         $themes = get_themes();
    509         $this->_filter_out_themes_not_in_root( $themes );
    510         $theme_names = array_keys($themes);
    511         $this->assertEquals(87, count($theme_names));
    512         $this->assertLessThanOrEqual(136342, strlen(serialize($themes)));
    513     }
    514 }
    515 
    516 /**
    517  * @group themes
    518  */
    519 class TestThemeSupport extends WP_UnitTestCase {
    520     function setUp() {
    521         parent::setUp();
    522     }
    523 
    524     function tearDown() {
    525         parent::tearDown();
    526     }
    527 
    528     function test_the_basics() {
    529         add_theme_support( 'automatic-feed-links' );
    530         $this->assertTrue( current_theme_supports( 'automatic-feed-links' ) );
    531         remove_theme_support( 'automatic-feed-links' );
    532         $this->assertFalse( current_theme_supports( 'automatic-feed-links' ) );
    533         add_theme_support( 'automatic-feed-links' );
    534         $this->assertTrue( current_theme_supports( 'automatic-feed-links' ) );
    535     }
    536 
    537     function test_admin_bar() {
    538         add_theme_support( 'admin-bar' );
    539         $this->assertTrue( current_theme_supports( 'admin-bar' ) );
    540         remove_theme_support( 'admin-bar' );
    541         $this->assertFalse( current_theme_supports( 'admin-bar' ) );
    542         add_theme_support( 'admin-bar' );
    543         $this->assertTrue( current_theme_supports( 'admin-bar' ) );
    544 
    545         add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
    546         $this->assertTrue( current_theme_supports( 'admin-bar' ) );
    547 
    548         $this->assertEquals(
    549             array( 0 => array( 'callback' => '__return_false' ) ),
    550             get_theme_support( 'admin-bar' )
    551         );
    552         remove_theme_support( 'admin-bar' );
    553         $this->assertFalse( current_theme_supports( 'admin-bar' ) );
    554         $this->assertFalse( get_theme_support( 'admin-bar' ) );
    555     }
    556 
    557     function test_post_thumbnails() {
    558         add_theme_support( 'post-thumbnails' );
    559         $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
    560         remove_theme_support( 'post-thumbnails' );
    561         $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
    562         add_theme_support( 'post-thumbnails' );
    563         $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
    564 
    565         // simple array of post types.
    566         add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
    567         $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
    568         $this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) );
    569         $this->assertFalse( current_theme_supports( 'post-thumbnails', 'book' ) );
    570         remove_theme_support( 'post-thumbnails' );
    571         $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
    572 
    573         #WP18548
    574         if ( ! function_exists( '_wp_render_title_tag' ) )
    575             return;
    576 
    577         // array of arguments, with the key of 'types' holding the post types.
    578         add_theme_support( 'post-thumbnails', array( 'types' => array( 'post', 'page' ) ) );
    579         $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
    580         $this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) );
    581         $this->assertFalse( current_theme_supports( 'post-thumbnails', 'book' ) );
    582         remove_theme_support( 'post-thumbnails' );
    583         $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
    584 
    585         // array of arguments, with the key of 'types' holding the post types.
    586         add_theme_support( 'post-thumbnails', array( 'types' => true ) );
    587         $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
    588         $this->assertTrue( current_theme_supports( 'post-thumbnails', rand_str() ) ); // any type
    589         remove_theme_support( 'post-thumbnails' );
    590         $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
    591 
    592         // array of arguments, with some other argument, and no 'types' argument.
    593         add_theme_support( 'post-thumbnails', array( rand_str() => rand_str() ) );
    594         $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
    595         $this->assertTrue( current_theme_supports( 'post-thumbnails', rand_str() ) ); // any type
    596         remove_theme_support( 'post-thumbnails' );
    597         $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
    598 
    599     }
    600 
    601     function supports_foobar( $yesno, $args, $feature ) {
    602         if ( $args[0] == $feature[0] )
    603             return true;
    604         return false;
    605     }
    606 
    607     function test_plugin_hook() {
    608         $this->assertFalse( current_theme_supports( 'foobar' ) );
    609         add_theme_support( 'foobar' );
    610         $this->assertTrue( current_theme_supports( 'foobar' ) );
    611 
    612         add_filter( 'current_theme_supports-foobar', array( $this, 'supports_foobar'), 10, 3 );
    613 
    614         add_theme_support( 'foobar', 'bar' );
    615         $this->assertFalse( current_theme_supports( 'foobar', 'foo' ) );
    616         $this->assertTrue( current_theme_supports( 'foobar', 'bar' ) );
    617 
    618         remove_theme_support( 'foobar' );
    619         $this->assertFalse( current_theme_supports( 'foobar', 'bar' ) );
    620     }
    621 }
Note: See TracChangeset for help on using the changeset viewer.