Make WordPress Core


Ignore:
Timestamp:
07/19/2014 11:06:54 PM (12 years ago)
Author:
wonderboymusic
Message:

Call untrailingslashit() when adding a theme directory in register_theme_directory(). This prevents double-slashing in generated URLs. Don't add a directory if it is already present.

Adds unit tests.
Props obenland, wonderboymusic.
Fixes #28662.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r28706 r29249  
    235235        }
    236236
     237        /**
     238         * @ticket 28662
     239         */
     240        function test_theme_dir_slashes() {
     241                $size = count( $GLOBALS['wp_theme_directories'] );
     242
     243                @mkdir( WP_CONTENT_DIR . '/themes/foo' );
     244                @mkdir( WP_CONTENT_DIR . '/themes/foo-themes' );
     245
     246                $this->assertTrue( file_exists( WP_CONTENT_DIR . '/themes/foo' ) );
     247                $this->assertTrue( file_exists( WP_CONTENT_DIR . '/themes/foo-themes') );
     248
     249                register_theme_directory( '/' );
     250
     251                $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     252
     253                register_theme_directory( 'themes/' );
     254
     255                $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     256
     257                register_theme_directory( '/foo/' );
     258
     259                $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     260
     261                register_theme_directory( 'foo/' );
     262
     263                $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     264
     265                register_theme_directory( 'themes/foo/' );
     266
     267                $this->assertCount( $size + 1, $GLOBALS['wp_theme_directories'] );
     268
     269                register_theme_directory( WP_CONTENT_DIR . '/foo-themes/' );
     270
     271                $this->assertCount( $size + 1, $GLOBALS['wp_theme_directories'] );
     272
     273                foreach ( $GLOBALS['wp_theme_directories'] as $dir ) {
     274                        $this->assertNotEquals( '/', substr( $dir, -1 ) );
     275                }
     276
     277                rmdir( WP_CONTENT_DIR . '/themes/foo' );
     278                rmdir( WP_CONTENT_DIR . '/themes/foo-themes' );
     279        }
    237280}
Note: See TracChangeset for help on using the changeset viewer.