Fix Customer validation issue and scenarios

This commit is contained in:
michalmarcinkowski 2016-06-02 17:58:34 +02:00
parent 21e7f0d951
commit 28d277b634
8 changed files with 44 additions and 103 deletions

View file

@ -10,15 +10,13 @@ Feature: Adding a new customer
@ui @ui
Scenario: Adding a new customer Scenario: Adding a new customer
Given I want to create a new customer Given I want to create a new customer
When I specify their first name as "Luke" When I specify their email as "l.skywalker@gmail.com"
And I specify their last name as "Skywalker"
And I specify their email as "l.skywalker@gmail.com"
And I add them And I add them
Then I should be notified that it has been successfully created Then I should be notified that it has been successfully created
And the customer "l.skywalker@gmail.com" should appear in the store And the customer "l.skywalker@gmail.com" should appear in the store
@ui @ui
Scenario: Adding a new customer with gender and birthday Scenario: Adding a new customer with full details
Given I want to create a new customer Given I want to create a new customer
When I specify their first name as "Luke" When I specify their first name as "Luke"
And I specify their last name as "Skywalker" And I specify their last name as "Skywalker"

View file

@ -10,15 +10,13 @@ Feature: Adding a new customer account
@ui @javascript @ui @javascript
Scenario: Adding a new customer with an account Scenario: Adding a new customer with an account
Given I want to create a new customer account Given I want to create a new customer account
When I specify their first name as "Luke" When I specify their email as "l.skywalker@gmail.com"
And I specify their last name as "Skywalker"
And I specify their email as "l.skywalker@gmail.com"
And I choose create account option And I choose create account option
And I specify its password as "psw123" And I specify its password as "psw123"
And I add them And I add them
Then I should be notified that it has been successfully created Then I should be notified that it has been successfully created
And the customer "l.skywalker@gmail.com" should appear in the store And the customer "l.skywalker@gmail.com" should appear in the store
And the customer "l.skywalker@gmail.com" should have an account created And this customer should have an account created
@ui @javascript @ui @javascript
Scenario: Creating an account for existing customer Scenario: Creating an account for existing customer

View file

@ -8,12 +8,10 @@ Feature: Customer uniqueness of email validation
Given I am logged in as an administrator Given I am logged in as an administrator
@ui @ui
Scenario: Try to add a new customer with taken email Scenario: Trying to add a new customer with taken email
Given the store has customer "f.baggins@example.com" Given the store has customer "f.baggins@example.com"
And I want to create a new customer And I want to create a new customer
When I specify their first name as "Geralt" When I specify their email as "f.baggins@example.com"
And I specify their last name as "Riv"
And I specify their email as "f.baggins@example.com"
And I try to add it And I try to add it
Then I should be notified that email must be unique Then I should be notified that email must be unique
And there should still be only one customer with email "f.baggins@example.com" And there should still be only one customer with email "f.baggins@example.com"

View file

@ -2,29 +2,11 @@
Feature: Customer validation Feature: Customer validation
In order to avoid making mistakes when managing customers In order to avoid making mistakes when managing customers
As an Administrator As an Administrator
I want to be prevented from adding it without specify required fields I want to be prevented from adding it without specifying required fields
Background: Background:
Given I am logged in as an administrator Given I am logged in as an administrator
@ui
Scenario: Trying to add a new customer without a first name
Given I want to create a new customer
When I specify their last name as "Skywalker"
And I specify their email as "l.skywalker@gmail.com"
And I try to add it
Then I should be notified that first name is required
And the customer with email "l.skywalker@gmail.com" should not appear in the store
@ui
Scenario: Trying to add a new customer without a last name
Given I want to create a new customer
When I specify their first name as "Luke"
And I specify their email as "l.skywalker@gmail.com"
And I try to add it
Then I should be notified that last name is required
And the customer with email "l.skywalker@gmail.com" should not appear in the store
@ui @ui
Scenario: Trying to add a new customer without an email Scenario: Trying to add a new customer without an email
Given I want to create a new customer Given I want to create a new customer
@ -32,48 +14,29 @@ Feature: Customer validation
And I specify their last name as "Skywalker" And I specify their last name as "Skywalker"
And I try to add it And I try to add it
Then I should be notified that email is required Then I should be notified that email is required
And the customer with email "l.skywalker@gmail.com" should not appear in the store
@ui @ui
Scenario: Trying to remove first name from existing customer Scenario: Trying to specify too short first name for an existing customer
Given the store has customer "l.skywalker@gmail.com" with first name "Luke"
And I want to edit the customer "l.skywalker@gmail.com"
When I remove its first name
And I try to save my changes
Then I should be notified that first name is required
And the customer "l.skywalker@gmail.com" should still have first name "Luke"
@ui
Scenario: Trying to specify too short first name for existing customer
Given the store has customer "l.skywalker@gmail.com" Given the store has customer "l.skywalker@gmail.com"
And I want to edit the customer "l.skywalker@gmail.com" And I want to edit this customer
When I specify their first name as "L" When I specify their first name as "L"
And I try to save my changes And I try to save my changes
Then I should be notified that first name should be at least 2 characters long Then I should be notified that first name should be at least 2 characters long
And the customer "l.skywalker@gmail.com" should still have empty first name And the customer "l.skywalker@gmail.com" should still have an empty first name
@ui @ui
Scenario: Trying to specify too short last name for existing customer Scenario: Trying to specify too short last name for an existing customer
Given the store has customer "l.skywalker@gmail.com" with first name "Luke" Given the store has customer "l.skywalker@gmail.com" with first name "Luke"
And I want to edit the customer "l.skywalker@gmail.com" And I want to edit this customer
When I specify their last name as "S" When I specify their last name as "S"
And I try to save my changes And I try to save my changes
Then I should be notified that last name should be at least 2 characters long Then I should be notified that last name should be at least 2 characters long
And the customer "l.skywalker@gmail.com" should still have empty last name And the customer "l.skywalker@gmail.com" should still have an empty last name
@ui @ui
Scenario: Trying to remove last name from existing customer Scenario: Trying to remove email from an existing customer
Given the store has customer "l.skywalker@gmail.com" with last name "Skywalker"
Given I want to edit the customer "l.skywalker@gmail.com"
When I remove its last name
And I try to save my changes
Then I should be notified that last name is required
And the customer "l.skywalker@gmail.com" should still have last name "Skywalker"
@ui
Scenario: Trying to remove email from existing customer
Given the store has customer "l.skywalker@gmail.com" Given the store has customer "l.skywalker@gmail.com"
Given I want to edit the customer "l.skywalker@gmail.com" And I want to edit this customer
When I remove its email When I remove its email
And I try to save my changes And I try to save my changes
Then I should be notified that email is required Then I should be notified that email is required
@ -82,9 +45,7 @@ Feature: Customer validation
@ui @ui
Scenario: Trying to create customer with wrong email format Scenario: Trying to create customer with wrong email format
Given I want to create a new customer Given I want to create a new customer
When I specify their first name as "Luke" When I specify their email as "wrongemail"
And I specify their last name as "Skywalker"
And I specify their email as "wrongemail"
And I try to add it And I try to add it
Then I should be notified that email is not valid Then I should be notified that email is not valid
And the customer with email "wrongemail" should not appear in the store And the customer with email "wrongemail" should not appear in the store

View file

@ -8,11 +8,22 @@ Feature: Editing a customer
Given I am logged in as an administrator Given I am logged in as an administrator
@ui @ui
Scenario: Editing a customer Scenario: Changing first and last name of an existing customer
Given the store has customer "Frodo Baggins" with email "f.baggins@example.com" Given the store has customer "Frodo Baggins" with email "f.baggins@example.com"
And I want to edit the customer "f.baggins@example.com" And I want to edit this customer
When I specify his first name as "Jon" When I specify his first name as "Jon"
And I specify his last name as "Snow" And I specify his last name as "Snow"
And I save my changes And I save my changes
Then I should be notified that it has been successfully edited Then I should be notified that it has been successfully edited
And this customer with name "Jon Snow" should appear in the store And this customer with name "Jon Snow" should appear in the store
@ui
Scenario: Removing first and last name from an existing customer
Given the store has customer "Luke Skywalker" with email "l.skywalker@gmail.com"
And I want to edit this customer
When I remove its first name
And I remove its last name
And I save my changes
Then I should be notified that it has been successfully edited
And this customer should have an empty first name
And this customer should have an empty last name

View file

@ -126,6 +126,7 @@ final class ManagingCustomersContext implements Context
} }
/** /**
* @Given /^I want to edit (this customer)$/
* @Given I want to edit the customer :customer * @Given I want to edit the customer :customer
*/ */
public function iWantToEditThisCustomer(CustomerInterface $customer) public function iWantToEditThisCustomer(CustomerInterface $customer)
@ -194,7 +195,7 @@ final class ManagingCustomersContext implements Context
{ {
Assert::true( Assert::true(
$this->createPage->checkValidationMessageFor($elementName, sprintf('Please enter your %s.', $elementName)), $this->createPage->checkValidationMessageFor($elementName, sprintf('Please enter your %s.', $elementName)),
sprintf('Customer % should be required.', $elementName) sprintf('Customer %s should be required.', $elementName)
); );
} }
@ -206,9 +207,9 @@ final class ManagingCustomersContext implements Context
Assert::true( Assert::true(
$this->updatePage->checkValidationMessageFor( $this->updatePage->checkValidationMessageFor(
$elementName, $elementName,
sprintf('%s must be %s', $elementName, $validationMessage) sprintf('%s must be %s.', ucfirst($elementName), $validationMessage)
), ),
sprintf('Customer % should be %s.', $elementName, $validationMessage) sprintf('Customer %s should be %s.', $elementName, $validationMessage)
); );
} }
@ -234,30 +235,17 @@ final class ManagingCustomersContext implements Context
} }
/** /**
* @Then the customer :customer should still have first name :firstName * @Then /^(this customer) should have an empty first name$/
* @Then the customer :customer should still have an empty first name
*/ */
public function theCustomerShouldStillHaveFirstName(CustomerInterface $customer, $firstName) public function theCustomerShouldStillHaveAnEmptyFirstName(CustomerInterface $customer)
{
$this->updatePage->open(['id' => $customer->getId()]);
Assert::eq(
$firstName,
$this->updatePage->getFirstName(),
sprintf('Customer should have first name %s, but it does not.', $firstName)
);
}
/**
* @Then the customer :customer should still have empty first name
*/
public function theCustomerShouldStillHaveEmptyFirstName(CustomerInterface $customer)
{ {
$this->updatePage->open(['id' => $customer->getId()]); $this->updatePage->open(['id' => $customer->getId()]);
Assert::eq( Assert::eq(
'', '',
$this->updatePage->getFirstName(), $this->updatePage->getFirstName(),
'Customer should have empty first name, but it does not.' 'Customer should have an empty first name, but it does not.'
); );
} }
@ -270,30 +258,17 @@ final class ManagingCustomersContext implements Context
} }
/** /**
* @Then the customer :customer should still have last name :lastName * @Then /^(this customer) should have an empty last name$/
* @Then the customer :customer should still have an empty last name
*/ */
public function theCustomerShouldStillHaveLastName(CustomerInterface $customer, $lastName) public function theCustomerShouldStillHaveAnEmptyLastName(CustomerInterface $customer)
{
$this->updatePage->open(['id' => $customer->getId()]);
Assert::eq(
$lastName,
$this->updatePage->getLastName(),
sprintf('Customer should have last name %s, but it does not.', $lastName)
);
}
/**
* @Then the customer :customer should still have empty last name
*/
public function theCustomerShouldStillHaveEmptyLastName(CustomerInterface $customer)
{ {
$this->updatePage->open(['id' => $customer->getId()]); $this->updatePage->open(['id' => $customer->getId()]);
Assert::eq( Assert::eq(
'', '',
$this->updatePage->getLastName(), $this->updatePage->getLastName(),
'Customer should have empty last name, but it does not.' 'Customer should have an empty last name, but it does not.'
); );
} }

View file

@ -133,7 +133,7 @@ class Configuration implements ConfigurationInterface
->children() ->children()
->arrayNode('default') ->arrayNode('default')
->prototype('scalar')->end() ->prototype('scalar')->end()
->defaultValue(['sylius', 'sylius_customer_profile']) ->defaultValue(['sylius'])
->end() ->end()
->arrayNode('profile') ->arrayNode('profile')
->prototype('scalar')->end() ->prototype('scalar')->end()

View file

@ -37,7 +37,7 @@
<option name="minMessage">sylius.customer.first_name.min</option> <option name="minMessage">sylius.customer.first_name.min</option>
<option name="max">255</option> <option name="max">255</option>
<option name="maxMessage">sylius.customer.first_name.max</option> <option name="maxMessage">sylius.customer.first_name.max</option>
<option name="groups">sylius_customer_profile</option> <option name="groups">sylius</option>
</constraint> </constraint>
</property> </property>
<property name="lastName"> <property name="lastName">
@ -50,7 +50,7 @@
<option name="minMessage">sylius.customer.last_name.min</option> <option name="minMessage">sylius.customer.last_name.min</option>
<option name="max">255</option> <option name="max">255</option>
<option name="maxMessage">sylius.customer.last_name.max</option> <option name="maxMessage">sylius.customer.last_name.max</option>
<option name="groups">sylius_customer_profile</option> <option name="groups">sylius</option>
</constraint> </constraint>
</property> </property>
<property name="gender"> <property name="gender">