From 9cf36e40879337b49f4fb23ca8b5fc52fddbf10c Mon Sep 17 00:00:00 2001 From: Stefan Doorn Date: Mon, 24 Dec 2018 18:41:11 +0100 Subject: [PATCH] Add additional Behat features for checkout --- ...ipping_and_billing_address_details.feature | 45 +++++++++++++++++++ ...d_billing_address_details_as_guest.feature | 38 ++++++++++++++++ .../Context/Transform/AddressContext.php | 22 +++++++++ .../Checkout/CheckoutAddressingContext.php | 30 +++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 features/checkout/address_order/filling_shipping_and_billing_address_details.feature create mode 100644 features/checkout/address_order/filling_shipping_and_billing_address_details_as_guest.feature diff --git a/features/checkout/address_order/filling_shipping_and_billing_address_details.feature b/features/checkout/address_order/filling_shipping_and_billing_address_details.feature new file mode 100644 index 0000000..59cc5ca --- /dev/null +++ b/features/checkout/address_order/filling_shipping_and_billing_address_details.feature @@ -0,0 +1,45 @@ +@house_number_checkout +Feature: Addressing an order + In order to address an order + As a Customer + I want to be able to fill addressing details + + 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 I am a logged in customer + + @ui + Scenario: Address an order without different billing address + Given I have product "PHP T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the shipping address extended as "Ankh Morpork", "Frost Alley", "12", "a", "90210", "United States" for "Jon Snow" + And I complete the addressing step + Then I should be on the checkout shipping step + + @ui + Scenario: Address an order without different billing address with optional addition + Given I have product "PHP T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the shipping address extended as "Ankh Morpork", "Frost Alley", "12", "", "90210", "United States" for "Jon Snow" + And I complete the addressing step + Then I should be on the checkout shipping step + + @ui + Scenario: Address an order with different billing address + Given I have product "PHP T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the shipping address extended as "Ankh Morpork", "Frost Alley", "14", "a", "90210", "United States" for "Jon Snow" + And I specify the billing address extended as "Ankh Morpork", "Frost Alley", "28", "b", "90210", "United States" for "Eddard Stark" + And I complete the addressing step + Then I should be on the checkout shipping step + + @ui + Scenario: Address an order with different billing address with optional addition + Given I have product "PHP T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the shipping address extended as "Ankh Morpork", "Frost Alley", "14", "", "90210", "United States" for "Jon Snow" + And I specify the billing address extended as "Ankh Morpork", "Frost Alley", "28", "", "90210", "United States" for "Eddard Stark" + And I complete the addressing step + Then I should be on the checkout shipping step diff --git a/features/checkout/address_order/filling_shipping_and_billing_address_details_as_guest.feature b/features/checkout/address_order/filling_shipping_and_billing_address_details_as_guest.feature new file mode 100644 index 0000000..676ae89 --- /dev/null +++ b/features/checkout/address_order/filling_shipping_and_billing_address_details_as_guest.feature @@ -0,0 +1,38 @@ +@house_number_checkout +Feature: Addressing an order + In order to address an order + As a Guest + I want to be able to fill extended addressing details + + Background: + Given the store operates on a single channel in "United States" + And the store ships everywhere for free + And the store has a product "PHP T-Shirt" priced at "$19.99" + + @ui + Scenario: Address an order without different billing address + Given I have product "PHP T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the email as "jon.snow@example.com" + And I specify the shipping address extended as "Ankh Morpork", "Frost Alley", "12", "a", "90210", "United States" for "Jon Snow" + And I complete the addressing step + Then I should be on the checkout shipping step + + @ui + Scenario: Address an order without different billing address with optional addition + Given I have product "PHP T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the email as "jon.snow@example.com" + And I specify the shipping address extended as "Ankh Morpork", "Frost Alley", "12", "", "90210", "United States" for "Jon Snow" + And I complete the addressing step + Then I should be on the checkout shipping step + + @ui + Scenario: Address an order with different billing address with optional addition + Given I have product "PHP T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the email as "eddard.stark@example.com" + And I specify the shipping address extended as "Ankh Morpork", "Frost Alley", "12", "", "90210", "United States" for "Jon Snow" + And I specify the billing address extended as "Ankh Morpork", "Frost Alley", "14", "", "90210", "United States" for "Eddard Stark" + And I complete the addressing step + Then I should be on the checkout shipping step diff --git a/tests/Behat/Context/Transform/AddressContext.php b/tests/Behat/Context/Transform/AddressContext.php index b11051c..9ebea3d 100644 --- a/tests/Behat/Context/Transform/AddressContext.php +++ b/tests/Behat/Context/Transform/AddressContext.php @@ -63,6 +63,28 @@ public function createNewAddressWith($city, $street, $postcode, $countryName, $c ]); } + /** + * @Transform /^address extended (?:as |is |to )"([^"]+)", ([^"]+)", ([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)"$/ + */ + public function createNewExtendedAddressWith($city, $street, $number, $addition, $postcode, $countryName, $customerName) + { + [$firstName, $lastName] = explode(' ', $customerName); + + return $this->exampleAddressFactory->create([ + 'country_code' => $this->countryNameConverter->convertToCode($countryName), + 'first_name' => $firstName, + 'last_name' => $lastName, + 'company' => null, + 'customer' => null, + 'phone_number' => null, + 'city' => $city, + 'street' => $street, + 'postcode' => $postcode, + 'number' => $number, + 'addition' => $addition, + ]); + } + /** * @Transform /^clear old (shipping|billing) address$/ * @Transform /^do not specify any (shipping|billing) address$/ diff --git a/tests/Behat/Context/Ui/Shop/Checkout/CheckoutAddressingContext.php b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutAddressingContext.php index 83635a9..0b6b136 100644 --- a/tests/Behat/Context/Ui/Shop/Checkout/CheckoutAddressingContext.php +++ b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutAddressingContext.php @@ -44,6 +44,36 @@ public function __construct( $this->selectShippingPage = $selectShippingPage; } + /** + * @When /^I specify the shipping (address extended as "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+" for "[^"]+")$/ + */ + public function iSpecifyTheShippingAddressAs(AddressInterface $address) + { + $key = sprintf( + 'shipping_address_%s_%s', + strtolower((string) $address->getFirstName()), + strtolower((string) $address->getLastName()) + ); + $this->sharedStorage->set($key, $address); + + $this->addressPage->specifyShippingAddress($address); + } + + /** + * @When /^I specify the billing (address extended as "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+" for "[^"]+")$/ + */ + public function iSpecifyTheBillingAddressAs(AddressInterface $address) + { + $key = sprintf( + 'billing_address_%s_%s', + strtolower((string) $address->getFirstName()), + strtolower((string) $address->getLastName()) + ); + $this->sharedStorage->set($key, $address); + + $this->addressPage->specifyBillingAddress($address); + } + /** * @Then /^I should be notified that the street number in (shipping|billing) details is required$/ */