Skip to content

Commit

Permalink
[Shop][Account] Fixes after PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed May 25, 2016
1 parent 49a6d45 commit 9c1e7ca
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 36 deletions.
4 changes: 2 additions & 2 deletions features/account/customer_account/changing_password.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Feature: Changing a customer password
And I am logged in as "francis@underwood.com"

@ui
Scenario: Changing my email
Scenario: Changing my password
Given I want to change my password
And I change password from "whitehouse" to "blackhouse"
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
@@ -1,5 +1,5 @@
@customer_account
Feature: Changing a customer password
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
Expand All @@ -12,26 +12,26 @@ Feature: Changing a customer password
@ui
Scenario: Trying to change my password with a wrong current password
Given I want to change my password
And I specify the current password as "greenhouse"
When I specify the current password as "greenhouse"
And I specify the new password as "blackhouse"
And I specify the confirmation 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
And I specify the current password as "whitehouse"
When I specify the current password as "whitehouse"
And I specify the new password as "blackhouse"
And I specify the confirmation password as "greenhouse"
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
And I specify the current password as "whitehouse"
When I specify the current password as "whitehouse"
And I specify the new password as "fu"
And I specify the confirmation 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
Expand Up @@ -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
Expand Up @@ -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"
12 changes: 6 additions & 6 deletions src/Sylius/Behat/Context/Ui/Shop/AccountContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ public function myEmailShouldBe($email)
*/
public function iShouldBeNotifiedThatElementIsRequired($element)
{
$this->assertFieldValidationMessage($this->profileUpdatePage, $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($this->profileUpdatePage, $element, sprintf('This %s is invalid.', $element));
$this->assertFieldValidationMessage($this->profileUpdatePage, str_replace(' ', '_', $element), sprintf('This %s is invalid.', $element));
}

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ public function iSpecifyTheNewPasswordAs($password)
}

/**
* @Given I specify the confirmation password as :password
* @Given I confirm this password as :password
*/
public function iSpecifyTheConfirmationPasswordAs($password)
{
Expand All @@ -222,23 +222,23 @@ public function iSpecifyTheConfirmationPasswordAs($password)
*/
public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne()
{
$this->assertFieldValidationMessage($this->changePasswordPage, 'current password', 'Provided password is different than the current one.');
$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');
$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.');
$this->assertFieldValidationMessage($this->changePasswordPage, 'new_password', 'Password must be at least 4 characters long.');
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Sylius/Behat/Page/Shop/Account/ChangePasswordPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function getRouteName()
*/
public function specifyCurrentPassword($password)
{
$this->getElement('current password')->setValue($password);
$this->getElement('current_password')->setValue($password);
}

/**
* @param string $password
*/
public function specifyNewPassword($password)
{
$this->getElement('new password')->setValue($password);
$this->getElement('new_password')->setValue($password);
}

/**
Expand All @@ -56,12 +56,12 @@ public function specifyConfirmationPassword($password)
*/
public function checkValidationMessageFor($element, $message)
{
$foundedElement = $this->getFieldElement($element);
if (null === $foundedElement) {
$foundElement = $this->getFieldElement($element);
if (null === $foundElement) {
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.pointing');
}

return $message === $foundedElement->find('css', '.form-error')->getText();
return $message === $foundElement->find('css', '.form-error')->getText();
}

/**
Expand All @@ -70,8 +70,8 @@ public function checkValidationMessageFor($element, $message)
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'current password' => '#sylius_user_change_password_currentPassword',
'new password' => '#sylius_user_change_password_newPassword_first',
'current_password' => '#sylius_user_change_password_currentPassword',
'new_password' => '#sylius_user_change_password_newPassword_first',
'confirmation' => '#sylius_user_change_password_newPassword_second',
]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Page/Shop/Account/ProfileUpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function checkValidationMessageFor($element, $message)
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'first name' => '#sylius_customer_profile_firstName',
'last name' => '#sylius_customer_profile_lastName',
'first_name' => '#sylius_customer_profile_firstName',
'last_name' => '#sylius_customer_profile_lastName',
'email' => '#sylius_customer_profile_email',
]);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Sylius/Bundle/UserBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
<parameter key="sylius.user.validator.unique_registered_user.class">Sylius\Bundle\UserBundle\Validator\Constraints\RegisteredUserValidator</parameter>
<parameter key="sylius.user.validator.customer_initializer.class">Sylius\Bundle\UserBundle\Validator\Initializer\CustomerInitializer</parameter>

<parameter key="sylius.form.type.user_change_password.date_class">Sylius\Bundle\UserBundle\Form\Model\ChangePassword</parameter>
<parameter key="sylius.form.type.user_change_password.validation_groups" type="collection">
<parameter>sylius</parameter>
</parameter>
<parameter key="sylius.form.model.change_password.class">Sylius\Bundle\UserBundle\Form\Model\ChangePassword</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -178,7 +175,7 @@
<tag name="form.type" alias="sylius_user_reset_password" />
</service>
<service id="sylius.form.type.user_change_password" class="%sylius.form.type.user_change_password.class%">
<argument type="string">%sylius.form.type.user_change_password.date_class%</argument>
<argument type="string">%sylius.form.model.change_password.class%</argument>
<argument type="collection">
<argument>sylius</argument>
</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\UserBundle\Form\Model\ChangePassword;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

Expand All @@ -21,6 +22,11 @@
*/
class UserChangePasswordTypeSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(ChangePassword::class, ['sylius']);
}

function it_extends_abstract_type()
{
$this->shouldHaveType(AbstractType::class);
Expand Down

0 comments on commit 9c1e7ca

Please sign in to comment.