OSDN Git Service

add test for --user global parameter
authorscribu <mail@scribu.net>
Sun, 17 Feb 2013 04:36:44 +0000 (06:36 +0200)
committerscribu <mail@scribu.net>
Sun, 17 Feb 2013 04:36:44 +0000 (06:36 +0200)
features/flags.feature
features/steps/basic_steps.php

index 82ec10a..47c9d00 100644 (file)
@@ -34,3 +34,27 @@ Feature: Global flags
       """
       Notice: Use of undefined constant CONST_WITHOUT_QUOTES
       """
+
+  Scenario: Setting the WP user
+    Given WP install
+
+    When I run `wp eval 'echo (int) is_user_logged_in();'`
+    Then it should run without errors
+    And STDOUT should be:
+      """
+      0
+      """
+
+    When I run `wp --user=admin eval 'echo wp_get_current_user()->user_login;'`
+    Then it should run without errors
+    And STDOUT should be:
+      """
+      admin
+      """
+
+    When I run `wp --user=non-existing-user`
+    Then the return code should be 1
+    And STDERR should be:
+      """
+      Error: Could not get a user_id for this user: 'non-existing-user'
+      """
index 436667d..9e19360 100644 (file)
@@ -46,7 +46,9 @@ $steps->Given( '/^custom wp-content directory$/',
 
 $steps->When( '/^I run `(.+)`$/',
        function ( $world, $cmd ) {
-               $cmd = ltrim( str_replace( 'wp', '', $cmd ) );
+               if ( 0 === strpos( $cmd, 'wp' ) ) {
+                       $cmd = ltrim( substr( $cmd, 2 ) );
+               }
 
                $world->replace_variables( $cmd );