diff --git a/Features/Context/Users.php b/Features/Context/Users.php index ec57f4629..d782c0dd6 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/Stories/FieldTypes/EmailFieldType.feature b/Features/Stories/FieldTypes/EmailFieldType.feature new file mode 100644 index 000000000..9fa3a606b --- /dev/null +++ b/Features/Stories/FieldTypes/EmailFieldType.feature @@ -0,0 +1,110 @@ +Feature: Test the validations done on fields from PlatformUI - Email fieldtype + In order to validate the e-mail address fieldtype + As an Editor user + I need to be able to create and update content with e-mail address fieldtype + + Background: + Given I am logged in as an Editor in PlatformUI + + ## + # Validate the existence of expected fields from a field type when creating a content + ## + @javascript + Scenario: A Content of a Content Type that has an e-mail address fieldtype must have an email field + Given a Content Type with an "e-mail address" Field exists + When I create a content of this type + Then I should see an "e-mail address" field + + @javascript + Scenario: When editing a Content the label of an e-mail address field must have the same name than field type from the respective Content Type + Given a Content Type with an "e-mail address" with field definition name "Email Contact" exists + When I create a content of this type + Then I should see an "Email Contact" label related with the "e-mail address" field + + @javascript + Scenario: The label of a required e-mail address field of a Content must be marked as required + Given a Content Type with a required "e-mail address" with field definition name "Required" exists + When I create a content of this type + Then the "Required" field should be marked as required + + ## + # Creating Content using a Content Type that has an e-mail address Field Type + ## + @javascript + Scenario: Creating a valid e-mail address Field works + Given a Content Type with an "e-mail address" Field exists + When I create a content of this type + And I set "paul@acme.com" as the Field Value + And I publish the content + Then the Content is successfully published + + @javascript + Scenario: Creating an invalid e-mail address Field fails validation when using an invalid email + Given a Content Type with an "e-mail address" Field exists + When I create a content of this type + And I set "paul.acme.com" as the Field Value + And I publish the content + Then Publishing fails with validation error message "The value should be a valid email address" + + @javascript + Scenario: Creating an e-mail address Field with an empty value works + Given a Content Type with an "e-mail address" Field exists + When I create a content of this type + And I set an empty value as the Field Value + And I publish the content + Then the Content is successfully published + + @javascript + Scenario: Creating a required e-mail address Field fails validation when using an empty value + Given a Content Type with a required "e-mail address" with field definition name "Required" exists + When I create a content of this type + And I set an empty value as the Field Value + And I publish the content + Then Publishing fails with validation error message "This field is required" + + ## + # Update Content using a Content Type that has an e-mail address Field Type + ## + @javascript + Scenario: Updating to a valid e-mail address Field works + Given a Content Type with an "e-mail address" Field exists + And a Content of this type exists + When I edit this content + And I set "ana@acme.com" as the Field Value + And I publish the content + Then the Content is successfully published + + @javascript + Scenario: Updating an invalid e-mail address Field fails validation when using an invalid email + Given a Content Type with an "e-mail address" Field exists + And a Content of this type exists + When I edit this content + And I set "invalidEmail" as the Field Value + And I publish the content + Then Publishing fails with validation error message "The value should be a valid email address" + + @javascript + Scenario: Updating a required e-mail address Field fails validation when using an empty value + Given a Content Type with a required "e-mail address" with field definition name "Required" exists + And a Content of this type exists + When I edit this content + And I set an empty value as the Field Value + And I publish the content + Then Publishing fails with validation error message "This field is required" + + ## + # Viewing content that has an email fieldtype + ## + @javascript + Scenario: Viewing a Content that has an e-mail address fieldtype should show the expected value when the value is plausible + Given a Content Type with an "e-mail address" Field exists + And a Content of this type exists with "e-mail address" Field Value set to "paul@acme.com" + When I view this Content + Then I should see a field with value "paul@acme.com" + + @javascript + Scenario: Viewing a Content that has an e-mail address fieldtype should return "This field is empty" when the value is empty + Given a Content Type with an "e-mail address" Field exists + And a Content of this type exists with "e-mail address" Field Value set to empty + When I view this Content + Then I should see a field with value "This field is empty" 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