Skip to content

Commit

Permalink
[Behat][Order] Add scenarios for viewing items with proper names
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Oct 30, 2017
1 parent 7f35652 commit 3da58c3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions src/Sylius/Behat/Context/Setup/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
15 changes: 12 additions & 3 deletions src/Sylius/Behat/Page/Admin/Order/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function countItems();
*
* @return bool
*/
public function isProductInTheList($productName);
public function isProductInTheList(string $productName): bool;

/**
* @return string
Expand Down
17 changes: 13 additions & 4 deletions src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3da58c3

Please sign in to comment.