Skip to content

Commit

Permalink
Merge pull request #5281 from GSadee/shop-account-order-details
Browse files Browse the repository at this point in the history
[Shop][Account] Order details on my account page
  • Loading branch information
Paweł Jędrzejewski committed Jun 22, 2016
2 parents cfa808a + 7fbcf39 commit 648607a
Show file tree
Hide file tree
Showing 25 changed files with 636 additions and 17 deletions.
Expand Up @@ -9,16 +9,15 @@ Feature: Viewing orders on my account page
And the store has "Angel T-Shirt" and "Green Arrow" products
And the store ships everywhere for free
And the store allows paying with "Cash on Delivery"
And there is a customer account "lucy@teamlucifer.com" identified by "heaven"
And a customer "lucy@teamlucifer.com" placed an order "#00000666"
And the customer "Lucifer Morningstar" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And I am a logged in customer
And I placed an order "#00000666"
And I addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And for the billing address of "Mazikeen Lilim" in the "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
And the customer chose "Free" shipping method with "Cash on Delivery" payment
And the customer bought a single "Angel T-Shirt"
And there is a customer "oliver@teamarrow.com" that placed an order "#00000999"
And I chose "Free" shipping method with "Cash on Delivery" payment
And I bought a single "Angel T-Shirt"
And there is another customer "oliver@teamarrow.com" that placed an order "#00000999"
And the customer "Oliver Queen" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And the customer bought a single "Green Arrow"
And I am logged in as "lucy@teamlucifer.com"

@ui
Scenario: Viewing orders
Expand Down
@@ -0,0 +1,25 @@
@customer_account
Feature: Viewing details of an order
In order to check some details of my placed order
As an Customer
I want to be able to view details of my placed order

Background:
Given the store operates on a single channel in "France"
And the store has a product "Angel T-Shirt" priced at "€39.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 addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And for the billing address of "Mazikeen Lilim" in the "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
And I chose "Free" shipping method with "Cash on Delivery" payment
And I bought a single "Angel T-Shirt"

@ui
Scenario: Viewing basic information about an order
When I view the summary of the order "#00000666"
And it should has number "#00000666"
And I should see "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States" as shiping address
And I should see "Mazikeen Lilim", "Pacific Coast Hwy", "90806", "Los Angeles", "United States" as billing address
And I should see "€39.00" as order's total
@@ -0,0 +1,28 @@
@customer_account
Feature: Viewing details of an order
In order to check some details of my placed order
As an Customer
I want to be able to view details of my placed order

Background:
Given the store operates on a single channel in "France"
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 addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And for the billing address of "Mazikeen Lilim" in the "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
And I chose "Free" shipping method with "Cash on Delivery" payment
And I bought an "Angel T-Shirt" and an "Angel Mug"

@ui @javascript
Scenario: Viewing basic information about an order
When I view the summary of the order "#00000666"
And it should has number "#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
And I should see "€58.00" as order's subtotal
And I should see "€58.00" as order's total
Expand Up @@ -9,13 +9,12 @@ Feature: Viewing only my orders on my account page
And the store has a product "Angel T-Shirt"
And the store ships everywhere for free
And the store allows paying with "Cash on Delivery"
And there is a customer account "lucy@teamlucifer.com" identified by "heaven"
And a customer "lucy@teamlucifer.com" placed an order "#00000666"
And the customer "Lucifer Morningstar" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And I am a logged in customer
And I placed an order "#00000666"
And I addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And for the billing address of "Mazikeen Lilim" in the "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
And the customer chose "Free" shipping method with "Cash on Delivery" payment
And the customer bought a single "Angel T-Shirt"
And I am logged in as "lucy@teamlucifer.com"
And I chose "Free" shipping method with "Cash on Delivery" payment
And I bought a single "Angel T-Shirt"

@ui
Scenario: Viewing orders
Expand Down
18 changes: 18 additions & 0 deletions src/Sylius/Behat/Context/Setup/OrderContext.php
Expand Up @@ -147,6 +147,7 @@ public function __construct(

/**
* @Given there is a customer :customer that placed an order :orderNumber
* @Given there is another customer :customer that placed an order :orderNumber
* @Given a customer :customer placed an order :orderNumber
*/
public function thereIsCustomerThatPlacedOrder(CustomerInterface $customer, $orderNumber)
Expand All @@ -158,8 +159,22 @@ public function thereIsCustomerThatPlacedOrder(CustomerInterface $customer, $ord
$this->orderRepository->add($order);
}

/**
* @Given /^(I) placed (an order "[^"]+")$/
*/
public function iPlacedAnOrder(UserInterface $user, $orderNumber)
{
$customer = $user->getCustomer();
$order = $this->createOrder($customer, $orderNumber);

$this->sharedStorage->set('order', $order);

$this->orderRepository->add($order);
}

/**
* @Given /^the customer ("[^"]+" addressed it to "[^"]+", "[^"]+" "[^"]+" in the "[^"]+")$/
* @Given /^I (addressed it to "[^"]+", "[^"]+", "[^"]+" "[^"]+" in the "[^"]+")$/
*/
public function theCustomerAddressedItTo(AddressInterface $address)
{
Expand Down Expand Up @@ -212,6 +227,7 @@ public function theCustomerChoseShippingToWithPayment(

/**
* @Given /^the customer chose ("[^"]+" shipping method) with ("[^"]+" payment)$/
* @Given /^I chose ("[^"]+" shipping method) with ("[^"]+" payment)$/
*/
public function theCustomerChoseShippingWithPayment(
ShippingMethodInterface $shippingMethod,
Expand All @@ -235,6 +251,7 @@ public function theCustomerChoseShippingWithPayment(

/**
* @Given the customer bought a single :product
* @Given I bought a single :product
*/
public function theCustomerBoughtSingleProduct(ProductInterface $product)
{
Expand All @@ -245,6 +262,7 @@ public function theCustomerBoughtSingleProduct(ProductInterface $product)

/**
* @Given /^the customer bought ((?:a|an) "[^"]+") and ((?:a|an) "[^"]+")$/
* @Given /^I bought ((?:a|an) "[^"]+") and ((?:a|an) "[^"]+")$/
*/
public function theCustomerBoughtProductAndProduct(ProductInterface $product, ProductInterface $secondProduct)
{
Expand Down
12 changes: 12 additions & 0 deletions src/Sylius/Behat/Context/Transform/AddressingContext.php
Expand Up @@ -75,6 +75,7 @@ public function createEmptyAddress()
/**
* @Transform /^"([^"]+)" addressed it to "([^"]+)", "([^"]+)" "([^"]+)" in the "([^"]+)"$/
* @Transform /^of "([^"]+)" in the "([^"]+)", "([^"]+)" "([^"]+)", "([^"]+)"$/
* @Transform /^addressed it to "([^"]+)", "([^"]+)", "([^"]+)" "([^"]+)" in the "([^"]+)"$/
*/
public function createNewAddressWithName($name, $street, $postcode, $city, $countryName)
{
Expand All @@ -84,6 +85,17 @@ public function createNewAddressWithName($name, $street, $postcode, $city, $coun
return $this->createAddress($countryCode, $names[0], $names[1], $city, $street, $postcode);
}

/**
* @Transform /^"([^"]+)" addressed it to "([^"]+)", "([^"]+)" "([^"]+)" in the "([^"]+)"$/
*/
public function createNewAddressWithUser($name, $street, $postcode, $city, $countryName)
{
$countryCode = $this->countryNameConverter->convertToCode($countryName);
$names = explode(" ", $name);

return $this->createAddress($countryCode, $names[0], $names[1], $city, $street, $postcode);
}

/**
* @param string $countryCode
* @param string $firstName
Expand Down
12 changes: 12 additions & 0 deletions src/Sylius/Behat/Context/Transform/OrderContext.php
Expand Up @@ -38,10 +38,22 @@ public function __construct(OrderRepositoryInterface $orderRepository)
*/
public function getOrderByNumber($orderNumber)
{
$orderNumber = $this->getOrderNumber($orderNumber);
$order = $this->orderRepository->findOneBy(['number' => $orderNumber]);

Assert::notNull($order, sprintf('Cannot find order with number %s', $orderNumber));

return $order;
}

/**
* @Transform :orderNumber
* @Transform /^an order "([^"]+)"$/
*/
public function getOrderNumber($orderNumber)
{
$orderNumber = str_replace('#', '', $orderNumber);

return $orderNumber;
}
}
105 changes: 101 additions & 4 deletions src/Sylius/Behat/Context/Ui/Shop/AccountContext.php
Expand Up @@ -16,8 +16,8 @@
use Sylius\Behat\Page\PageInterface;
use Sylius\Behat\Page\Shop\Account\ChangePasswordPageInterface;
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface;
use Sylius\Behat\Page\Shop\Account\Order\IndexPage;
use Sylius\Behat\Page\Shop\Account\Order\IndexPageInterface;
use Sylius\Behat\Page\Shop\Account\Order\ShowPageInterface;
use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Core\Formatter\StringInflector;
Expand Down Expand Up @@ -49,6 +49,11 @@ final class AccountContext implements Context
*/
private $orderIndexPage;

/**
* @var ShowPageInterface
*/
private $orderShowPage;

/**
* @var NotificationCheckerInterface
*/
Expand All @@ -58,20 +63,23 @@ final class AccountContext implements Context
* @param DashboardPageInterface $dashboardPage
* @param ProfileUpdatePageInterface $profileUpdatePage
* @param ChangePasswordPageInterface $changePasswordPage
* @param IndexPage $orderIndexPage
* @param IndexPageInterface $orderIndexPage
* @param ShowPageInterface $orderShowPage
* @param NotificationCheckerInterface $notificationChecker
*/
public function __construct(
DashboardPageInterface $dashboardPage,
ProfileUpdatePageInterface $profileUpdatePage,
ChangePasswordPageInterface $changePasswordPage,
IndexPage $orderIndexPage,
IndexPageInterface $orderIndexPage,
ShowPageInterface $orderShowPage,
NotificationCheckerInterface $notificationChecker
) {
$this->dashboardPage = $dashboardPage;
$this->profileUpdatePage = $profileUpdatePage;
$this->changePasswordPage = $changePasswordPage;
$this->orderIndexPage = $orderIndexPage;
$this->orderShowPage = $orderShowPage;
$this->notificationChecker = $notificationChecker;
}

Expand Down Expand Up @@ -274,7 +282,7 @@ public function iShouldSeeASingleOrderInTheList()
}

/**
* @Given this order should have :order number
* @Then this order should have :order number
*/
public function thisOrderShouldHaveNumber(OrderInterface $order)
{
Expand All @@ -284,6 +292,95 @@ public function thisOrderShouldHaveNumber(OrderInterface $order)
);
}

/**
* @When I view the summary of the order :order
*/
public function iViewTheSummaryOfTheOrder(OrderInterface $order)
{
$this->orderShowPage->open(['number' => $order->getNumber()]);
}

/**
* @Then it should has number :orderNumber
*/
public function itShouldHasNumber($orderNumber)
{
Assert::same(
$this->orderShowPage->getNumber(),
$orderNumber,
'The number of an order is %s, but should be %s.'
);
}

/**
* @Then I should see :customerName, :street, :postcode, :city, :countryName as shiping address
*/
public function iShouldSeeAsShipingAddress($customerName, $street, $postcode, $city, $countryName)
{
Assert::true(
$this->orderShowPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName),
sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
);
}

/**
* @Then I should see :customerName, :street, :postcode, :city, :countryName as billing address
*/
public function itShouldBeShippedTo($customerName, $street, $postcode, $city, $countryName)
{
Assert::true(
$this->orderShowPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName),
sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
);
}

/**
* @Then I should see :total as order's total
*/
public function iShouldSeeAsOrderSTotal($total)
{
Assert::same(
$this->orderShowPage->getTotal(),
$total,
'Total is %s, but should be %s.'
);
}

/**
* @Then I should see :itemsTotal as order's subtotal
*/
public function iShouldSeeAsOrderSSubtotal($subtotal)
{
Assert::same(
$this->orderShowPage->getSubtotal(),
$subtotal,
'Subtotal is %s, but should be %s.'
);
}

/**
* @Then I should see :numberOfItems items in the list
*/
public function iShouldSeeItemsInTheList($numberOfItems)
{
Assert::same(
$numberOfItems,
$this->orderShowPage->countItems(),
'%s items should appear on order page, but %s rows has been found'
);
}

/**
* @Then the product named :productName should be in the items list
*/
public function theProductShouldBeInTheItemsList($productName)
{
Assert::true(
$this->orderShowPage->isProductInTheList($productName),
sprintf('Product %s is not in the item list.', $productName)
);
}

/**
* @param PageInterface $page
* @param string $element
Expand Down

0 comments on commit 648607a

Please sign in to comment.