diff --git a/docs/modules/WPBrowser.md b/docs/modules/WPBrowser.md index 1a80635f7..8629d62e2 100644 --- a/docs/modules/WPBrowser.md +++ b/docs/modules/WPBrowser.md @@ -111,6 +111,21 @@ $I->amEditingPostWithId($postId); $I->fillField('post_title', 'Post title'); ``` +#### amEditingUserWithId +Signature: `amEditingUserWithId(int $id)` : `void` + +Go to the admin page to edit the user with the specified ID. + +The method will **not** handle authentication the admin area. + +```php +loginAsAdmin(); +$userId = $I->haveUserInDatabase('luca', 'editor'); +$I->amEditingUserWithId($userId); +$I->fillField('email', 'new@example.net'); +``` + #### amHttpAuthenticated Signature: `amHttpAuthenticated($username, $password)` : `void` diff --git a/docs/modules/WPWebDriver.md b/docs/modules/WPWebDriver.md index f2a7bad76..bb2cbed99 100644 --- a/docs/modules/WPWebDriver.md +++ b/docs/modules/WPWebDriver.md @@ -129,6 +129,21 @@ $I->amEditingPostWithId($postId); $I->fillField('post_title', 'Post title'); ``` +#### amEditingUserWithId +Signature: `amEditingUserWithId(int $id)` : `void` + +Go to the admin page to edit the user with the specified ID. + +The method will **not** handle authentication the admin area. + +```php +loginAsAdmin(); +$userId = $I->haveUserInDatabase('luca', 'editor'); +$I->amEditingUserWithId($userId); +$I->fillField('email', 'new@example.net'); +``` + #### amOnAdminAjaxPage Signature: `amOnAdminAjaxPage([array|string|null $queryVars])` : `void` diff --git a/src/Module/WPBrowserMethods.php b/src/Module/WPBrowserMethods.php index 94462a14c..d79d485da 100644 --- a/src/Module/WPBrowserMethods.php +++ b/src/Module/WPBrowserMethods.php @@ -528,4 +528,26 @@ protected function validateConfig(): void } } } + + /** + * Go to the admin page to edit the user with the specified ID. + * + * The method will **not** handle authentication the admin area. + * + * @example + * ```php + * $I->loginAsAdmin(); + * $userId = $I->haveUserInDatabase('luca', 'editor'); + * $I->amEditingUserWithId($userId); + * $I->fillField('email', 'new@example.net'); + * ``` + * + * @param int $id The user ID. + * + * @return void + */ + public function amEditingUserWithId(int $id): void + { + $this->amOnAdminPage('/user-edit.php?user_id=' . $id); + } } diff --git a/tests/_support/_generated/AcceptanceTesterActions.php b/tests/_support/_generated/AcceptanceTesterActions.php index b16da0641..6f4974f60 100644 --- a/tests/_support/_generated/AcceptanceTesterActions.php +++ b/tests/_support/_generated/AcceptanceTesterActions.php @@ -1,4 +1,4 @@ -loginAsAdmin(); + * $userId = $I->haveUserInDatabase('luca', 'editor'); + * $I->amEditingUserWithId($userId); + * $I->fillField('email', 'new@example.net'); + * ``` + * + * @param int $id The user ID. + * + * @return void + * @see \lucatume\WPBrowser\Module\WPBrowser::amEditingUserWithId() + */ + public function amEditingUserWithId(int $id): void { + $this->getScenario()->runStep(new \Codeception\Step\Condition('amEditingUserWithId', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -6503,8 +6528,8 @@ public function cantSeeAttachmentInDatabase(array $criteria): void { * Removes an attachment from the posts table. * * @example - * ``` - * $postmeta = $I->grabpostmetatablename(); + * ``` php + * $postmeta = $I->grabpostmetatablename(); * $thumbnailId = $I->grabFromDatabase($postmeta, 'meta_value', [ * 'post_id' => $id, * 'meta_key'=>'thumbnail_id' diff --git a/tests/_support/_generated/WebDriverTesterActions.php b/tests/_support/_generated/WebDriverTesterActions.php index fb5001ff2..7b4dd4a90 100644 --- a/tests/_support/_generated/WebDriverTesterActions.php +++ b/tests/_support/_generated/WebDriverTesterActions.php @@ -1,4 +1,4 @@ -loginAsAdmin(); + * $userId = $I->haveUserInDatabase('luca', 'editor'); + * $I->amEditingUserWithId($userId); + * $I->fillField('email', 'new@example.net'); + * ``` + * + * @param int $id The user ID. + * + * @return void + * @see \lucatume\WPBrowser\Module\WPWebDriver::amEditingUserWithId() + */ + public function amEditingUserWithId(int $id): void { + $this->getScenario()->runStep(new \Codeception\Step\Condition('amEditingUserWithId', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -7206,8 +7231,8 @@ public function cantSeeAttachmentInDatabase(array $criteria): void { * Removes an attachment from the posts table. * * @example - * ``` - * $postmeta = $I->grabpostmetatablename(); + * ``` php + * $postmeta = $I->grabpostmetatablename(); * $thumbnailId = $I->grabFromDatabase($postmeta, 'meta_value', [ * 'post_id' => $id, * 'meta_key'=>'thumbnail_id' diff --git a/tests/acceptance/UserEditCest.php b/tests/acceptance/UserEditCest.php new file mode 100644 index 000000000..05c5ca365 --- /dev/null +++ b/tests/acceptance/UserEditCest.php @@ -0,0 +1,44 @@ +loginAsAdmin(); + } + + /** + * It should allow editing a user by ID + * + * @test + */ + public function should_allow_editing_a_user_by_id(Tester $I): void + { + $userId = $I->haveUserInDatabase('bob', 'subscriber', [ + 'display_name' => 'TheBob' + ]); + + $I->amEditingUserWithId($userId); + + $I->see('Edit User TheBob'); + } + + /** + * It should fail to edit a user that does not exist + * + * @test + */ + public function should_fail_to_edit_a_user_that_does_not_exist(Tester $I): void + { + $userId = 999999; + + $I->amEditingUserWithId($userId); + + $I->see('Invalid user ID.'); + } +} diff --git a/tests/webdriver/UserEditCest.php b/tests/webdriver/UserEditCest.php new file mode 100644 index 000000000..a78ce1d55 --- /dev/null +++ b/tests/webdriver/UserEditCest.php @@ -0,0 +1,44 @@ +loginAsAdmin(); + } + + /** + * It should allow editing a user by ID + * + * @test + */ + public function should_allow_editing_a_user_by_id(Tester $I): void + { + $userId = $I->haveUserInDatabase('bob', 'subscriber', [ + 'display_name' => 'TheBob' + ]); + + $I->amEditingUserWithId($userId); + + $I->waitForText('Edit User TheBob'); + } + + /** + * It should fail to edit a user that does not exist + * + * @test + */ + public function should_fail_to_edit_a_user_that_does_not_exist(Tester $I): void + { + $userId = 999999; + + $I->amEditingUserWithId($userId); + + $I->see('Invalid user ID.'); + } +}