Skip to content

Commit affd1ee

Browse files
committed
Merge pull request #136 from magento-mpi/MTA-560
[MPI] Refactor end-to-end functional 3rd party tests
2 parents e2ef0d5 + 24e867b commit affd1ee

File tree

10 files changed

+201
-70
lines changed

10 files changed

+201
-70
lines changed

dev/tests/functional/credentials.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@
2424

2525
<field path="section/carriers_usps_userid/value" value="" />
2626
<field path="section/carriers_usps_password/value" value="" />
27+
28+
<field path="section/payment_authorizenet_login/value" value="" />
29+
<field path="section/payment_authorizenet_trans_key/value" value="" />
30+
31+
<field path="section/payment_paypal_group_all_in_one_wpp_usuk_wpp_required_settings_wpp_and_express_checkout_business_account/value" value="" />
32+
<field path="section/payment_paypal_group_all_in_one_wpp_usuk_wpp_required_settings_wpp_and_express_checkout_api_username/value" value="" />
33+
<field path="section/payment_paypal_group_all_in_one_wpp_usuk_wpp_required_settings_wpp_and_express_checkout_api_password/value" value="" />
34+
<field path="section/payment_paypal_group_all_in_one_wpp_usuk_wpp_required_settings_wpp_and_express_checkout_api_signature/value" value="" />
35+
36+
<field path="section/payment_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_business_account/value" value="" />
37+
<field path="section/payment_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_partner/value" value="" />
38+
<field path="section/payment_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_user/value" value="" />
39+
<field path="section/payment_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_pwd/value" value="" />
40+
<field path="section/payment_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_vendor/value" value="" />
2741
</replace>

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/Methods.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Checkout\Test\Block\Onepage\Payment;
88

99
use Magento\Mtf\Block\Form;
10+
use Magento\Payment\Test\Fixture\CreditCard;
1011

1112
/**
1213
* Class Methods
@@ -61,10 +62,11 @@ class Methods extends Form
6162
* Select payment method
6263
*
6364
* @param array $payment
65+
* @param CreditCard|null $creditCard
6466
* @throws \Exception
6567
* @return void
6668
*/
67-
public function selectPaymentMethod(array $payment)
69+
public function selectPaymentMethod(array $payment, CreditCard $creditCard = null)
6870
{
6971
$paymentSelector = $this->_rootElement->find(sprintf($this->paymentMethodInput, $payment['method']));
7072
if ($paymentSelector->isVisible()) {
@@ -79,14 +81,13 @@ public function selectPaymentMethod(array $payment)
7981
if ($payment['method'] == "purchaseorder") {
8082
$this->_rootElement->find($this->purchaseOrderNumber)->setValue($payment['po_number']);
8183
}
82-
if (isset($payment['dataConfig']['payment_form_class'])) {
83-
$paymentFormClass = $payment['dataConfig']['payment_form_class'];
84+
if ($creditCard !== null) {
8485
/** @var \Magento\Payment\Test\Block\Form\Cc $formBlock */
8586
$formBlock = $this->blockFactory->create(
86-
$paymentFormClass,
87+
'\\Magento\\Payment\\Test\\Block\\Form\\Cc',
8788
['element' => $this->_rootElement->find('#payment_form_' . $payment['method'])]
8889
);
89-
$formBlock->fill($payment['credit_card']);
90+
$formBlock->fill($creditCard);
9091
}
9192
}
9293

dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/EstimateShippingAndTaxStep.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,27 @@ class EstimateShippingAndTaxStep implements TestStepInterface
7575
* @param CheckoutCart $checkoutCart
7676
* @param Address $address
7777
* @param AssertEstimateShippingAndTax $assertEstimateShippingAndTax
78-
* @param Cart $cart
7978
* @param FixtureFactory $fixtureFactory
80-
* @param array $shipping
8179
* @param array $products
80+
* @param array $shipping
81+
* @param Cart|null $cart
8282
*/
8383
public function __construct(
8484
CheckoutCart $checkoutCart,
8585
Address $address,
8686
AssertEstimateShippingAndTax $assertEstimateShippingAndTax,
87-
Cart $cart,
8887
FixtureFactory $fixtureFactory,
89-
array $shipping,
90-
array $products
88+
array $products,
89+
array $shipping = [],
90+
Cart $cart = null
9191
) {
9292
$this->checkoutCart = $checkoutCart;
9393
$this->address = $address;
9494
$this->assertEstimateShippingAndTax = $assertEstimateShippingAndTax;
95-
$this->cart = $cart;
9695
$this->fixtureFactory = $fixtureFactory;
97-
$this->shipping = $shipping;
9896
$this->products = $products;
97+
$this->shipping = $shipping;
98+
$this->cart = $cart;
9999
}
100100

101101
/**
@@ -106,16 +106,16 @@ public function __construct(
106106
public function run()
107107
{
108108
$this->checkoutCart->open();
109-
$this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($this->address);
110-
if ($this->shipping['shipping_service'] !== '-') {
111-
$this->checkoutCart->getShippingBlock()->selectShippingMethod($this->shipping);
112-
}
113109
/** @var \Magento\Checkout\Test\Fixture\Cart $cart */
114-
if (!empty($this->cart->hasData())) {
110+
if ($this->cart !== null) {
115111
$cart = $this->fixtureFactory->createByCode(
116112
'cart',
117113
['data' => array_merge($this->cart->getData(), ['items' => ['products' => $this->products]])]
118114
);
115+
$this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($this->address);
116+
if (!empty($this->shipping)) {
117+
$this->checkoutCart->getShippingBlock()->selectShippingMethod($this->shipping);
118+
}
119119
$this->assertEstimateShippingAndTax->processAssert($this->checkoutCart, $cart);
120120
}
121121
}

dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillShippingMethodStep.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FillShippingMethodStep implements TestStepInterface
3434
* @param CheckoutOnepage $checkoutOnepage
3535
* @param array $shipping
3636
*/
37-
public function __construct(CheckoutOnepage $checkoutOnepage, array $shipping)
37+
public function __construct(CheckoutOnepage $checkoutOnepage, array $shipping = [])
3838
{
3939
$this->checkoutOnepage = $checkoutOnepage;
4040
$this->shipping = $shipping;
@@ -47,7 +47,7 @@ public function __construct(CheckoutOnepage $checkoutOnepage, array $shipping)
4747
*/
4848
public function run()
4949
{
50-
if ($this->shipping['shipping_service'] !== '-') {
50+
if (!empty($this->shipping)) {
5151
$this->checkoutOnepage->getShippingMethodBlock()->selectShippingMethod($this->shipping);
5252
$this->checkoutOnepage->getShippingMethodBlock()->clickContinue();
5353
}

dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/SelectPaymentMethodStep.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Checkout\Test\Page\CheckoutOnepage;
1010
use Magento\Mtf\TestStep\TestStepInterface;
11+
use Magento\Payment\Test\Fixture\CreditCard;
1112

1213
/**
1314
* Class SelectPaymentMethodStep
@@ -29,15 +30,27 @@ class SelectPaymentMethodStep implements TestStepInterface
2930
*/
3031
protected $payment;
3132

33+
/**
34+
* Credit card information
35+
*
36+
* @var string
37+
*/
38+
protected $creditCard;
39+
3240
/**
3341
* @constructor
3442
* @param CheckoutOnepage $checkoutOnepage
3543
* @param array $payment
44+
* @param CreditCard|null $creditCard
3645
*/
37-
public function __construct(CheckoutOnepage $checkoutOnepage, array $payment)
38-
{
46+
public function __construct(
47+
CheckoutOnepage $checkoutOnepage,
48+
array $payment,
49+
CreditCard $creditCard = null
50+
) {
3951
$this->checkoutOnepage = $checkoutOnepage;
4052
$this->payment = $payment;
53+
$this->creditCard = $creditCard;
4154
}
4255

4356
/**
@@ -48,7 +61,7 @@ public function __construct(CheckoutOnepage $checkoutOnepage, array $payment)
4861
public function run()
4962
{
5063
if ($this->payment['method'] !== 'free') {
51-
$this->checkoutOnepage->getPaymentMethodsBlock()->selectPaymentMethod($this->payment);
64+
$this->checkoutOnepage->getPaymentMethodsBlock()->selectPaymentMethod($this->payment, $this->creditCard);
5265
}
5366
$this->checkoutOnepage->getPaymentMethodsBlock()->clickContinue();
5467
}

dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/TestCase/etc/testcase.xsd">
9-
<scenario name="OnePageCheckoutTest" firstStep="setupConfiguration">
10-
<step name="setupConfiguration" module="Magento_Core" next="createProducts"/>
11-
<step name="createProducts" module="Magento_Catalog" next="createTaxRule"/>
12-
<step name="createTaxRule" module="Magento_Tax" next="addProductsToTheCart"/>
13-
<step name="addProductsToTheCart" module="Magento_Checkout" next="estimateShippingAndTax"/>
14-
<step name="estimateShippingAndTax" module="Magento_Checkout" next="proceedToCheckout"/>
15-
<step name="proceedToCheckout" module="Magento_Checkout" next="selectCheckoutMethod"/>
16-
<step name="createCustomer" module="Magento_Customer" next="selectCheckoutMethod"/>
17-
<step name="selectCheckoutMethod" module="Magento_Checkout" next="fillBillingInformation"/>
18-
<step name="fillBillingInformation" module="Magento_Checkout" next="fillShippingMethod"/>
19-
<step name="fillShippingMethod" module="Magento_Checkout" next="selectPaymentMethod"/>
20-
<step name="selectPaymentMethod" module="Magento_Checkout" next="placeOrder"/>
21-
<step name="placeOrder" module="Magento_Checkout"/>
22-
</scenario>
9+
<scenario name="OnePageCheckoutTest" firstStep="setupConfiguration">
10+
<step name="setupConfiguration" module="Magento_Core" next="createProducts"/>
11+
<step name="createProducts" module="Magento_Catalog" next="createTaxRule"/>
12+
<step name="createTaxRule" module="Magento_Tax" next="addProductsToTheCart"/>
13+
<step name="addProductsToTheCart" module="Magento_Checkout" next="estimateShippingAndTax"/>
14+
<step name="estimateShippingAndTax" module="Magento_Checkout" next="proceedToCheckout"/>
15+
<step name="proceedToCheckout" module="Magento_Checkout" next="createCustomer"/>
16+
<step name="createCustomer" module="Magento_Customer" next="selectCheckoutMethod"/>
17+
<step name="selectCheckoutMethod" module="Magento_Checkout" next="fillBillingInformation"/>
18+
<step name="fillBillingInformation" module="Magento_Checkout" next="fillShippingMethod"/>
19+
<step name="fillShippingMethod" module="Magento_Checkout" next="selectPaymentMethod"/>
20+
<step name="selectPaymentMethod" module="Magento_Checkout" next="placeOrder"/>
21+
<step name="placeOrder" module="Magento_Checkout"/>
22+
</scenario>
2323
</config>

dev/tests/functional/tests/app/Magento/Core/Test/Handler/ConfigData/Curl.php

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class Curl extends AbstractCurl implements ConfigDataInterface
2121
{
2222
/**
23-
* Mapping values for data
23+
* Mapping values for data.
2424
*
2525
* @var array
2626
*/
@@ -33,7 +33,7 @@ class Curl extends AbstractCurl implements ConfigDataInterface
3333
];
3434

3535
/**
36-
* Post request for setting configuration
36+
* Post request for setting configuration.
3737
*
3838
* @param FixtureInterface|null $fixture [optional]
3939
* @return void
@@ -47,29 +47,60 @@ public function persist(FixtureInterface $fixture = null)
4747
}
4848

4949
/**
50-
* Prepare POST data for setting configuration
50+
* Prepare POST data for setting configuration.
5151
*
5252
* @param FixtureInterface $fixture
5353
* @return array
5454
*/
5555
protected function prepareData(FixtureInterface $fixture)
5656
{
57+
$configPath = [];
5758
$result = [];
5859
$fields = $fixture->getData();
5960
if (isset($fields['section'])) {
6061
foreach ($fields['section'] as $itemSection) {
61-
list($scope, $group, $field) = explode('/', $itemSection['path']);
62-
$value = isset($this->mappingData[$field])
63-
? $this->mappingData[$field][$itemSection['value']]
64-
: $itemSection['value'];
65-
$result[$scope]['groups'][$group]['fields'][$field]['value'] = $value;
62+
parse_str($this->prepareConfigPath($itemSection), $configPath);
63+
$result = array_merge_recursive($result, $configPath);
6664
}
6765
}
6866
return $result;
6967
}
7068

7169
/**
72-
* Apply config settings via curl
70+
* Prepare config path.
71+
*
72+
* From payment/cashondelivery/active to ['payment']['groups']['cashondelivery']['fields']['active']
73+
*
74+
* @param array $input
75+
* @return string
76+
*/
77+
protected function prepareConfigPath(array $input)
78+
{
79+
$resultArray = '';
80+
$path = explode('/', $input['path']);
81+
foreach ($path as $position => $subPath) {
82+
if ($position === 0) {
83+
$resultArray.= $subPath;
84+
continue;
85+
} elseif ($position === (count($path) - 1)) {
86+
$resultArray.= '[fields]';
87+
} else {
88+
$resultArray.= '[groups]';
89+
}
90+
$resultArray.= '[' . $subPath .']';
91+
}
92+
$resultArray.= '[value]';
93+
if (is_array($input['value'])) {
94+
$resultArray.= '[' . key($input['value']) . ']';
95+
$resultArray.= '=' . current($input['value']);
96+
} else {
97+
$resultArray.= '=' . $input['value'];
98+
}
99+
return $resultArray;
100+
}
101+
102+
/**
103+
* Apply config settings via curl.
73104
*
74105
* @param array $data
75106
* @param string $section
@@ -90,7 +121,7 @@ protected function applyConfigSettings(array $data, $section)
90121
}
91122

92123
/**
93-
* Retrieve URL for request
124+
* Retrieve URL for request.
94125
*
95126
* @param string $section
96127
* @return string

dev/tests/functional/tests/app/Magento/OfflinePayments/Test/Repository/ConfigData.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
<dataset name="cashondelivery_specificcountry_gb">
1919
<field path="payment/cashondelivery/active" scope="payment" scope_id="1" label="Yes" xsi:type="string">1</field>
2020
<field path="payment/cashondelivery/allowspecific" scope="payment" scope_id="1" label="Specific Countries" xsi:type="string">1</field>
21-
<field path="payment/cashondelivery/specificcountry/active" scope="payment" scope_id="1" label="United Kingdom" xsi:type="string">GB</field>
21+
<field path="payment/cashondelivery/specificcountry" scope="payment" scope_id="1" xsi:type="array">
22+
<item label="United Kingdom" xsi:type="string">GB</item>
23+
</field>
2224
</dataset>
2325

2426
<dataset name="cashondelivery_specificcountry_gb_rollback">
@@ -37,7 +39,9 @@
3739
<dataset name="checkmo_specificcountry_gb">
3840
<field path="payment/checkmo/active" scope="payment" scope_id="1" label="Yes" xsi:type="string">1</field>
3941
<field path="payment/checkmo/allowspecific" scope="payment" scope_id="1" label="Specific Countries" xsi:type="string">1</field>
40-
<field path="payment/checkmo/specificcountry/active" scope="payment" scope_id="1" label="United Kingdom" xsi:type="string">GB</field>
42+
<field path="payment/checkmo/specificcountry" scope="payment" scope_id="1" xsi:type="array">
43+
<item label="United Kingdom" xsi:type="string">GB</item>
44+
</field>
4145
</dataset>
4246

4347
<dataset name="checkmo_specificcountry_gb_rollback">
@@ -56,7 +60,9 @@
5660
<dataset name="banktransfer_specificcountry_gb">
5761
<field path="payment/banktransfer/active" scope="payment" scope_id="1" label="Yes" xsi:type="string">1</field>
5862
<field path="payment/banktransfer/allowspecific" scope="payment" scope_id="1" label="Specific Countries" xsi:type="string">1</field>
59-
<field path="payment/banktransfer/specificcountry/active" scope="payment" scope_id="1" label="United Kingdom" xsi:type="string">GB</field>
63+
<field path="payment/banktransfer/specificcountry" scope="payment" scope_id="1" xsi:type="array">
64+
<item label="United Kingdom" xsi:type="string">GB</item>
65+
</field>
6066
</dataset>
6167

6268
<dataset name="banktransfer_specificcountry_gb_rollback">
@@ -75,7 +81,9 @@
7581
<dataset name="purchaseorder_specificcountry_gb">
7682
<field path="payment/purchaseorder/active" scope="payment" scope_id="1" label="Yes" xsi:type="string">1</field>
7783
<field path="payment/purchaseorder/allowspecific" scope="payment" scope_id="1" label="Specific Countries" xsi:type="string">1</field>
78-
<field path="payment/purchaseorder/specificcountry/active" scope="payment" scope_id="1" label="United Kingdom" xsi:type="string">GB</field>
84+
<field path="payment/purchaseorder/specificcountry" scope="payment" scope_id="1" xsi:type="array">
85+
<item label="United Kingdom" xsi:type="string">GB</item>
86+
</field>
7987
</dataset>
8088

8189
<dataset name="purchaseorder_specificcountry_gb_rollback">

0 commit comments

Comments
 (0)