From 398af1ceea87bf96396e9825792c0c30ff0cf2cd Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 30 Dec 2012 14:57:36 +0200 Subject: [PATCH] add test case for custom WP_CONTENT dirs --- tests/abstract-spec.php | 5 +++++ tests/command-runner.php | 31 +++++++++++++++++++++++++++++++ tests/spec-core.php | 14 ++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/tests/abstract-spec.php b/tests/abstract-spec.php index 11effab3..e49239dd 100644 --- a/tests/abstract-spec.php +++ b/tests/abstract-spec.php @@ -45,6 +45,11 @@ abstract class WP_CLI_Spec extends PHPUnit_Extensions_Story_TestCase { } break; + case 'custom wp-content dir': { + $world['runner']->define_custom_wp_content_dir(); + } + break; + default: { return $this->notImplemented( $action ); } diff --git a/tests/command-runner.php b/tests/command-runner.php index d232c911..26133fd9 100644 --- a/tests/command-runner.php +++ b/tests/command-runner.php @@ -28,6 +28,37 @@ class WP_CLI_Command_Runner { return $this->run( 'core config' . \WP_CLI\Utils\compose_assoc_args( $db_settings ) ); } + public function define_custom_wp_content_dir() { + $wp_config_path = $this->install_dir . '/wp-config.php'; + + $wp_config_code = file_get_contents( $wp_config_path ); + + $this->add_line_to_wp_config( $wp_config_code, + "define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/my-content' );" ); + + $this->move_files( 'wp-content', 'my-content' ); + + $this->add_line_to_wp_config( $wp_config_code, + "define( 'WP_PLUGIN_DIR', __DIR__ . '/my-plugins' );" ); + + $this->move_files( 'my-content/plugins', 'my-plugins' ); + + file_put_contents( $wp_config_path, $wp_config_code ); + } + + private function move_files( $src, $dest ) { + rename( + $this->install_dir . '/' . $src, + $this->install_dir . '/' . $dest + ); + } + + private function add_line_to_wp_config( &$wp_config_code, $line ) { + $token = "/* That's all, stop editing!"; + + $wp_config_code = str_replace( $token, "$line\n\n$token", $wp_config_code ); + } + public function run_install() { $cmd = 'core install' . \WP_CLI\Utils\compose_assoc_args( array( 'url' => 'http://example.com', diff --git a/tests/spec-core.php b/tests/spec-core.php index 4221919d..adb4c574 100644 --- a/tests/spec-core.php +++ b/tests/spec-core.php @@ -59,5 +59,19 @@ class CoreCommandSpec extends WP_CLI_Spec { ->when( 'invoking', 'core is-installed' ) ->then( 'return code should be', 0 ); } + + /** @scenario */ + public function customWpContentDir() { + $this + ->given( 'empty dir' ) + ->and( 'wp install' ) + ->and( 'custom wp-content dir' ) + + ->when( 'invoking', 'theme status twentytwelve' ) + ->then( 'return code should be', 0 ) + + ->when( 'invoking', 'plugin status hello' ) + ->then( 'return code should be', 0 ); + } } -- 2.11.0