Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

[Behat] Add Behat test for issue EZP-25642 users 'Delete' button #553

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions Features/Context/SubContext/CommonActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ private function goToContentWithPath($path)
$this->clickOnTreePath($path);
}

/**
* @Then I should see a :button action bar button
*
* @param string $buttonText Text of the element in the action bar
*/
public function iShouldSeeActionBarButton($buttonText)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this to an ActionBarContext.

{
$element = $this->getElementByText($buttonText, '.ez-actionbar-container .ez-action', '.action-label');
EzAssertion::assertSingleElement($buttonText, $element, null, 'Action bar button');
}

/**
* @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');
EzAssertion::assertElementNotFound($buttonText, $element, null, 'Action bar button');
}

/**
* @Then I am on the :name location view
*/
Expand Down
115 changes: 112 additions & 3 deletions Features/Context/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,87 @@
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
{
const USERGROUP_ROOT_CONTENT_ID = 4;
const DEFAULT_LANGUAGE = 'eng-GB';

use RepositoryContext;

/**
* @var eZ\Publish\API\Repository\ContentService
*/
protected $userService;

/**
* @var eZ\Publish\API\Repository\ContentService
*/
protected $contentService;

/**
* @var eZ\Publish\API\Repository\Values\User\User
*/
protected $userDefault;

/**
* @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;
$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));
}

/**
* @When I create a new User
* @When I fill a new User fields with:
Expand All @@ -35,13 +113,44 @@ 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 = null)
{
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');

$this->iAmOnPage('Users');
$this->waitWhileLoading();
$this->clickOnTreePath("$firstName $lastName");
$this->sleep(); //safeguard for application delays
}

/**
* @When I edit user :username
*/
public function editUserUser($username)
{
$this->clickOnTreePath("$username $username");
$this->sleep(); //safegaurd for application delays
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');

$this->clickOnTreePath("$firstName $lastName");
$this->sleep(); //safeguard for application delays
$this->waitWhileLoading();
$this->clickActionBar('Edit');
}
Expand All @@ -51,7 +160,7 @@ public function editUserUser($username)
*/
public function iSeeUsersPage()
{
$this->sleep(); // safegaurd for application delays
$this->sleep(); // safeguard for application delays
$this->iSeeTitle('Users');
}

Expand Down
6 changes: 6 additions & 0 deletions Features/Users/users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ 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 "Send to trash" button is replaced with "Delete" when browsing users
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replace "and" with "but", I think it works too. And it sounds a bit better :-)