Skip to content

Commit

Permalink
Merge pull request #654 from lucatume/v3-add-586-back
Browse files Browse the repository at this point in the history
fix(WPBrowserMethods) re-introduce amEditingUserWithId method
  • Loading branch information
lucatume authored Oct 5, 2023
2 parents 6c95b1b + 56f0393 commit e1d1e62
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 6 deletions.
15 changes: 15 additions & 0 deletions docs/modules/WPBrowser.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
$I->loginAsAdmin();
$userId = $I->haveUserInDatabase('luca', 'editor');
$I->amEditingUserWithId($userId);
$I->fillField('email', 'new@example.net');
```

#### amHttpAuthenticated
Signature: `amHttpAuthenticated($username, $password)` : `void`

Expand Down
15 changes: 15 additions & 0 deletions docs/modules/WPWebDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
$I->loginAsAdmin();
$userId = $I->haveUserInDatabase('luca', 'editor');
$I->amEditingUserWithId($userId);
$I->fillField('email', 'new@example.net');
```

#### amOnAdminAjaxPage
Signature: `amOnAdminAjaxPage([array|string|null $queryVars])` : `void`

Expand Down
22 changes: 22 additions & 0 deletions src/Module/WPBrowserMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
31 changes: 28 additions & 3 deletions tests/_support/_generated/AcceptanceTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] 148ccd6234ead9b1f5505ef1e0b761f5
<?php //[STAMP] df1287dea3c460a2adbcbff84fc4b739
// phpcs:ignoreFile
namespace _generated;

Expand Down Expand Up @@ -2859,6 +2859,31 @@ public function amEditingPostWithId(int $id): void {
}


/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* 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
* @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.
*
Expand Down Expand Up @@ -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'
Expand Down
31 changes: 28 additions & 3 deletions tests/_support/_generated/WebDriverTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] 18aaf26454dcd8726cbe86b073d2dc41
<?php //[STAMP] 6a82500183fff9142991dcd66a6b8827
// phpcs:ignoreFile
namespace _generated;

Expand Down Expand Up @@ -3562,6 +3562,31 @@ public function amEditingPostWithId(int $id): void {
}


/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* 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
* @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.
*
Expand Down Expand Up @@ -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'
Expand Down
44 changes: 44 additions & 0 deletions tests/acceptance/UserEditCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php


namespace Acceptance;

use \AcceptanceTester as Tester;

class UserEditCest
{
public function _before(Tester $I)
{
$I->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.');
}
}
44 changes: 44 additions & 0 deletions tests/webdriver/UserEditCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php


namespace Webdriver;

use WebDriverTester as Tester;

class UserEditCest
{
public function _before(Tester $I)
{
$I->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.');
}
}

0 comments on commit e1d1e62

Please sign in to comment.