From 980df25c8bc4d539f6d04559639abd82009e426d Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 18 Apr 2016 16:58:37 +0100 Subject: [PATCH 01/11] [Behat] Add Behat test for issue EZP-25642 users 'Delete' button --- Features/Context/SubContext/CommonActions.php | 14 ++++++++++++++ Features/Context/Users.php | 9 +++++++++ Features/Users/users.feature | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/Features/Context/SubContext/CommonActions.php b/Features/Context/SubContext/CommonActions.php index 0bd5ddd71..aef7a7636 100644 --- a/Features/Context/SubContext/CommonActions.php +++ b/Features/Context/SubContext/CommonActions.php @@ -313,6 +313,20 @@ private function goToContentWithPath($path) $this->clickOnTreePath($path); } + + /** + * @Then I should see a :button button in the action bar + * + * @param string $button Text of the element in the action bar + */ + public function iShouldSeeActionBarButton($button) + { + $element = $this->getElementByText($button, '.ez-actionbar-container .ez-action', '.action-label'); + if (!$element) { + throw new \Exception("Action bar button '$button' not found"); + } + } + /** * @Then I am on the :name location view */ diff --git a/Features/Context/Users.php b/Features/Context/Users.php index e82b0d420..65a042661 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -35,6 +35,15 @@ public function iCreateUser(TableNode $users = null) } } + /** + * @When I go to (the) User :username page + */ + public function goToUserPage($username) + { + $this->clickOnTreePath("$username $username"); + $this->sleep(); //safegaurd for application delays + } + /** * @When I edit user :username */ diff --git a/Features/Users/users.feature b/Features/Users/users.feature index 0a20840f9..68ef96917 100644 --- a/Features/Users/users.feature +++ b/Features/Users/users.feature @@ -67,3 +67,10 @@ Feature: Use the eZ Users field And I fill in "Password" with "12345" And I fill in "Confirm password" with "123456" Then I should see error messages + + @javascript @edge + Scenario: Validate that users have the "Delete" button available + Given I am on the Users page + And there is a User with name "One" + When I go to User "One" page + Then I should see a "Delete" button in the action bar From 9eafc7f04f65acd32abc589fa481fec0a3e51385 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 19 Apr 2016 15:52:10 +0100 Subject: [PATCH 02/11] [Behat] minor comment syntax fix --- Features/Context/Users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Features/Context/Users.php b/Features/Context/Users.php index 65a042661..9bd040d20 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -41,7 +41,7 @@ public function iCreateUser(TableNode $users = null) public function goToUserPage($username) { $this->clickOnTreePath("$username $username"); - $this->sleep(); //safegaurd for application delays + $this->sleep(); //safeguard for application delays } /** From d1591ab5f2ba4721ad9163001050ccb1fc1658e2 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 19 Apr 2016 15:53:34 +0100 Subject: [PATCH 03/11] [Behat] Improve 'I should see action bar button' sentence --- Features/Context/SubContext/CommonActions.php | 2 +- Features/Users/users.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Features/Context/SubContext/CommonActions.php b/Features/Context/SubContext/CommonActions.php index aef7a7636..2d6e4a03b 100644 --- a/Features/Context/SubContext/CommonActions.php +++ b/Features/Context/SubContext/CommonActions.php @@ -315,7 +315,7 @@ private function goToContentWithPath($path) /** - * @Then I should see a :button button in the action bar + * @Then I should see a :button action bar button * * @param string $button Text of the element in the action bar */ diff --git a/Features/Users/users.feature b/Features/Users/users.feature index 68ef96917..2da892eb9 100644 --- a/Features/Users/users.feature +++ b/Features/Users/users.feature @@ -73,4 +73,4 @@ Feature: Use the eZ Users field Given I am on the Users page And there is a User with name "One" When I go to User "One" page - Then I should see a "Delete" button in the action bar + Then I should see a "Delete" action bar button From b641dea765f359f0ffea18cbc3e132cb210e5a96 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 19 Apr 2016 15:54:33 +0100 Subject: [PATCH 04/11] [Behat] Improve 'I should see action bar button' method argument --- Features/Context/SubContext/CommonActions.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Features/Context/SubContext/CommonActions.php b/Features/Context/SubContext/CommonActions.php index 2d6e4a03b..2ca94a676 100644 --- a/Features/Context/SubContext/CommonActions.php +++ b/Features/Context/SubContext/CommonActions.php @@ -313,17 +313,16 @@ private function goToContentWithPath($path) $this->clickOnTreePath($path); } - /** * @Then I should see a :button action bar button * - * @param string $button Text of the element in the action bar + * @param string $buttonText Text of the element in the action bar */ - public function iShouldSeeActionBarButton($button) + public function iShouldSeeActionBarButton($buttonText) { - $element = $this->getElementByText($button, '.ez-actionbar-container .ez-action', '.action-label'); + $element = $this->getElementByText($buttonText, '.ez-actionbar-container .ez-action', '.action-label'); if (!$element) { - throw new \Exception("Action bar button '$button' not found"); + throw new \Exception("Action bar button '$buttonText' not found"); } } From 1fa996f63f6df5f00b42da38fa8593dc5dbd302c Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 20 Apr 2016 08:47:49 +0100 Subject: [PATCH 05/11] [Behat] Add 'I should not see action bar button' sentence --- Features/Context/SubContext/CommonActions.php | 13 +++++++++++++ Features/Users/users.feature | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Features/Context/SubContext/CommonActions.php b/Features/Context/SubContext/CommonActions.php index 2ca94a676..da5af807c 100644 --- a/Features/Context/SubContext/CommonActions.php +++ b/Features/Context/SubContext/CommonActions.php @@ -326,6 +326,19 @@ public function iShouldSeeActionBarButton($buttonText) } } + /** + * @Then I should not see a :button action bar button + * + * @param string $buttonText Text of the element in the action bar + */ + public function iShouldNotSeeActionBarButton($buttonText) + { + $element = $this->getElementByText($buttonText, '.ez-actionbar-container .ez-action', '.action-label'); + if ($element) { + throw new \Exception("Action bar button '$buttonText' was found"); + } + } + /** * @Then I am on the :name location view */ diff --git a/Features/Users/users.feature b/Features/Users/users.feature index 2da892eb9..9d463691f 100644 --- a/Features/Users/users.feature +++ b/Features/Users/users.feature @@ -73,4 +73,5 @@ Feature: Use the eZ Users field Given I am on the Users page And there is a User with name "One" When I go to User "One" page - Then I should see a "Delete" action bar button + Then I should not see a "Send to thrash" action bar button + And I should see a "Delete" action bar button From e79ba26d067afbe4712288e279be12d511f3ef10 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 20 Apr 2016 08:48:27 +0100 Subject: [PATCH 06/11] [Behat] Improve 'I go to User page' sentence --- Features/Context/Users.php | 2 ++ Features/Users/users.feature | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Features/Context/Users.php b/Features/Context/Users.php index 9bd040d20..170a59073 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -40,6 +40,8 @@ public function iCreateUser(TableNode $users = null) */ public function goToUserPage($username) { + $this->iAmOnPage('Users'); + $this->waitWhileLoading(); $this->clickOnTreePath("$username $username"); $this->sleep(); //safeguard for application delays } diff --git a/Features/Users/users.feature b/Features/Users/users.feature index 9d463691f..2a3377185 100644 --- a/Features/Users/users.feature +++ b/Features/Users/users.feature @@ -70,8 +70,7 @@ Feature: Use the eZ Users field @javascript @edge Scenario: Validate that users have the "Delete" button available - Given I am on the Users page - And there is a User with name "One" + Given there is a User with name "One" When I go to User "One" page Then I should not see a "Send to thrash" action bar button And I should see a "Delete" action bar button From 515e519a01c0f240f427de0fb82909df699efe71 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 20 Apr 2016 13:54:41 +0100 Subject: [PATCH 07/11] [Behat] Change 'iShouldSeeActionBarButton' exception for assertion --- Features/Context/SubContext/CommonActions.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Features/Context/SubContext/CommonActions.php b/Features/Context/SubContext/CommonActions.php index da5af807c..e25e1b56f 100644 --- a/Features/Context/SubContext/CommonActions.php +++ b/Features/Context/SubContext/CommonActions.php @@ -321,9 +321,7 @@ private function goToContentWithPath($path) public function iShouldSeeActionBarButton($buttonText) { $element = $this->getElementByText($buttonText, '.ez-actionbar-container .ez-action', '.action-label'); - if (!$element) { - throw new \Exception("Action bar button '$buttonText' not found"); - } + EzAssertion::assertSingleElement($buttonText, $element, null, 'Action bar button'); } /** @@ -334,9 +332,7 @@ public function iShouldSeeActionBarButton($buttonText) public function iShouldNotSeeActionBarButton($buttonText) { $element = $this->getElementByText($buttonText, '.ez-actionbar-container .ez-action', '.action-label'); - if ($element) { - throw new \Exception("Action bar button '$buttonText' was found"); - } + EzAssertion::assertElementNotFound($buttonText, $element, null, 'Action bar button'); } /** From 0538b7361ee6f6ab917f5be9ee829918989c22e0 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 26 Apr 2016 16:27:22 +0100 Subject: [PATCH 08/11] [Behat] Fix User edit sentence fetches the first and last name of the User to select from the conten tree --- Features/Context/Users.php | 39 +++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Features/Context/Users.php b/Features/Context/Users.php index 170a59073..cc68404b6 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -10,9 +10,38 @@ namespace EzSystems\PlatformUIBundle\Features\Context; use Behat\Gherkin\Node\TableNode; +use EzSystems\PlatformBehatBundle\Context\RepositoryContext; +use eZ\Publish\API\Repository\Repository; +use eZ\Publish\API\Repository\UserService; +use eZ\Publish\API\Repository\ContentService; class Users extends PlatformUI { + use RepositoryContext; + + /** + * @var eZ\Publish\API\Repository\ContentService + */ + protected $userService; + + /** + * @var eZ\Publish\API\Repository\ContentService + */ + protected $contentService; + + /** + * @injectService $repository @ezpublish.api.repository + * @injectService $userService @ezpublish.api.service.user + * @injectService $contentService @ezpublish.api.service.content + */ + public function __construct(Repository $repository, UserService $userService, ContentService $contentService) + { + parent::__construct(); + $this->setRepository($repository); + $this->userService = $userService; + $this->contentService = $contentService; + } + /** * @When I create a new User * @When I fill a new User fields with: @@ -51,8 +80,12 @@ public function goToUserPage($username) */ public function editUserUser($username) { - $this->clickOnTreePath("$username $username"); - $this->sleep(); //safegaurd for application delays + $user = $this->userService->loadUserByLogin($username); + $userObject = $this->contentService->loadContent($user->getUserId()); + $firstName = $userObject->getFieldValue('first_name'); + $lastName = $userObject->getFieldValue('last_name'); + $this->clickOnTreePath("$firstName $lastName"); + $this->sleep(); //safeguard for application delays $this->waitWhileLoading(); $this->clickActionBar('Edit'); } @@ -62,7 +95,7 @@ public function editUserUser($username) */ public function iSeeUsersPage() { - $this->sleep(); // safegaurd for application delays + $this->sleep(); // safeguard for application delays $this->iSeeTitle('Users'); } From 98a533b742fbbe3dcec65edb555a270eebdaeae2 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 29 Apr 2016 16:52:50 +0100 Subject: [PATCH 09/11] [Behat] minor User sentence typo and Scenario description fix --- Features/Users/users.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Features/Users/users.feature b/Features/Users/users.feature index 2a3377185..05f72209b 100644 --- a/Features/Users/users.feature +++ b/Features/Users/users.feature @@ -69,8 +69,8 @@ Feature: Use the eZ Users field Then I should see error messages @javascript @edge - Scenario: Validate that users have the "Delete" button available + Scenario: Validate "Send to trash" button is replaced with "Delete" when browsing users Given there is a User with name "One" When I go to User "One" page - Then I should not see a "Send to thrash" action bar button + Then I should not see a "Send to trash" action bar button And I should see a "Delete" action bar button From daaff8ea9f637d9e2de7dd8211821124d943b247 Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 2 May 2016 10:36:13 +0100 Subject: [PATCH 10/11] [Behat] Fix User page sentence fetches the first and last name of the User to select from the conten tree --- Features/Context/Users.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Features/Context/Users.php b/Features/Context/Users.php index cc68404b6..ec57f4629 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -69,9 +69,14 @@ public function iCreateUser(TableNode $users = null) */ public function goToUserPage($username) { + $user = $this->userService->loadUserByLogin($username); + $userObject = $this->contentService->loadContent($user->getUserId()); + $firstName = $userObject->getFieldValue('first_name'); + $lastName = $userObject->getFieldValue('last_name'); + $this->iAmOnPage('Users'); $this->waitWhileLoading(); - $this->clickOnTreePath("$username $username"); + $this->clickOnTreePath("$firstName $lastName"); $this->sleep(); //safeguard for application delays } @@ -84,6 +89,7 @@ public function editUserUser($username) $userObject = $this->contentService->loadContent($user->getUserId()); $firstName = $userObject->getFieldValue('first_name'); $lastName = $userObject->getFieldValue('last_name'); + $this->clickOnTreePath("$firstName $lastName"); $this->sleep(); //safeguard for application delays $this->waitWhileLoading(); From 389f07a69fa2b37440e902aa19c87f23747e1f67 Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 2 May 2016 13:27:39 +0100 Subject: [PATCH 11/11] [Behat] Add default User creation and sentence --- Features/Context/Users.php | 65 ++++++++++++++++++++++++++++++++++-- Features/Users/users.feature | 3 +- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/Features/Context/Users.php b/Features/Context/Users.php index ec57f4629..379ad8ca7 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -17,6 +17,9 @@ class Users extends PlatformUI { + const USERGROUP_ROOT_CONTENT_ID = 4; + const DEFAULT_LANGUAGE = 'eng-GB'; + use RepositoryContext; /** @@ -29,6 +32,11 @@ class Users extends PlatformUI */ protected $contentService; + /** + * @var eZ\Publish\API\Repository\Values\User\User + */ + protected $userDefault; + /** * @injectService $repository @ezpublish.api.repository * @injectService $userService @ezpublish.api.service.user @@ -40,6 +48,47 @@ public function __construct(Repository $repository, UserService $userService, Co $this->setRepository($repository); $this->userService = $userService; $this->contentService = $contentService; + $this->userDefault = null; + } + + /** + * Return the default user, if there is none one is created. + */ + protected function getDefaultUser() + { + if (!$this->userDefault) { + $username = $password = 'User#' . uniqid(); + $email = $username . '@ez.no'; + $this->userDefault = $this->createUser($username, $email, $password); + } + + return $this->userDefault; + } + + /** + * Create user inside given User Group. + * + * @param $username username of the user to create + * @param $email email address of user to create + * @param $password account password for user to create + * + * @return eZ\Publish\API\Repository\Values\User\User + */ + protected function createUser($username, $email, $password) + { + $repository = $this->getRepository(); + + $userCreateStruct = $this->userService->newUserCreateStruct( + $username, + $email, + $password, + self::DEFAULT_LANGUAGE + ); + $userCreateStruct->setField('first_name', $username); + $userCreateStruct->setField('last_name', $username); + $parentGroup = $this->userService->loadUserGroup(self::USERGROUP_ROOT_CONTENT_ID); + + return $this->userService->createUser($userCreateStruct, array($parentGroup)); } /** @@ -66,10 +115,15 @@ public function iCreateUser(TableNode $users = null) /** * @When I go to (the) User :username page + * @When I go to a valid User page */ - public function goToUserPage($username) + public function goToUserPage($username = null) { - $user = $this->userService->loadUserByLogin($username); + if ($username) { + $user = $this->userService->loadUserByLogin($username); + } else { + $user = $this->getDefaultUser(); + } $userObject = $this->contentService->loadContent($user->getUserId()); $firstName = $userObject->getFieldValue('first_name'); $lastName = $userObject->getFieldValue('last_name'); @@ -85,7 +139,12 @@ public function goToUserPage($username) */ public function editUserUser($username) { - $user = $this->userService->loadUserByLogin($username); + if ($username) { + $user = $this->userService->loadUserByLogin($username); + } else { + $user = $this->getDefaultUser(); + } + $userObject = $this->contentService->loadContent($user->getUserId()); $firstName = $userObject->getFieldValue('first_name'); $lastName = $userObject->getFieldValue('last_name'); diff --git a/Features/Users/users.feature b/Features/Users/users.feature index 05f72209b..9994efb0f 100644 --- a/Features/Users/users.feature +++ b/Features/Users/users.feature @@ -70,7 +70,6 @@ Feature: Use the eZ Users field @javascript @edge Scenario: Validate "Send to trash" button is replaced with "Delete" when browsing users - Given there is a User with name "One" - When I go to User "One" page + When I go to a valid User page Then I should not see a "Send to trash" action bar button And I should see a "Delete" action bar button