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

Commit

Permalink
[Behat] Add default User creation and sentence
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel committed May 2, 2016
1 parent daaff8e commit d61cd85
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
65 changes: 62 additions & 3 deletions Features/Context/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class Users extends PlatformUI
{
const USERGROUP_ROOT_CONTENT_ID = 4;
const DEFAULT_LANGUAGE = 'eng-GB';

use RepositoryContext;

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

/**
Expand All @@ -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');
Expand All @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions Features/Users/users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d61cd85

Please sign in to comment.