From 3da58c35596ec183bd704b2250c07f7406fc5f1d Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 19 Oct 2017 14:55:31 +0200 Subject: [PATCH] [Behat][Order] Add scenarios for viewing items with proper names --- ...wing_order_items_with_proper_names.feature | 26 ++++++++++++++++++ ...eing_order_items_with_proper_names.feature | 27 +++++++++++++++++++ .../Behat/Context/Setup/ProductContext.php | 10 +++++++ .../Behat/Page/Admin/Order/ShowPage.php | 15 ++++++++--- .../Page/Admin/Order/ShowPageInterface.php | 2 +- .../Page/Shop/Account/Order/ShowPage.php | 17 +++++++++--- .../Shop/Account/Order/ShowPageInterface.php | 4 +-- 7 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature create mode 100644 features/order/managing_orders/seeing_order_items_with_proper_names.feature diff --git a/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature b/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature new file mode 100644 index 00000000000..26e3346aaa2 --- /dev/null +++ b/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature @@ -0,0 +1,26 @@ +@customer_account +Feature: Viewing order items with proper names + In order to check some details of my placed order + As an Customer + I want to be able to view items with proper names of my placed order + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "Angel T-Shirt" priced at "$39.00" + And the store has a product "Angel Mug" priced at "$19.00" + And the store ships everywhere for free + And the store allows paying with "Cash on Delivery" + And I am a logged in customer + And I placed an order "#00000666" + And I bought an "Angel T-Shirt" and an "Angel Mug" + And I addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address + And I chose "Free" shipping method with "Cash on Delivery" payment + + @ui @todo + Scenario: Viewing basic information about an order + Given the product "Angel T-Shirt" was renamed to "Devil Cardigan" + And the product "Angel Mug" was renamed to "Devil Glass" + When I view the summary of the order "#00000666" + And I should see 2 items in the list + And the product named "Angel T-Shirt" should be in the items list + And the product named "Angel Mug" should be in the items list diff --git a/features/order/managing_orders/seeing_order_items_with_proper_names.feature b/features/order/managing_orders/seeing_order_items_with_proper_names.feature new file mode 100644 index 00000000000..3305a4b963f --- /dev/null +++ b/features/order/managing_orders/seeing_order_items_with_proper_names.feature @@ -0,0 +1,27 @@ +@managing_orders +Feature: Seeing order items with proper names + In order to see ordered products with proper names + As an Administrator + I want to be able to list items + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "Angel T-Shirt" priced at "$39.00" + And the store has a product "Angel Mug" priced at "$19.00" + And the store ships everywhere for free + And the store allows paying with "Cash on Delivery" + And there is a customer "lucy@teamlucifer.com" that placed an order "#00000666" + And the customer bought an "Angel T-Shirt" and an "Angel Mug" + And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment + And I am logged in as an administrator + + @ui @todo + Scenario: Seeing order items with proper names + Given the product "Angel T-Shirt" was renamed to "Devil Cardigan" + And the product "Angel Mug" was renamed to "Devil Glass" + When I view the summary of the order "#00000666" + Then it should have 2 items + And the product named "Angel T-Shirt" should be in the items list + And the product named "Angel Mug" should be in the items list + And the order's items total should be "$58.00" + And the order's total should be "$58.00" diff --git a/src/Sylius/Behat/Context/Setup/ProductContext.php b/src/Sylius/Behat/Context/Setup/ProductContext.php index 971dce110bd..b7d9fb378c4 100644 --- a/src/Sylius/Behat/Context/Setup/ProductContext.php +++ b/src/Sylius/Behat/Context/Setup/ProductContext.php @@ -782,6 +782,16 @@ public function thisProductHasBeenDisabled(ProductInterface $product) $this->objectManager->flush(); } + /** + * @Given the product :product was renamed to :productName + */ + public function theProductWasRenamedTo(ProductInterface $product, string $productName): void + { + $product->setName($productName); + + $this->objectManager->flush(); + } + /** * @param string $price * diff --git a/src/Sylius/Behat/Page/Admin/Order/ShowPage.php b/src/Sylius/Behat/Page/Admin/Order/ShowPage.php index 32497cf166c..a01159ab2ab 100644 --- a/src/Sylius/Behat/Page/Admin/Order/ShowPage.php +++ b/src/Sylius/Behat/Page/Admin/Order/ShowPage.php @@ -145,15 +145,24 @@ public function countItems() /** * {@inheritdoc} */ - public function isProductInTheList($productName) + public function isProductInTheList(string $productName): bool { try { + $table = $this->getElement('table'); $rows = $this->tableAccessor->getRowsWithFields( - $this->getElement('table'), + $table, ['item' => $productName] ); - return 1 === count($rows); + foreach ($rows as $row) { + $field = $this->tableAccessor->getFieldFromRow($table, $row, 'item'); + $name = $field->find('css', '.sylius-product-name'); + if (null !== $name && $name->getText() === $productName) { + return true; + } + } + + return false; } catch (\InvalidArgumentException $exception) { return false; } diff --git a/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php b/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php index ff05f775508..cf567f735f8 100644 --- a/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php @@ -103,7 +103,7 @@ public function countItems(); * * @return bool */ - public function isProductInTheList($productName); + public function isProductInTheList(string $productName): bool; /** * @return string diff --git a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php index 3b0be8d0c94..a3e844460e2 100644 --- a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php +++ b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php @@ -122,15 +122,24 @@ public function getPaymentPrice() /** * {@inheritdoc} */ - public function isProductInTheList($name) + public function isProductInTheList(string $productName): bool { try { + $table = $this->getElement('order_items'); $rows = $this->tableAccessor->getRowsWithFields( - $this->getElement('order_items'), - ['item' => $name] + $table, + ['item' => $productName] ); - return 1 === count($rows); + foreach ($rows as $row) { + $field = $this->tableAccessor->getFieldFromRow($table, $row, 'item'); + $name = $field->find('css', '.sylius-product-name'); + if (null !== $name && $name->getText() === $productName) { + return true; + } + } + + return false; } catch (\InvalidArgumentException $exception) { return false; } diff --git a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php index 9fea45da276..21caeec874e 100644 --- a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php +++ b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php @@ -65,11 +65,11 @@ public function countItems(); public function getPaymentPrice(); /** - * @param string $name + * @param string $productName * * @return bool */ - public function isProductInTheList($name); + public function isProductInTheList(string $productName): bool; /** * @return string