Skip to content

Commit e92b01e

Browse files
committed
MTA-3236: Order Management: Extend existing functional automated tests
- merge commit
2 parents 7ba8f24 + 53241d3 commit e92b01e

File tree

13 files changed

+341
-74
lines changed

13 files changed

+341
-74
lines changed

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,25 +279,40 @@ public function updateItems()
279279
}
280280

281281
/**
282-
* Fill addresses based on present data in customer and order fixtures.
282+
* Fill Billing Address.
283283
*
284-
* @param FixtureInterface $address
285-
* @param string $saveAddress
284+
* @param FixtureInterface $billingAddress
285+
* @param string $saveAddress [optional]
286286
* @param bool $setShippingAddress [optional]
287287
* @return void
288288
*/
289-
public function fillAddresses(FixtureInterface $address, $saveAddress = 'No', $setShippingAddress = true)
290-
{
289+
public function fillBillingAddress(
290+
FixtureInterface $billingAddress,
291+
$saveAddress = 'No',
292+
$setShippingAddress = true
293+
) {
291294
if ($setShippingAddress) {
292295
$this->getShippingAddressBlock()->uncheckSameAsBillingShippingAddress();
293296
}
294-
$this->browser->find($this->header)->hover();
295-
$this->getBillingAddressBlock()->fill($address);
297+
$this->getBillingAddressBlock()->fill($billingAddress);
296298
$this->getBillingAddressBlock()->saveInAddressBookBillingAddress($saveAddress);
297299
$this->getTemplateBlock()->waitLoader();
298-
if ($setShippingAddress) {
300+
}
301+
302+
/**
303+
* Fill Shipping Address.
304+
*
305+
* @param FixtureInterface $shippingAddress [optional]
306+
* @return void
307+
*/
308+
public function fillShippingAddress(FixtureInterface $shippingAddress = null)
309+
{
310+
if (!$shippingAddress) {
299311
$this->getShippingAddressBlock()->setSameAsBillingShippingAddress();
300312
$this->getTemplateBlock()->waitLoader();
313+
} else {
314+
$this->getShippingAddressBlock()->fill($shippingAddress);
315+
$this->getTemplateBlock()->waitLoader();
301316
}
302317
}
303318

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Shipping/Address.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Mtf\Block\Form;
1010
use Magento\Mtf\Client\Locator;
1111
use Magento\Backend\Test\Block\Template;
12+
use Magento\Mtf\Client\Element\SimpleElement;
1213

1314
/**
1415
* Adminhtml sales order create shipping address block.
@@ -29,6 +30,13 @@ class Address extends Form
2930
*/
3031
protected $sameAsBilling = '#order-shipping_same_as_billing';
3132

33+
/**
34+
* Wait element.
35+
*
36+
* @var string
37+
*/
38+
private $waitElement = '.loading-mask';
39+
3240
/**
3341
* Shipping address title selector.
3442
*
@@ -95,4 +103,41 @@ protected function getTemplateBlock()
95103
['element' => $this->_rootElement->find($this->templateBlock, Locator::SELECTOR_XPATH)]
96104
);
97105
}
106+
107+
/**
108+
* Fill specified form data.
109+
*
110+
* @param array $fields
111+
* @param SimpleElement $element
112+
* @return void
113+
* @throws \Exception
114+
*/
115+
protected function _fill(array $fields, SimpleElement $element = null)
116+
{
117+
$context = ($element === null) ? $this->_rootElement : $element;
118+
foreach ($fields as $name => $field) {
119+
$this->waitFormLoading();
120+
$element = $this->getElement($context, $field);
121+
if (!$element->isDisabled()) {
122+
$element->setValue($field['value']);
123+
} else {
124+
throw new \Exception("Unable to set value to field '$name' as it's disabled.");
125+
}
126+
}
127+
}
128+
129+
/**
130+
* Wait for form loading.
131+
*
132+
* @return void
133+
*/
134+
private function waitFormLoading()
135+
{
136+
$this->_rootElement->click();
137+
$this->browser->waitUntil(
138+
function () {
139+
return $this->browser->find($this->waitElement)->isVisible() ? null : true;
140+
}
141+
);
142+
}
98143
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<mapping strict="0">
9+
<wrapper>order[shipping_address]</wrapper>
10+
<fields>
11+
<firstname />
12+
<lastname />
13+
<company />
14+
<street>
15+
<selector>[name='order[shipping_address][street][0]']</selector>
16+
</street>
17+
<city />
18+
<country_id>
19+
<input>select</input>
20+
</country_id>
21+
<region_id>
22+
<input>select</input>
23+
</region_id>
24+
<postcode />
25+
<telephone />
26+
</fields>
27+
</mapping>

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Shipping/Method.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class Method extends Block
2828
*/
2929
protected $shippingMethod = '//dt[contains(.,"%s")]/following-sibling::*//*[contains(text(), "%s")]';
3030

31+
/**
32+
* Wait element.
33+
*
34+
* @var string
35+
*/
36+
private $waitElement = '.loading-mask';
37+
3138
/**
3239
* Select shipping method.
3340
*
@@ -36,6 +43,7 @@ class Method extends Block
3643
*/
3744
public function selectShippingMethod(array $shippingMethod)
3845
{
46+
$this->waitFormLoading();
3947
if ($this->_rootElement->find($this->shippingMethodsLink)->isVisible()) {
4048
$this->_rootElement->find($this->shippingMethodsLink)->click();
4149
}
@@ -46,4 +54,19 @@ public function selectShippingMethod(array $shippingMethod)
4654
);
4755
$this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->click();
4856
}
57+
58+
/**
59+
* Wait for form loading.
60+
*
61+
* @return void
62+
*/
63+
private function waitFormLoading()
64+
{
65+
$this->_rootElement->click();
66+
$this->browser->waitUntil(
67+
function () {
68+
return $this->browser->find($this->waitElement)->isVisible() ? null : true;
69+
}
70+
);
71+
}
4972
}

dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
1111
use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
1212
use Magento\Mtf\TestCase\Injectable;
13+
use Magento\Mtf\TestStep\TestStepFactory;
1314

1415
/**
1516
* Preconditions:
16-
* 1. Enable payment method "Check/Money Order".
17-
* 2. Enable shipping method one of "Flat Rate".
18-
* 3. Create order
17+
* 1. Enable payment method: "Check/Money Order/Bank Transfer/Cash on Delivery/Purchase Order/Zero Subtotal Checkout".
18+
* 2. Enable shipping method one of "Flat Rate/Free Shipping".
19+
* 3. Create order.
1920
*
2021
* Steps:
2122
* 1. Login to backend.
@@ -48,20 +49,7 @@ class CancelCreatedOrderTest extends Injectable
4849
protected $salesOrderView;
4950

5051
/**
51-
* Enable "Check/Money Order" and "Flat Rate" in configuration.
52-
*
53-
* @return void
54-
*/
55-
public function __prepare()
56-
{
57-
$this->objectManager->create(
58-
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
59-
['configData' => 'checkmo, flatrate', 'rollback' => true]
60-
)->run();
61-
}
62-
63-
/**
64-
* Inject pages
52+
* Inject pages.
6553
*
6654
* @param OrderIndex $orderIndex
6755
* @param SalesOrderView $salesOrderView
@@ -77,11 +65,17 @@ public function __inject(OrderIndex $orderIndex, SalesOrderView $salesOrderView)
7765
* Cancel created order.
7866
*
7967
* @param OrderInjectable $order
68+
* @param TestStepFactory $stepFactory
69+
* @param string $configData
8070
* @return array
8171
*/
82-
public function test(OrderInjectable $order)
72+
public function test(OrderInjectable $order, TestStepFactory $stepFactory, $configData)
8373
{
8474
// Preconditions
75+
$stepFactory->create(
76+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
77+
['configData' => $configData]
78+
)->run();
8579
$order->persist();
8680

8781
// Steps

dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.xml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,49 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Sales\Test\TestCase\CancelCreatedOrderTest" summary="Cancel Created Order for Offline Payment Methods" ticketId="MAGETWO-28191">
10-
<variation name="CancelCreatedOrderTestVariation1">
11-
<data name="description" xsi:type="string">cancel order and check status on storefront</data>
10+
<variation name="CancelCreatedOrderTestVariationWithCheckMoneyOrderPaymentMethod" summary="Cancel order with check/money order payment method and check status on storefront">
1211
<data name="order/dataset" xsi:type="string">default</data>
1312
<data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data>
1413
<data name="status" xsi:type="string">Canceled</data>
14+
<data name="configData" xsi:type="string">checkmo</data>
1515
<constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelSuccessMessage" />
1616
<constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" />
1717
<constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" />
1818
</variation>
19+
<variation name="CancelCreatedOrderTestVariationWithZeroSubtotalCheckout" summary="Cancel order with zero subtotal checkout payment method and check status on storefront">
20+
<data name="order/dataset" xsi:type="string">default</data>
21+
<data name="order/data/payment_auth_expiration/method" xsi:type="string">free</data>
22+
<data name="order/data/shipping_method" xsi:type="string">freeshipping_freeshipping</data>
23+
<data name="order/data/coupon_code/dataset" xsi:type="string">active_sales_rule_with_fixed_price_discount_coupon</data>
24+
<data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::product_10_dollar</data>
25+
<data name="status" xsi:type="string">Canceled</data>
26+
<data name="configData" xsi:type="string">zero_subtotal_checkout, freeshipping</data>
27+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelSuccessMessage" />
28+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" />
29+
</variation>
30+
<variation name="CancelCreatedOrderTestVariationWithBankTransferPaymentMethod" summary="Cancel order with bank transfer payment method and check status on storefront">
31+
<data name="order/dataset" xsi:type="string">default</data>
32+
<data name="order/data/payment_auth_expiration/method" xsi:type="string">banktransfer</data>
33+
<data name="status" xsi:type="string">Canceled</data>
34+
<data name="configData" xsi:type="string">banktransfer</data>
35+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelSuccessMessage" />
36+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" />
37+
</variation>
38+
<variation name="CancelCreatedOrderTestVariationWithCashOnDeliveryPaymentMethod" summary="Cancel order with cash on delivery payment method and check status on storefront">
39+
<data name="order/dataset" xsi:type="string">default</data>
40+
<data name="order/data/payment_auth_expiration/method" xsi:type="string">cashondelivery</data>
41+
<data name="status" xsi:type="string">Canceled</data>
42+
<data name="configData" xsi:type="string">cashondelivery</data>
43+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelSuccessMessage" />
44+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" />
45+
</variation>
46+
<variation name="CancelCreatedOrderTestVariationWithPurchaseOrderPaymentMethod" summary="Cancel order with purchase order payment method and check status on storefront">
47+
<data name="order/dataset" xsi:type="string">default</data>
48+
<data name="order/data/payment_auth_expiration/method" xsi:type="string">purchaseorder</data>
49+
<data name="status" xsi:type="string">Canceled</data>
50+
<data name="configData" xsi:type="string">purchaseorder</data>
51+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelSuccessMessage" />
52+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" />
53+
</variation>
1954
</testCase>
2055
</config>

dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCreditMemoEntityTest.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
use Magento\Mtf\Fixture\FixtureFactory;
1111
use Magento\Mtf\Fixture\FixtureInterface;
1212
use Magento\Mtf\TestCase\Injectable;
13+
use Magento\Mtf\TestStep\TestStepFactory;
1314

1415
/**
1516
* Preconditions:
16-
* 1. Enable payment method "Check/Money Order".
17+
* 1. Enable payment method one of "Check/Money Order/Bank Transfer/Cash on Delivery/Purchase Order".
1718
* 2. Enable shipping method one of "Flat Rate/Free Shipping".
1819
* 3. Create order.
1920
* 4. Create Invoice.
@@ -54,38 +55,34 @@ class CreateCreditMemoEntityTest extends Injectable
5455
'price',
5556
];
5657

57-
/**
58-
* Set up configuration.
59-
*
60-
* @param FixtureFactory $fixtureFactory
61-
* @return void
62-
*/
63-
public function __prepare(FixtureFactory $fixtureFactory)
64-
{
65-
$this->fixtureFactory = $fixtureFactory;
66-
67-
$setupConfigurationStep = $this->objectManager->create(
68-
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
69-
['configData' => 'checkmo, flatrate']
70-
);
71-
$setupConfigurationStep->run();
72-
}
73-
7458
/**
7559
* Create credit memo.
7660
*
61+
* @param TestStepFactory $stepFactory
62+
* @param FixtureFactory $fixtureFactory
7763
* @param OrderInjectable $order
7864
* @param array $data
65+
* @param string $configData
7966
* @return array
8067
*/
81-
public function test(OrderInjectable $order, array $data)
82-
{
68+
public function test(
69+
TestStepFactory $stepFactory,
70+
FixtureFactory $fixtureFactory,
71+
OrderInjectable $order,
72+
array $data,
73+
$configData
74+
) {
8375
// Preconditions
76+
$this->fixtureFactory = $fixtureFactory;
77+
$stepFactory->create(
78+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
79+
['configData' => $configData]
80+
)->run();
8481
$order->persist();
85-
$this->objectManager->create(\Magento\Sales\Test\TestStep\CreateInvoiceStep::class, ['order' => $order])->run();
82+
$stepFactory->create(\Magento\Sales\Test\TestStep\CreateInvoiceStep::class, ['order' => $order])->run();
8683

8784
// Steps
88-
$createCreditMemoStep = $this->objectManager->create(
85+
$createCreditMemoStep = $stepFactory->create(
8986
\Magento\Sales\Test\TestStep\CreateCreditMemoStep::class,
9087
['order' => $order, 'data' => $data]
9188
);

0 commit comments

Comments
 (0)