Skip to content

Commit

Permalink
Merge pull request #116 from wp-cli/issue-12-theme_root
Browse files Browse the repository at this point in the history
Filter theme_root in tests/bootstrap.php.
  • Loading branch information
schlessera authored Jan 16, 2018
2 parents 71c49e9 + 7fcf9b7 commit 6e5eede
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
41 changes: 40 additions & 1 deletion features/scaffold-theme-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature: Scaffold theme unit tests
"""
And the {THEME_DIR}/p2child/tests/bootstrap.php file should contain:
"""
register_theme_directory( dirname( $theme_dir ) );
register_theme_directory( $theme_root );
"""
And the {THEME_DIR}/p2child/tests/bootstrap.php file should contain:
"""
Expand Down Expand Up @@ -73,6 +73,45 @@ Feature: Scaffold theme unit tests
executable
"""

# Warning: overwriting generated functions.php file, so functions.php file loaded only tests beyond here...
Given a wp-content/themes/p2child/functions.php file:
"""
<?php echo __FILE__ . " loaded.\n";
"""
And I run `MYSQL_PWD=password1 mysql -u wp_cli_test -e "DROP DATABASE IF EXISTS wp_cli_test_scaffold"`
And I try `rm -fr /tmp/behat-wordpress-tests-lib`
And I try `rm -fr /tmp/behat-wordpress`
And I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress {THEME_DIR}/p2child/bin/install-wp-tests.sh wp_cli_test_scaffold wp_cli_test password1 localhost latest`
Then the return code should be 0

When I run `cd {THEME_DIR}/p2child; WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib phpunit`
Then STDOUT should contain:
"""
p2child/functions.php loaded.
"""
And STDOUT should contain:
"""
Running as single site
"""
And STDOUT should contain:
"""
OK (1 test, 1 assertion)
"""

When I run `cd {THEME_DIR}/p2child; WP_MULTISITE=1 WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib phpunit`
Then STDOUT should contain:
"""
p2child/functions.php loaded.
"""
And STDOUT should contain:
"""
Running as multisite
"""
And STDOUT should contain:
"""
OK (1 test, 1 assertion)
"""

Scenario: Scaffold theme tests invalid theme
When I try `wp scaffold theme-tests p3child`
Then STDERR should be:
Expand Down
9 changes: 7 additions & 2 deletions templates/theme-bootstrap.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ require_once $_tests_dir . '/includes/functions.php';

function _register_theme() {
$theme_dir = dirname( dirname( __FILE__ ) );
$theme_dir = dirname( __DIR__ );
$current_theme = basename( $theme_dir );
$theme_root = dirname( $theme_dir );
register_theme_directory( dirname( $theme_dir ) );
add_filter( 'theme_root', function() use ( $theme_root ) {
return $theme_root;
} );

register_theme_directory( $theme_root );

add_filter( 'pre_option_template', function() use ( $current_theme ) {
return $current_theme;
Expand Down

0 comments on commit 6e5eede

Please sign in to comment.