Skip to content

Commit

Permalink
Merge pull request Sylius#7406 from Arminek/order-shipping-method-int…
Browse files Browse the repository at this point in the history
…egirty-validation

[Checkout] Order shipping method integrity validation
  • Loading branch information
pjedrzejewski committed Feb 9, 2017
2 parents 87ef6bd + 6abb1e8 commit 2c6920a
Show file tree
Hide file tree
Showing 39 changed files with 1,057 additions and 36 deletions.
@@ -0,0 +1,24 @@
@checkout
Feature: Order promotions integrity
In order to have valid promotions applied on my order
As a Customer
I want to have information about promotion changes on my order

Background:
Given the store operates on a single channel in "United States"
And the store allows paying offline
And the store ships everywhere for free
And the store has a product "PHP T-Shirt" priced at "$100.00"
And there is a promotion "Christmas sale"
And this promotion gives "$10.00" discount to every order
And this promotion expires tomorrow
And I am a logged in customer

@ui
Scenario: Preventing customer from completing checkout with already expired promotion
Given I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Offline" payment method
And this promotion has already expired
When I confirm my order
Then I should be informed that this promotion is no longer applied
And I should not see the thank you page
@@ -0,0 +1,54 @@
@paying_for_order
Feature: Inform customer about any order total changes during checkout process
In order inform the customer about any changes that affect order total
As a Customer
I want to be able prevent placing order with invalid order total

Background:
Given the store operates on a single channel in "United States"
And the store has "NA VAT" tax rate of 23% for "Clothes" within the "US" zone
And the store has a product "PHP T-Shirt" priced at "$19.99"
And it belongs to "Clothes" tax category
And the store ships everywhere for free
And the store allows paying offline

@ui
Scenario: Inform customer about order total change due to product price change
Given I am a logged in customer
And I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Offline" payment method
And this product price has been changed to "$25.00"
When I confirm my order
Then I should be informed that order total has been changed
And I should not see the thank you page

@ui
Scenario: Be able to confirm order after information appears
Given I am a logged in customer
And I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Offline" payment method
And this product price has been changed to "$25.00"
And I have confirmed order
When I confirm my order
Then I should see the thank you page

@ui
Scenario: Inform customer about order total change due to tax change
Given I am a logged in customer
And I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Offline" payment method
And the "NA VAT" tax rate has changed to 10%
When I confirm my order
Then I should be informed that order total has been changed
And I should not see the thank you page

@ui
Scenario: Inform customer about order total change due to shipping method fee change
Given the store has "UPS" shipping method with "$20.00" fee
And I added product "PHP T-Shirt" to the cart
And I have completed addressing step with email "guest@example.com" and "United States" based shipping address
And I have proceeded order with "UPS" shipping method and "Offline" payment
And the shipping fee for "UPS" shipping method has been changed to "$30.00"
When I confirm my order
Then I should be informed that order total has been changed
And I should not see the thank you page
@@ -0,0 +1,21 @@
@paying_for_order
Feature: Order payment method integrity
In order to have valid payment method
As a Customer
I want to have valid order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
And the store allows paying offline
And I am a logged in customer

@ui
Scenario: Preventing customer from completing checkout with no longer available payment method
Given I have product "PHP T-Shirt" in the cart
And I have proceeded selecting "Offline" payment method
But this payment method has been disabled
When I confirm my order
Then I should be informed that this payment method has been disabled
And I should not see the thank you page
21 changes: 21 additions & 0 deletions features/checkout/product_integrity_validation.feature
@@ -0,0 +1,21 @@
@paying_for_order
Feature: Order products integrity
In order to have valid products
As a Customer
I want to have enabled products in my order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
And the store allows paying offline
And I am a logged in customer

@ui
Scenario: Preventing customer from completing checkout with no longer available products
Given I have product "PHP T-Shirt" in the cart
And I have proceeded selecting "Offline" payment method
But this product has been disabled
When I confirm my order
Then I should be informed that this product has been disabled
And I should not see the thank you page
@@ -0,0 +1,50 @@
@checkout
Feature: Order shipping method integrity
In order to have valid shipping method on my order
As a Visitor
I want to have valid order

Background:
Given the store operates on a single channel in "United States"
And the store has "Heavy stuff" shipping category
And the store has "Small stuff" shipping category
And the store allows paying offline
And the store allows shipping with "DHL"
And this shipping method requires that all units match to "Heavy stuff" shipping category
And the store allows shipping with "FedEx"
And this shipping method requires at least one unit matches to "Small stuff" shipping category
And the store has a product "Westworld host" priced at "$12.54"
And this product belongs to "Heavy stuff" shipping category
And the store has a product "T-shirt Breaking Bad" priced at "$12.54"
And this product belongs to "Small stuff" shipping category

@ui
Scenario: Validate shipping method after adding item which does not fit shipping method requirements
Given I added product "Westworld host" to the cart
And I have completed addressing step with email "guest@example.com" and "United States" based shipping address
And I have proceeded order with "DHL" shipping method and "Offline" payment
When I add product "T-shirt Breaking Bad" to the cart
And I want to complete checkout
Then I should not be able to confirm order because products does not fit "DHL" requirements
And I should not see the thank you page

@ui @javascript
Scenario: Validate shipping method after removing item which fits shipping method requirements
Given I added product "T-shirt Breaking Bad" to the cart
And I added product "Westworld host" to the cart
And I have completed addressing step with email "guest@example.com" and "United States" based shipping address
And I have proceeded order with "FedEx" shipping method and "Offline" payment
When I remove product "T-shirt Breaking Bad" from the cart
And I want to complete checkout
Then I should not be able to confirm order because products does not fit "FedEx" requirements
And I should not see the thank you page

@ui
Scenario: Validate shipping method after administrator changes shipping method requirements
Given I added product "Westworld host" to the cart
And I have completed addressing step with email "guest@example.com" and "United States" based shipping address
And I have proceeded order with "DHL" shipping method and "Offline" payment
And product "Westworld host" shipping category has been changed to "Small stuff"
When I want to complete checkout
Then I should not be able to confirm order because products does not fit "DHL" requirements
And I should not see the thank you page
Expand Up @@ -26,3 +26,11 @@ Feature: Reverting previously applied discount on cart
When I change "PHP Mug" quantity to 4
Then product "PHP Mug" price should not be decreased
And my cart total should be "$80.00"

@ui
Scenario: Reverting discount applied from total item cost based promotion
Given this promotion gives "10%" off on every product when the item total is at least "$100.00"
And I have 8 products "PHP Mug" in the cart
When I change "PHP Mug" quantity to 4
Then product "PHP Mug" price should not be decreased
And my cart total should be "$80.00"
Expand Up @@ -13,28 +13,27 @@ Feature: Apply correct taxes based on customer data
And the store has "VAT" tax rate of 10% for "Clothes" for the rest of the world
And the store has a product "PHP T-Shirt" priced at "$100.00"
And it belongs to "Clothes" tax category
And there is user "john@example.com" identified by "password123", with "Germany" as shipping country
And I am logged in as "john@example.com"
And there is user "john@example.com" with "Germany" as shipping country

@todo
Scenario: Proper taxes for taxed product
@ui
Scenario: Proper taxes for logged in Customer
Given I am logged in as "john@example.com"
When I add product "PHP T-Shirt" to the cart
Then my cart total should be "$110.00"
And my cart taxes should be "$10.00"

@todo
@ui
Scenario: Proper taxes after specifying shipping address
Given I am a logged in customer
When I add product "PHP T-Shirt" to the cart
And I log in as "john@example.com" with "password123" password
And I proceed without selecting shipping address
Then my cart total should be "$110.00"
And my cart taxes should be "$10.00"
And I specified the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
Then my cart total should be "$123.00"
And my cart taxes should be "$23.00"

@todo
Scenario: Proper taxes for logged in Customer with already specified shipping address
@ui
Scenario: Proper taxes after specifying shipping address
Given I am a logged in customer
And my default shipping address is "Germany"
When I add product "PHP T-Shirt" to the cart
And I proceed without selecting shipping address
And I specified the shipping address as "Ankh Morpork", "Frost Alley", "90210", "Germany" for "Jon Snow"
Then my cart total should be "$110.00"
And my cart taxes should be "$10.00"
54 changes: 45 additions & 9 deletions src/Sylius/Behat/Context/Setup/CustomerContext.php
Expand Up @@ -14,6 +14,8 @@
use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Core\Model\Address;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
use Sylius\Component\Customer\Model\CustomerGroupInterface;
Expand Down Expand Up @@ -76,23 +78,28 @@ public function __construct(
public function theStoreHasCustomerWithNameAndEmail($name, $email)
{
$partsOfName = explode(' ', $name);
$this->createCustomer($email, $partsOfName[0], $partsOfName[1]);
$customer = $this->createCustomer($email, $partsOfName[0], $partsOfName[1]);
$this->customerRepository->add($customer);
}

/**
* @Given the store (also )has customer :email
*/
public function theStoreHasCustomer($email)
{
$this->createCustomer($email);
$customer = $this->createCustomer($email);

$this->customerRepository->add($customer);
}

/**
* @Given the store has customer :email with first name :firstName
*/
public function theStoreHasCustomerWithFirstName($email, $firstName)
{
$this->createCustomer($email, $firstName);
$customer = $this->createCustomer($email, $firstName);

$this->customerRepository->add($customer);
}

/**
Expand All @@ -101,15 +108,18 @@ public function theStoreHasCustomerWithFirstName($email, $firstName)
public function theStoreHasCustomerWithNameAndRegistrationDate($email, $fullName, $since)
{
$names = explode(' ', $fullName);
$this->createCustomer($email, $names[0], $names[1], new \DateTime($since));
$customer = $this->createCustomer($email, $names[0], $names[1], new \DateTime($since));

$this->customerRepository->add($customer);
}

/**
* @Given there is disabled customer account :email with password :password
*/
public function thereIsDisabledCustomerAccountWithPassword($email, $password)
{
$this->createCustomerWithUserAccount($email, $password, false);
$customer = $this->createCustomerWithUserAccount($email, $password, false);
$this->customerRepository->add($customer);
}

/**
Expand All @@ -119,7 +129,8 @@ public function thereIsDisabledCustomerAccountWithPassword($email, $password)
*/
public function theStoreHasEnabledCustomerAccountWithPassword($email, $password = 'sylius')
{
$this->createCustomerWithUserAccount($email, $password, true);
$customer = $this->createCustomerWithUserAccount($email, $password, true);
$this->customerRepository->add($customer);
}

/**
Expand All @@ -131,7 +142,8 @@ public function theStoreHasCustomerAccountWithEmailAndPassword($name, $email, $p
$firstName = $names[0];
$lastName = count($names) > 1 ? $names[1] : null;

$this->createCustomerWithUserAccount($email, $password, true, $firstName, $lastName);
$customer = $this->createCustomerWithUserAccount($email, $password, true, $firstName, $lastName);
$this->customerRepository->add($customer);
}

/**
Expand Down Expand Up @@ -164,11 +176,31 @@ public function theCustomerBelongsToGroup(CustomerInterface $customer, CustomerG
$this->customerManager->flush();
}

/**
* @Given there is user :email with :country as shipping country
*/
public function thereIsUserIdentifiedByWithAsShippingCountry($email, CountryInterface $country)
{
$customer = $this->createCustomerWithUserAccount($email, 'password123', true, 'John', 'Doe');
$address = new Address();
$address->setCountryCode($country->getCode());
$address->setCity('Berlin');
$address->setFirstName($customer->getFirstName());
$address->setLastName($customer->getLastName());
$address->setStreet('street');
$address->setPostcode('123');
$customer->setDefaultAddress($address);

$this->customerRepository->add($customer);
}

/**
* @param string $email
* @param string|null $firstName
* @param string|null $lastName
* @param \DateTime|null $createdAt
*
* @return CustomerInterface
*/
private function createCustomer($email, $firstName = null, $lastName = null, \DateTime $createdAt = null)
{
Expand All @@ -183,7 +215,8 @@ private function createCustomer($email, $firstName = null, $lastName = null, \Da
}

$this->sharedStorage->set('customer', $customer);
$this->customerRepository->add($customer);

return $customer;
}

/**
Expand All @@ -193,6 +226,8 @@ private function createCustomer($email, $firstName = null, $lastName = null, \Da
* @param string|null $firstName
* @param string|null $lastName
* @param string|null $role
*
* @return CustomerInterface
*/
private function createCustomerWithUserAccount(
$email,
Expand All @@ -218,6 +253,7 @@ private function createCustomerWithUserAccount(
$customer->setUser($user);

$this->sharedStorage->set('customer', $customer);
$this->customerRepository->add($customer);

return $customer;
}
}
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Setup/PaymentContext.php
Expand Up @@ -128,6 +128,7 @@ public function thisPaymentMethodIsNamedIn(PaymentMethodInterface $paymentMethod

/**
* @Given the payment method :paymentMethod is disabled
* @Given /^(this payment method) has been disabled$/
*/
public function theStoreHasAPaymentMethodDisabled(PaymentMethodInterface $paymentMethod)
{
Expand Down

0 comments on commit 2c6920a

Please sign in to comment.