Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shop][Account] Changing customer password #5094

Merged
merged 5 commits into from
May 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions features/account/customer_account/changing_password.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@customer_account
Feature: Changing a customer password
In order to enhance the security of my account
As a Customer
I want to be able to change my password

Background:
Given the store operates on a single channel in "France"
And there is a customer "Francis Underwood" identified by an email "francis@underwood.com" and a password "whitehouse"
And I am logged in as "francis@underwood.com"

@ui
Scenario: Changing my password
Given I want to change my password
When I change password from "whitehouse" to "blackhouse"
And I save my changes
Then I should be notified that my password has been successfully changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@customer_account
Feature: Customer password validation
In order to avoid making mistakes when changing my password
As a Customer
I want to be prevented from entering incorrect password

Background:
Given the store operates on a single channel in "France"
And there is a customer account "francis@underwood.com" identified by "whitehouse"
And I am logged in as "francis@underwood.com"

@ui
Scenario: Trying to change my password with a wrong current password
Given I want to change my password
When I specify the current password as "greenhouse"
And I specify the new password as "blackhouse"
And I confirm this password as "blackhouse"
And I try to save my changes
Then I should be notified that provided password is different than the current one

@ui
Scenario: Trying to change my password with a wrong confirmation password2
Given I want to change my password
When I specify the current password as "whitehouse"
And I specify the new password as "blackhouse"
And I confirm this password as "greenhouse"
And I try to save my changes
Then I should be notified that the entered passwords do not match

@ui
Scenario: Trying to change my password with a too short password
Given I want to change my password
When I specify the current password as "whitehouse"
And I specify the new password as "fu"
And I confirm this password as "fu"
And I try to save my changes
Then I should be notified that the password should be at least 4 characters long
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@customer_account
Feature: Customer profile validation
In order to avoid making mistakes when changing my personal information
As a logged user
I want to be prevented from changing fields to incorrect values
As a Customer
I want to be prevented from entering incorrect values

Background:
Given the store operates on a single channel in "France"
Expand All @@ -13,39 +13,39 @@ Feature: Customer profile validation
@ui
Scenario: Trying to remove my first name
Given I want to modify my profile
And I remove the first name
When I remove the first name
And I try to save my changes
Then I should be notified that the first name is required
And my name should still be "Francis Underwood"

@ui
Scenario: Trying to remove my last name
Given I want to modify my profile
And I remove the last name
When I remove the last name
And I try to save my changes
Then I should be notified that the last name is required
And my name should still be "Francis Underwood"

@ui
Scenario: Trying to remove my email
Given I want to modify my profile
And I remove the email
When I remove the email
And I try to save my changes
Then I should be notified that the email is required
And my email should still be "francis@underwood.com"

@ui
Scenario: Trying to change my email to an existing value
Given I want to modify my profile
And I specify the email as "claire@underwood.com"
When I specify the email as "claire@underwood.com"
And I try to save my changes
Then I should be notified that the email is already used
And my email should still be "francis@underwood.com"

@ui
Scenario: Trying to change my email to an invalid value
Given I want to modify my profile
And I specify the email as "francisunderwood"
When I specify the email as "francisunderwood"
And I try to save my changes
Then I should be notified that the email is invalid
And my email should still be "francis@underwood.com"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@customer_account
Feature: Editing a customer profile
In order to manage my personal information
As a logged user
As a Customer
I want to be able to edit my name and email

Background:
Expand All @@ -12,7 +12,7 @@ Feature: Editing a customer profile
@ui
Scenario: Changing my first name and last name
Given I want to modify my profile
And I specify the first name as "Will"
When I specify the first name as "Will"
And I specify the last name as "Conway"
And I save my changes
Then I should be notified that it has been successfully edited
Expand All @@ -21,7 +21,7 @@ Feature: Editing a customer profile
@ui
Scenario: Changing my email
Given I want to modify my profile
And I specify the email as "frank@underwood.com"
When I specify the email as "frank@underwood.com"
And I save my changes
Then I should be notified that it has been successfully edited
And my email should be "frank@underwood.com"
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Setup/CustomerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function thereIsDisabledCustomerAccountWithPassword($email, $password)

/**
* @Given there is enabled customer account :email with password :password
* @Given there is a customer account :email identified by :password
*/
public function theStoreHasEnabledCustomerAccountWithPassword($email, $password)
{
Expand Down
115 changes: 100 additions & 15 deletions src/Sylius/Behat/Context/Ui/Shop/AccountContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\PageInterface;
use Sylius\Behat\Page\Shop\Account\ChangePasswordPageInterface;
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface;
use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
Expand All @@ -23,11 +25,6 @@
*/
final class AccountContext implements Context
{
/**
* @var NotificationCheckerInterface
*/
private $notificationChecker;

/**
* @var DashboardPageInterface
*/
Expand All @@ -37,20 +34,33 @@ final class AccountContext implements Context
* @var ProfileUpdatePageInterface
*/
private $profileUpdatePage;

/**
* @var ChangePasswordPageInterface
*/
private $changePasswordPage;

/**
* @var NotificationCheckerInterface
*/
private $notificationChecker;

/**
* @param NotificationCheckerInterface $notificationChecker
* @param DashboardPageInterface $dashboardPage
* @param ProfileUpdatePageInterface $profileUpdatePage
* @param ChangePasswordPageInterface $changePasswordPage
* @param NotificationCheckerInterface $notificationChecker
*/
public function __construct(
NotificationCheckerInterface $notificationChecker,
DashboardPageInterface $dashboardPage,
ProfileUpdatePageInterface $profileUpdatePage
ProfileUpdatePageInterface $profileUpdatePage,
ChangePasswordPageInterface $changePasswordPage,
NotificationCheckerInterface $notificationChecker
) {
$this->notificationChecker = $notificationChecker;
$this->dashboardPage = $dashboardPage;
$this->profileUpdatePage = $profileUpdatePage;
$this->changePasswordPage = $changePasswordPage;
$this->notificationChecker = $notificationChecker;
}

/**
Expand Down Expand Up @@ -138,34 +148,109 @@ public function myEmailShouldBe($email)
*/
public function iShouldBeNotifiedThatElementIsRequired($element)
{
$this->assertFieldValidationMessage($element, sprintf('Please enter your %s.', $element));
$this->assertFieldValidationMessage($this->profileUpdatePage, str_replace(' ', '_', $element), sprintf('Please enter your %s.', $element));
}

/**
* @Then /^I should be notified that the ([^"]+) is invalid$/
*/
public function iShouldBeNotifiedThatElementIsInvalid($element)
{
$this->assertFieldValidationMessage($element, sprintf('This %s is invalid.', $element));
$this->assertFieldValidationMessage($this->profileUpdatePage, str_replace(' ', '_', $element), sprintf('This %s is invalid.', $element));
}

/**
* @Then I should be notified that the email is already used
*/
public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed()
{
$this->assertFieldValidationMessage('email', 'This email is already used.');
$this->assertFieldValidationMessage($this->profileUpdatePage, 'email', 'This email is already used.');
}

/**
* @Given /^I want to change my password$/
*/
public function iWantToChangeMyPassword()
{
$this->changePasswordPage->open();
}

/**
* @Given I change password from :oldPassword to :newPassword
*/
public function iChangePasswordTo($oldPassword, $newPassword)
{
$this->iSpecifyTheCurrentPasswordAs($oldPassword);
$this->iSpecifyTheNewPasswordAs($newPassword);
$this->iSpecifyTheConfirmationPasswordAs($newPassword);
}

/**
* @Then I should be notified that my password has been successfully changed
*/
public function iShouldBeNotifiedThatMyPasswordHasBeenSuccessfullyChanged()
{
$this->notificationChecker->checkNotification('has been changed successfully!', NotificationType::success());
}

/**
* @Given I specify the current password as :password
*/
public function iSpecifyTheCurrentPasswordAs($password)
{
$this->changePasswordPage->specifyCurrentPassword($password);
}

/**
* @Given I specify the new password as :password
*/
public function iSpecifyTheNewPasswordAs($password)
{
$this->changePasswordPage->specifyNewPassword($password);
}

/**
* @Given I confirm this password as :password
*/
public function iSpecifyTheConfirmationPasswordAs($password)
{
$this->changePasswordPage->specifyConfirmationPassword($password);
}

/**
* @Then I should be notified that provided password is different than the current one
*/
public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne()
{
$this->assertFieldValidationMessage($this->changePasswordPage, 'current_password', 'Provided password is different than the current one.');
}

/**
* @Then I should be notified that the entered passwords do not match
*/
public function iShouldBeNotifiedThatTheEnteredPasswordsDoNotMatch()
{
$this->assertFieldValidationMessage($this->changePasswordPage, 'new_password', 'The entered passwords don\'t match');
}

/**
* @Then I should be notified that the password should be at least 4 characters long
*/
public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong()
{
$this->assertFieldValidationMessage($this->changePasswordPage, 'new_password', 'Password must be at least 4 characters long.');
}

/**
* @param PageInterface $page
* @param string $element
* @param string $expectedMessage
*/
private function assertFieldValidationMessage($element, $expectedMessage)
private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage)
{
Assert::true(
$this->profileUpdatePage->checkValidationMessageFor($element, $expectedMessage),
sprintf('The %s should be required.', $element)
$page->checkValidationMessageFor($element, $expectedMessage),
sprintf('There should be a message: "%s".', $expectedMessage)
);
}
}
Loading