OSDN Git Service

test wp user update
authorscribu <mail@scribu.net>
Sun, 17 Feb 2013 02:17:58 +0000 (04:17 +0200)
committerscribu <mail@scribu.net>
Sun, 17 Feb 2013 02:18:22 +0000 (04:18 +0200)
features/bootstrap/FeatureContext.php
features/user.feature

index 87661bf..4d4e85b 100644 (file)
@@ -25,11 +25,27 @@ class FeatureContext extends BehatContext
         *
         * @param array $parameters context parameters (set them up through behat.yml)
         */
-       public function __construct(array $parameters)
+       public function __construct( array $parameters )
        {
                $this->runner = new WP_CLI_Command_Runner;
        }
 
+       private function replace_variables( &$str )
+       {
+               $str = preg_replace_callback( '/\{(\w+)\}/', array( $this, '_replace_var' ), $str );
+       }
+
+       private function _replace_var( $matches )
+       {
+               $cmd = $matches[0];
+
+               foreach ( array_slice( $matches, 1 ) as $key ) {
+                       $cmd = str_replace( '{' . $key . '}', $this->variables[ $key ], $cmd );
+               }
+
+               return $cmd;
+       }
+
        /**
         * @Given /^an empty directory$/
         */
@@ -89,21 +105,11 @@ class FeatureContext extends BehatContext
        {
                $cmd = ltrim( str_replace( 'wp', '', $cmd ) );
 
-               $cmd = preg_replace_callback( '/\{(\w+)\}/', array( $this, 'replace_var' ), $cmd );
+               $this->replace_variables( $cmd );
 
                $this->result = $this->runner->run( $cmd );
        }
 
-       private function replace_var( $matches ) {
-               $cmd = $matches[0];
-
-               foreach ( array_slice( $matches, 1 ) as $key ) {
-                       $cmd = str_replace( '{' . $key . '}', $this->variables[ $key ], $cmd );
-               }
-
-               return $cmd;
-       }
-
        /**
         * @When /^I run the previous command again$/
         */
@@ -148,6 +154,8 @@ class FeatureContext extends BehatContext
         */
        public function outputShouldBe( $stream, PyStringNode $output )
        {
+               $this->replace_variables( $output );
+
                $result = rtrim( $this->result->$stream, "\n" );
 
                if ( (string) $output != $result ) {
index 73d4212..ec16aa4 100644 (file)
@@ -1,6 +1,6 @@
 Feature: Manage WordPress users
 
-  Scenario: Creating/deleting users
+  Scenario: Creating/updating/deleting users
     Given WP install
 
     When I run `wp user create testuser testuser@example.com --porcelain`
@@ -11,6 +11,13 @@ Feature: Manage WordPress users
     When I run the previous command again
     Then the return code should be 1
 
+    When I run `wp user update {USER_ID} --displayname=Foo`
+    Then it should run without errors
+    And STDOUT should be:
+      """
+      Success: Updated user {USER_ID}.
+      """
+
     When I run `wp user delete {USER_ID}`
     Then it should run without errors