Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behat tests for orders in the Back Office. Various Behat features created and scenarios added #16525

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
4397323
Update order status feature behat tests
tdavidsonas88 Nov 25, 2019
ad2a2f1
Update order status feature behat tests
tdavidsonas88 Nov 25, 2019
c7724a5
Update order status feature behat tests
tdavidsonas88 Nov 25, 2019
2c80289
Update order status feature behat tests
tdavidsonas88 Nov 25, 2019
e54feb6
Update order status feature behat tests
tdavidsonas88 Nov 25, 2019
579be52
feature/order-edit-shipping=integration-tests
tdavidsonas88 Nov 26, 2019
2f9ff5f
order integration-tests with behat
tdavidsonas88 Nov 26, 2019
bc48fb1
order integration-tests with behat
tdavidsonas88 Nov 27, 2019
1fa5bcd
order integration-tests with behat
tdavidsonas88 Nov 27, 2019
ab432d1
order integration-tests with behat
tdavidsonas88 Nov 27, 2019
33714aa
order integration-tests with behat
tdavidsonas88 Nov 28, 2019
b3826f5
add_payment.feature behat tests
tdavidsonas88 Nov 28, 2019
ddbc367
add_payment.feature behat tests
tdavidsonas88 Nov 28, 2019
b2a6b19
add_payment.feature behat tests
tdavidsonas88 Nov 28, 2019
316dd01
add_payment.feature behat tests
tdavidsonas88 Nov 28, 2019
73ce5e5
add_payment.feature behat tests
tdavidsonas88 Nov 28, 2019
c4abab4
add_payment.feature behat tests
tdavidsonas88 Nov 28, 2019
1aa90fd
add_payment.feature behat tests
tdavidsonas88 Nov 29, 2019
ea6094e
Merge branch 'm/orders/create-summary' of https://github.com/zuk3975/…
tdavidsonas88 Dec 3, 2019
4e96605
Refactored the naming of the methods after margud QA
tdavidsonas88 Dec 4, 2019
076538b
Behat Feature: Duplicate order cart from Back Office
tdavidsonas88 Dec 6, 2019
20be8d8
Behat feature test for Duplicate order cart from BO
tdavidsonas88 Dec 6, 2019
fc5a39d
Behat feature test for Duplicate order cart from BO
tdavidsonas88 Dec 6, 2019
13e25a7
Behat feature test for Duplicate order cart from BO
tdavidsonas88 Dec 9, 2019
dad4e5b
Bussiness value defined for duplicate order cart feature
tdavidsonas88 Dec 9, 2019
ca95ce7
shipping info is null by default in duplicate order cart feature
tdavidsonas88 Dec 9, 2019
7366895
refactored to use PHPUnit_Framework_Assert:: instead of relative path
tdavidsonas88 Dec 11, 2019
05dfa8e
fixes after code review
tdavidsonas88 Dec 13, 2019
bf704b7
work in progress commit
tdavidsonas88 Dec 17, 2019
1a2ac10
Quality improvements after code review - will be more soon
tdavidsonas88 Dec 18, 2019
df99805
Refactored orders tests after code review recommendations
tdavidsonas88 Dec 18, 2019
1501a71
Refactored orders tests after code review recommendations
tdavidsonas88 Dec 18, 2019
e0ece26
Reduced legacy classes usage in the Behat tests;
tdavidsonas88 Dec 19, 2019
7c47efa
Feature: Order from Back Office (BO) code optimized
tdavidsonas88 Dec 19, 2019
7842a11
SearchProductsHandler test coverage
tdavidsonas88 Dec 19, 2019
f76b2b4
SearchProductsHandler test coverage
tdavidsonas88 Dec 19, 2019
1b303a8
written todo's for tests not to depend on the legacy classes
tdavidsonas88 Dec 19, 2019
e0e587d
written todo's for tests not to depend on the legacy classes
tdavidsonas88 Dec 19, 2019
99020fa
ChangeOrderDeliveryAddressHandler test
tdavidsonas88 Dec 19, 2019
98087c2
ChangeOrderDeliveryAddressCommand test covered
tdavidsonas88 Dec 19, 2019
188be7c
ChangeOrderDeliveryAddressCommand test covered
tdavidsonas88 Dec 19, 2019
b22cdf8
more specific todo's
tdavidsonas88 Dec 20, 2019
00f627a
todos left, addresses handlers still depends on legacy address details
tdavidsonas88 Dec 20, 2019
cce3758
todos suggestions to be implemented
tdavidsonas88 Dec 20, 2019
717e011
AddressFeatureContext created
tdavidsonas88 Dec 20, 2019
088f4ec
Scenario: Change order shipping address
tdavidsonas88 Dec 20, 2019
76d0466
code style fixes
tdavidsonas88 Dec 20, 2019
07b6608
code style fixes
tdavidsonas88 Dec 20, 2019
d7c90bf
order feature small changes
tdavidsonas88 Dec 20, 2019
d14d0a7
removed todos
tdavidsonas88 Jan 2, 2020
b58997e
fixes for change order shipping test case
tdavidsonas88 Jan 2, 2020
1aeb61e
pending definition removed
tdavidsonas88 Jan 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions classes/order/Order.php
Expand Up @@ -53,6 +53,7 @@ class OrderCore extends ObjectModel
/** @var int Customer id */
public $id_customer;

// todo: string received instead of int
/** @var int Carrier id */
public $id_carrier;

Expand Down
Expand Up @@ -26,7 +26,7 @@

namespace PrestaShop\PrestaShop\Adapter\Address\CommandHandler;

use CustomerAddress;
use Address;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\SetRequiredFieldsForAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\CommandHandler\SetRequiredFieldsForAddressHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\CannotSetRequiredFieldsForAddressException;
Expand All @@ -46,7 +46,7 @@ final class SetRequiredFieldsForAddressHandler implements SetRequiredFieldsForAd
*/
public function handle(SetRequiredFieldsForAddressCommand $command)
{
$address = new CustomerAddress();
$address = new Address();

try {
if ($address->addFieldsRequiredDatabase($command->getRequiredFields())) {
Expand Down
Expand Up @@ -88,7 +88,7 @@ public function handle(AddOrderFromBackOfficeCommand $command)
$cart->secure_key
);
} catch (Exception $e) {
throw new OrderException('Failed to add order.', 0, $e);
throw new OrderException('Failed to add order. ' . $e->getMessage(), 0, $e);
}

if (!$paymentModule->currentOrder) {
Expand Down
Expand Up @@ -133,6 +133,8 @@ private function assertIsModuleName($moduleName)

/**
* @param int $orderStateId
*
* @throws OrderException
*/
private function assertOrderStateIsPositiveInt($orderStateId)
{
Expand Down
Expand Up @@ -29,6 +29,8 @@
class OrderPaymentsForViewing
{
/**
* hint - collection would be better
*
* @var OrderPaymentForViewing[]
*/
private $payments = [];
Expand Down
Expand Up @@ -29,6 +29,8 @@
class OrderProductsForViewing
{
/**
* hint - collection could be better
*
* @var OrderProductForViewing[]
*/
private $products = [];
Expand Down
Expand Up @@ -78,6 +78,8 @@ public function __construct(
}

/**
* hint - collection of OrderCarrierForViewing objects would be better
*
* @return OrderCarrierForViewing[]
*/
public function getCarriers(): array
Expand Down
2 changes: 0 additions & 2 deletions src/Core/Domain/Product/Query/SearchProducts.php
Expand Up @@ -46,8 +46,6 @@ class SearchProducts
/**
* @param string $phrase
* @param int $resultsLimit
*
* @throws ProductException
*/
public function __construct(string $phrase, int $resultsLimit)
{
Expand Down
Expand Up @@ -26,7 +26,10 @@

namespace PrestaShopBundle\Controller\Admin\Sell\Order;

use Context;
use Currency;
use Exception;
use Language;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CartConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Query\GetCartInformation;
use PrestaShop\PrestaShop\Core\Domain\CustomerMessage\Command\AddOrderCustomerMessageCommand;
Expand All @@ -48,13 +51,13 @@
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\TransistEmailSendingException;
use PrestaShop\PrestaShop\Core\Domain\Order\Invoice\Command\GenerateInvoiceCommand;
use PrestaShop\PrestaShop\Core\Domain\Order\OrderConstraints;
use PrestaShop\PrestaShop\Core\Domain\Order\Invoice\Command\UpdateInvoiceNoteCommand;
use PrestaShop\PrestaShop\Core\Domain\Order\OrderConstraints;
use PrestaShop\PrestaShop\Core\Domain\Order\Payment\Command\AddPaymentCommand;
use PrestaShop\PrestaShop\Core\Domain\Order\Product\Command\UpdateProductInOrderCommand;
use PrestaShop\PrestaShop\Core\Domain\Order\Query\GetOrderForViewing;
use PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderForViewing;
use PrestaShop\PrestaShop\Core\Domain\Order\Query\GetOrderPreview;
use PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderForViewing;
use PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderPreview;
use PrestaShop\PrestaShop\Core\Domain\Order\ValueObject\OrderId;
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\OrderGridDefinitionFactory;
Expand Down Expand Up @@ -137,8 +140,8 @@ private function getOrderToolbarButtons(): array
public function createAction()
{
return $this->render('@PrestaShop/Admin/Sell/Order/Order/create.html.twig', [
'currencies' => \Currency::getCurrenciesByIdShop(\Context::getContext()->shop->id),
'languages' => \Language::getLanguages(true, \Context::getContext()->shop->id),
'currencies' => Currency::getCurrenciesByIdShop(Context::getContext()->shop->id),
'languages' => Language::getLanguages(true, Context::getContext()->shop->id),
]);
}

Expand Down
Expand Up @@ -196,6 +196,8 @@ public function createAddress($addressName, $postCode, $stateName)
$address->alias = 'alias';
$address->add();
$this->addresses[$addressName] = $address;

SharedStorage::getStorage()->set($addressName, $address->id);
}

/**
Expand Down
Expand Up @@ -88,7 +88,7 @@ public function customerHasAddressInCountry($reference, $isoCode)
}
}

throw new Exception(sprintf(
throw new RuntimeException(sprintf(
'Customer does not have address in "%s" country',
$isoCode
));
Expand Down
Expand Up @@ -32,6 +32,7 @@
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\DeleteCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\EditCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\TransformGuestToCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\DuplicateCustomerEmailException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Query\GetCustomerForEditing;
use PrestaShop\PrestaShop\Core\Domain\Customer\QueryResult\EditableCustomer;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerDeleteMethod;
Expand Down Expand Up @@ -65,6 +66,8 @@ class CustomerManagerFeatureContext extends AbstractPrestaShopFeatureContext
protected $customerRegistry = [];

/**
* todo hint: move to domain context?
*
* @When /^I create a customer "(.+)" with following properties:$/
*/
public function createACustomerUsingCommand($customerReference, TableNode $table)
Expand Down Expand Up @@ -110,9 +113,13 @@ public function createACustomerUsingCommand($customerReference, TableNode $table

$this->latestResult = $id->getValue();
$this->customerRegistry[$customerReference] = $id->getValue();

SharedStorage::getStorage()->set($customerReference, $id->getValue());
}

/**
* todo hint: move to domain context?
*
* @When /^I attempt to create a customer "(.+)" with following properties:$/
*/
public function attemptToCreateACustomerUsingCommand($customerReference, TableNode $table)
Expand All @@ -129,6 +136,24 @@ public function attemptToCreateACustomerUsingCommand($customerReference, TableNo
}
}

/**
* todo hint: move to domain context?
*
* @When I create not existing customer :customerReference with following properties:
*
* @param string $customerReference
* @param TableNode $table
*/
public function iCreateNotExistingCustomerWithFollowingProperties(string $customerReference, TableNode $table)
{
try {
/** @var CustomerId $customerIdObject */
$customerIdObject = $this->createACustomerUsingCommand($customerReference, $table);
SharedStorage::getStorage()->set($customerReference, $customerIdObject->getValue());
} catch (DuplicateCustomerEmailException $e) {
}
}

/**
* @When /^I edit customer "(.+)" and I change the following properties:$/
*/
Expand Down
Expand Up @@ -104,8 +104,6 @@ protected function assertLastErrorIsNull()
/**
* @param string $expectedError
* @param int|null $errorCode
*
* @throws RuntimeException
*/
protected function assertLastErrorIs($expectedError, $errorCode = null)
{
Expand Down
Expand Up @@ -29,16 +29,18 @@
use Cart;
use Configuration;
use Context;
use Currency;
use Country;
use Currency;
use Customer;
use Exception;
use PrestaShop\PrestaShop\Core\Domain\Cart\Command\CreateEmptyCustomerCartCommand;
use PrestaShop\PrestaShop\Core\Domain\Cart\Command\SetFreeShippingToCartCommand;
use PrestaShop\PrestaShop\Core\Domain\Cart\Command\UpdateCartAddressesCommand;
use PrestaShop\PrestaShop\Core\Domain\Cart\Command\UpdateProductQuantityInCartCommand;
use PrestaShop\PrestaShop\Core\Domain\Cart\ValueObject\CartId;
use PrestaShop\PrestaShop\Core\Domain\Cart\ValueObject\QuantityAction;
use Product;
use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts;
use RuntimeException;
use Tests\Integration\Behaviour\Features\Context\SharedStorage;

class CartFeatureContext extends AbstractDomainFeatureContext
Expand All @@ -60,45 +62,64 @@ public function addCurrencyToContext($currencyIsoCode)

/**
* @When I create an empty cart :cartReference for customer :customerReference
*
* @param string $cartReference
* @param string $customerReference
*/
public function createEmptyCartForCustomer($cartReference, $customerReference)
public function createEmptyCartForCustomer(string $cartReference, string $customerReference)
{
// Clear static cache each time you create a cart
Cart::resetStaticCache();
/** @var Customer $customer */
$customer = SharedStorage::getStorage()->get($customerReference);

/** @var CartId $cartId */
$cartId = $this->getCommandBus()->handle(
/** @var CartId $cartIdObject */
$cartIdObject = $this->getCommandBus()->handle(
new CreateEmptyCustomerCartCommand(
(int) $customer->id,
(int) Context::getContext()->shop->id
(int) $customer->id
)
);

SharedStorage::getStorage()->set($cartReference, new Cart($cartId->getValue()));
SharedStorage::getStorage()->set($cartReference, $cartIdObject->getValue());
}

/**
* @When I add :quantity products with reference :productReference to the cart :reference
* @When I add :quantity products :productName to the cart :cartReference
*
* @param int $quantity
* @param string $productName
* @param string $cartReference
*/
public function addProductToCarts($quantity, $productReference, $reference)
public function addProductsToCarts(int $quantity, string $productName, string $cartReference)
{
$productId = (int) Product::getIdByReference($productReference);
/** @var array $productsMap */
$productsMap = $this->getQueryBus()->handle(new SearchProducts($productName, 1));
$productId = array_key_first($productsMap);

if (!$productId) {
throw new RuntimeException('Product with name "%s" does not exist', $productName);
}

$this->getCommandBus()->handle(
new UpdateProductQuantityInCartCommand(
(int) SharedStorage::getStorage()->get($reference)->id,
SharedStorage::getStorage()->get($cartReference),
$productId,
(int) $quantity,
QuantityAction::INCREASE_PRODUCT_QUANTITY
)
);

SharedStorage::getStorage()->set($productName, $productId);
}

/**
* @When I select :countryIsoCode address as delivery and invoice address for customer :customerReference in cart :cartReference
*
* @param string $countryIsoCode
* @param string $customerReference
* @param string $cartReference
*/
public function selectAddressAsDeliveryAndInvoiceAddress($countryIsoCode, $customerReference, $cartReference)
public function selectAddressAsDeliveryAndInvoiceAddress(string $countryIsoCode, string $customerReference, string $cartReference)
{
$customer = SharedStorage::getStorage()->get($customerReference);

Expand All @@ -120,21 +141,23 @@ public function selectAddressAsDeliveryAndInvoiceAddress($countryIsoCode, $custo

$this->getCommandBus()->handle(
new UpdateCartAddressesCommand(
(int) SharedStorage::getStorage()->get($cartReference)->id,
(int) SharedStorage::getStorage()->get($cartReference),
$addressId,
$addressId
)
);
}

/**
* @When I set Free shipping to the cart :reference
* @When I set Free shipping to the cart :cartReference
*
* @param string $cartReference
*/
public function setFreeShippingToCart($reference)
public function setFreeShippingToCart(string $cartReference)
{
$this->getCommandBus()->handle(
new SetFreeShippingToCartCommand(
(int) SharedStorage::getStorage()->get($reference)->id,
SharedStorage::getStorage()->get($cartReference),
true
)
);
Expand Down