Cleanup ProductContext

This commit is contained in:
michalmarcinkowski 2016-10-18 15:17:28 +02:00
parent c0223b18db
commit c0632e1063
8 changed files with 52 additions and 69 deletions

View file

@ -10,7 +10,7 @@ Feature: Adding a simple product of given quantity to the cart
@ui
Scenario: Adding a product with stated quantity to the cart
Given there are 10 items of product "T-shirt banana" available in the inventory
Given there are 10 units of product "T-shirt banana" available in the inventory
When I add 5 of them to my cart
Then I should be on my cart summary page
And I should be notified that the product has been successfully added

View file

@ -8,7 +8,7 @@ Feature: Prevent buying more products than available in a stock
Given the store operates on a single channel in "United States"
And the store has a product "T-shirt Mononoke" priced at "$12.54"
And "T-shirt Mononoke" product is tracked by the inventory
And there are 5 items of product "T-Shirt Mononoke" available in the inventory
And there are 5 units of product "T-Shirt Mononoke" available in the inventory
@ui @javascript
Scenario: Preventing from adding more items to the cart than it's available in stock

View file

@ -8,7 +8,7 @@ Feature: Verifying inventory quantity on cart summary
Given the store operates on a single channel in "United States"
And the store has a product "Iron Maiden T-Shirt" priced at "12.54"
And this product is tracked by the inventory
And there are 5 items of product "Iron Maiden T-Shirt" available in the inventory
And there are 5 units of product "Iron Maiden T-Shirt" available in the inventory
@ui
Scenario: Being unable to save a cart with product that is out of stock

View file

@ -9,11 +9,11 @@ Feature: Inventory releasing on order cancellation
And the store has a product "T-Shirt banana"
And the product "T-shirt banana" has "Green" variant priced at "5.54"
And the product "T-shirt banana" has "Red" variant priced at "5.54"
And there are 5 items of "Green" variant of product "T-shirt banana" available in the inventory
And there are 5 items of "Red" variant of product "T-shirt banana" available in the inventory
And there are 5 units of "Green" variant of product "T-shirt banana" available in the inventory
And there are 5 units of "Red" variant of product "T-shirt banana" available in the inventory
And the store has a product "Skirt watermelon"
And the product "Skirt watermelon" has "Yellow" variant priced at "500.43"
And there are 5 items of "Yellow" variant of product "Skirt watermelon" available in the inventory
And there are 5 units of "Yellow" variant of product "Skirt watermelon" available in the inventory
And the store ships everywhere for free
And the store allows paying with "Cash on Delivery"
And I am logged in as an administrator
@ -21,7 +21,7 @@ Feature: Inventory releasing on order cancellation
@ui
Scenario: Verify the reserved inventory is back in stock after cancellation of a new order
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought 3 items of "Green" variant of product "T-shirt banana"
And the customer bought 3 units of "Green" variant of product "T-shirt banana"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And the order "#00000022" was cancelled
When I view all variants of the product "T-shirt banana"
@ -31,7 +31,7 @@ Feature: Inventory releasing on order cancellation
@ui
Scenario: Verify the reserved inventory and quantity of product's items is back in stock after cancellation of paid order
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought 3 items of "Green" variant of product "T-shirt banana"
And the customer bought 3 units of "Green" variant of product "T-shirt banana"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And the order "#00000022" is already paid
And the order "#00000022" was cancelled
@ -42,8 +42,8 @@ Feature: Inventory releasing on order cancellation
@ui
Scenario: Verify the reserved inventory is back in stock after cancellation of a new order with two variants of product
Given there is a customer "john.doe@gmail.com" that placed an order "#00000023"
And the customer bought 3 items of "Green" variant of product "T-shirt banana"
And the customer bought 2 items of "Red" variant of product "T-shirt banana"
And the customer bought 3 units of "Green" variant of product "T-shirt banana"
And the customer bought 2 units of "Red" variant of product "T-shirt banana"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And the order "#00000023" was cancelled
When I view all variants of the product "T-shirt banana"
@ -55,8 +55,8 @@ Feature: Inventory releasing on order cancellation
@ui
Scenario: Verify the reserved inventory and quantity of product's items is back in stock after cancellation of paid order with two variants of product
Given there is a customer "john.doe@gmail.com" that placed an order "#00000023"
And the customer bought 3 items of "Green" variant of product "T-shirt banana"
And the customer bought 2 items of "Red" variant of product "T-shirt banana"
And the customer bought 3 units of "Green" variant of product "T-shirt banana"
And the customer bought 2 units of "Red" variant of product "T-shirt banana"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And the order "#00000023" is already paid
And the order "#00000023" was cancelled
@ -69,8 +69,8 @@ Feature: Inventory releasing on order cancellation
@ui
Scenario: Verify the reserved inventory is back in stock after cancellation of a new order with two variants of differents products
Given there is a customer "john.doe@gmail.com" that placed an order "#00000024"
And the customer bought 3 items of "Green" variant of product "T-shirt banana"
And the customer bought 2 items of "Yellow" variant of product "Skirt watermelon"
And the customer bought 3 units of "Green" variant of product "T-shirt banana"
And the customer bought 2 units of "Yellow" variant of product "Skirt watermelon"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And the order "#00000024" was cancelled
Then the "Green" variant of "T-shirt banana" product should have 5 items on hand
@ -81,8 +81,8 @@ Feature: Inventory releasing on order cancellation
@ui
Scenario: Verify the reserved inventory and quantity of product's items is back in stock after cancellation of paid order with two variants of differents products
Given there is a customer "john.doe@gmail.com" that placed an order "#00000024"
And the customer bought 3 items of "Green" variant of product "T-shirt banana"
And the customer bought 2 items of "Yellow" variant of product "Skirt watermelon"
And the customer bought 3 units of "Green" variant of product "T-shirt banana"
And the customer bought 2 units of "Yellow" variant of product "Skirt watermelon"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And the order "#00000024" is already paid
And the order "#00000024" was cancelled

View file

@ -9,8 +9,8 @@ Feature: Seeing product's variant with specify quantity of items on hand
And the store has a "T-shirt banana" configurable product
And the product "T-shirt banana" has "Yellow" variant priced at "20.54"
And the product "T-shirt banana" has "Green" variant priced at "5.54"
And there are 5 items of "Yellow" variant of product "T-shirt banana" available in the inventory
And there are 5 items of "Green" variant of product "T-shirt banana" available in the inventory
And there are 5 units of "Yellow" variant of product "T-shirt banana" available in the inventory
And there are 5 units of "Green" variant of product "T-shirt banana" available in the inventory
And the store ships everywhere for free
And the store allows paying with "Cash on Delivery"
And I am logged in as an administrator
@ -18,7 +18,7 @@ Feature: Seeing product's variant with specify quantity of items on hand
@ui
Scenario: Seeing decreased quantity of product's items in selected variant after order payment
Given there is a customer "lucy@teamlucifer.com" that placed an order "#00000666"
And the customer bought 3 items of "Green" variant of product "T-shirt banana"
And the customer bought 3 units of "Green" variant of product "T-shirt banana"
And the customer "Lucifer Morningstar" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address
And the customer chose "Free" shipping method with "Cash on Delivery" payment
And this order is already paid
@ -28,8 +28,8 @@ Feature: Seeing product's variant with specify quantity of items on hand
@ui
Scenario: Seeing decreased quantity of product's items from different variants after order payment
Given there is a customer "lucy@teamlucifer.com" that placed an order "#00000666"
And the customer bought 3 items of "Yellow" variant of product "T-shirt banana"
And the customer bought 2 items of "Green" variant of product "T-shirt banana"
And the customer bought 3 units of "Yellow" variant of product "T-shirt banana"
And the customer bought 2 units of "Green" variant of product "T-shirt banana"
And the customer "Lucifer Morningstar" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address
And the customer chose "Free" shipping method with "Cash on Delivery" payment
And this order is already paid

View file

@ -19,7 +19,7 @@ Feature: Seeing order item detailed data
And there is a promotion "T-Shirts promotion"
And it gives "$2.00" off on every product with minimum price at "$20.00"
And there is a customer "tony@stark.com" that placed an order "#00000666"
And the customer bought 4 items of "Iron Man T-Shirt" variant of product "Marvel T-Shirt"
And the customer bought 4 units of "Iron Man T-Shirt" variant of product "Marvel T-Shirt"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And I am logged in as an administrator

View file

@ -336,7 +336,7 @@ final class OrderContext implements Context
}
/**
* @Given /^the customer bought ([^"]+) items of ("[^"]+" variant of product "[^"]+")$/
* @Given /^the customer bought ([^"]+) units of ("[^"]+" variant of product "[^"]+")$/
*/
public function theCustomerBoughtSeveralVariantsOfProduct($quantity, ProductVariantInterface $variant)
{

View file

@ -280,8 +280,10 @@ final class ProductContext implements Context
*/
public function productBelongsToTaxCategory(ProductInterface $product, TaxCategoryInterface $taxCategory)
{
/** @var ProductVariantInterface $variant */
$variant = $this->defaultVariantResolver->getVariant($product);
$variant->setTaxCategory($taxCategory);
$this->objectManager->flush();
}
@ -406,22 +408,29 @@ final class ProductContext implements Context
}
/**
* @Given /^there (?:is|are) (\d+) (?:item|unit)(?:|s) of (product "([^"]+)") available in the inventory$/
* @Given /^there (?:is|are) (\d+) unit(?:|s) of (product "([^"]+)") available in the inventory$/
* @When product :product quantity is changed to :quantity
*/
public function thereIsQuantityOfProducts($quantity, ProductInterface $product)
{
$this->setProductsQuantity($product, $quantity);
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productVariant->setOnHand($quantity);
$this->objectManager->flush();
}
/**
* @Given /^the (product "([^"]+)") is out of stock$/
*/
public function theProductIsNotAvailable(ProductInterface $product)
public function theProductIsOutOfStock(ProductInterface $product)
{
$product->getFirstVariant()->setTracked(true);
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productVariant->setTracked(true);
$productVariant->setOnHand(0);
$this->setProductsQuantity($product, 0);
$this->objectManager->flush();
}
/**
@ -431,19 +440,20 @@ final class ProductContext implements Context
{
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productQuantity = $productVariant->getOnHand() - $quantity;
$productVariant->setOnHand($productVariant->getOnHand() - $quantity);
$this->setProductsQuantity($product, $productQuantity);
$this->objectManager->flush();
}
/**
* @Given /^(this product) is tracked by the inventory$/
* @Given /^("[^"]+" product) is(?:| also) tracked by the inventory$/
* @Given /^(?:|the )("[^"]+" product) is(?:| also) tracked by the inventory$/
*/
public function thisProductIsTrackedByTheInventory(ProductInterface $product)
{
$variant = $this->defaultVariantResolver->getVariant($product);
$variant->setTracked(true);
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productVariant->setTracked(true);
$this->objectManager->flush();
}
@ -479,7 +489,7 @@ final class ProductContext implements Context
}
/**
* @Given /^there are ([^"]+) items of ("[^"]+" variant of product "[^"]+") available in the inventory$/
* @Given /^there are ([^"]+) units of ("[^"]+" variant of product "[^"]+") available in the inventory$/
*/
public function thereAreItemsOfProductInVariantAvailableInTheInventory($quantity, ProductVariantInterface $productVariant)
{
@ -489,17 +499,6 @@ final class ProductContext implements Context
$this->objectManager->flush();
}
/**
* @Given /^the ("[^"]+" product) is tracked by the inventory$/
*/
public function theProductIsTrackedByTheInventory(ProductInterface $product)
{
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productVariant->setTracked(true);
$this->objectManager->flush();
}
/**
* @Given /^the ("[^"]+" product variant) is tracked by the inventory$/
*/
@ -511,11 +510,14 @@ final class ProductContext implements Context
}
/**
* @Given /^(this product)'s price is ("[^"]+")$/
* @Given /^the (product "[^"]+") changed its price to ("[^"]+")$/
*/
public function theProductChangedItsPriceTo(ProductInterface $product, $price)
{
$product->getFirstVariant()->setPrice($price);
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productVariant->setPrice($price);
$this->objectManager->flush();
}
@ -539,15 +541,6 @@ final class ProductContext implements Context
$this->objectManager->flush($product);
}
/**
* @Given /^(this product)'s price is "([^"]+)"$/
*/
public function thisProductPriceIs(ProductInterface $product, $price)
{
$product->getFirstVariant()->setPrice($this->getPriceFromString($price));
$this->objectManager->flush($product);
}
/**
* @param string $type
* @param string $name
@ -608,9 +601,10 @@ final class ProductContext implements Context
$product->setCode($this->convertToCode($productName));
$product->setCreatedAt(new \DateTime($date));
$variant = $this->defaultVariantResolver->getVariant($product);
$variant->setPrice($price);
$variant->setCode($product->getCode());
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productVariant->setPrice($price);
$productVariant->setCode($product->getCode());
return $product;
}
@ -636,17 +630,6 @@ final class ProductContext implements Context
return $optionValue;
}
/**
* @param ProductInterface $product
* @param int $quantity
*/
private function setProductsQuantity(ProductInterface $product, $quantity)
{
$product->getFirstVariant()->setOnHand($quantity);
$this->saveProduct($product);
}
/**
* @param ProductInterface $product
*/