OSDN Git Service

test getting help for a third-party command
authorscribu <mail@scribu.net>
Tue, 12 Mar 2013 00:26:29 +0000 (02:26 +0200)
committerscribu <mail@scribu.net>
Tue, 12 Mar 2013 00:27:14 +0000 (02:27 +0200)
features/bootstrap/FeatureContext.php
features/help.feature
features/steps/basic_steps.php

index d45f895..8fb9912 100644 (file)
@@ -69,6 +69,21 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface
                return $this->install_dir . '/' . $file;
        }
 
+       public function get_cache_path( $file ) {
+               static $path;
+
+               if ( !$path ) {
+                       $path = sys_get_temp_dir() . '/wp-cli-test-cache';
+                       system( \WP_CLI\Utils\create_cmd( 'mkdir -p %s', $path ) );
+               }
+
+               return $path . '/' . $file;
+       }
+
+       public function download_file( $url, $path ) {
+               system( \WP_CLI\Utils\create_cmd( 'curl -sSL %s > %s', $url, $path ) );
+       }
+
        private static function run_sql( $sql ) {
                $dbuser = self::$db_settings['dbuser'];
                $dbpass = self::$db_settings['dbpass'];
index 53dfbb8..432eadf 100644 (file)
@@ -14,7 +14,7 @@ Feature: Get help about WP-CLI commands
     Then it should run without errors
     And STDOUT should contain:
       """
-      usage:
+      usage: wp core
       """
 
     When I run `wp help core download`
@@ -26,3 +26,16 @@ Feature: Get help about WP-CLI commands
 
     When I run `wp help non-existent-command`
     Then the return code should be 1
+
+  Scenario: Getting help for a third-party command
+    Given a WP install
+    And a google-sitemap-generator-cli plugin zip
+    And I run `wp plugin install --activate {PLUGIN_ZIP}`
+    And I run `wp plugin install --activate google-sitemap-generator`
+
+    When I run `wp help google-sitemap`
+    Then it should run without errors
+    And STDOUT should contain:
+      """
+      usage: wp google-sitemap
+      """
index 6e48c3b..f16959b 100644 (file)
@@ -44,19 +44,25 @@ $steps->Given( '/^custom wp-content directory$/',
        }
 );
 
-$steps->Given('/^a P2 theme zip$/',
+$steps->Given( '/^a P2 theme zip$/',
        function ( $world ) {
                $zip_name = 'p2.1.0.1.zip';
 
-               $cache_dir = sys_get_temp_dir() . '/wp-cli-test-cache';
-               $world->variables['THEME_ZIP'] = $cache_dir . '/' . $zip_name;
+               $world->variables['THEME_ZIP'] = $world->get_cache_path( $zip_name );
 
                $zip_url = 'http://wordpress.org/extend/themes/download/' . $zip_name;
 
-               system( \WP_CLI\Utils\create_cmd( 'mkdir -p %s', $cache_dir ) );
+               $world->download_file( $zip_url, $world->variables['THEME_ZIP'] );
+       }
+);
+
+$steps->Given( '/^a google-sitemap-generator-cli plugin zip$/',
+       function ( $world ) {
+               $zip_url = 'https://github.com/wp-cli/google-sitemap-generator-cli/archive/master.zip';
+
+               $world->variables['PLUGIN_ZIP'] = $world->get_cache_path( 'google-sitemap-generator-cli.zip' );
 
-               system( \WP_CLI\Utils\create_cmd( 'curl -s %s > %s', $zip_url,
-                       $world->variables['THEME_ZIP'] ) );
+               $world->download_file( $zip_url, $world->variables['PLUGIN_ZIP'] );
        }
 );