Skip to content

Commit 76611ae

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-60958' into 2.1.8-develop-pr24
# Conflicts: # dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/Method.php # dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml
2 parents 3d35dd7 + 0f27eba commit 76611ae

File tree

12 files changed

+400
-13
lines changed

12 files changed

+400
-13
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ define(
4444
addressData.region.region_code = region['code'];
4545
addressData.region.region = region['name'];
4646
}
47+
} else if (
48+
!addressData.region_id
49+
&& countryData()[addressData.country_id]
50+
&& countryData()[addressData.country_id]['regions']
51+
) {
52+
addressData.region.region_code = '';
53+
addressData.region.region = '';
4754
}
4855
delete addressData.region_id;
4956

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ define(
177177
address;
178178

179179
if (this.validateAddressData(addressFlat)) {
180-
addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat);
180+
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
181181
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
182182
selectShippingAddress(address);
183183
}

app/code/Magento/Ups/Model/Carrier.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,13 @@ protected function _getXmlQuotes()
739739
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
740740
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (bool)$this->getConfigFlag('mode_xml'));
741741
$xmlResponse = curl_exec($ch);
742-
743-
$debugData['result'] = $xmlResponse;
744-
$this->_setCachedQuotes($xmlRequest, $xmlResponse);
742+
if ($xmlResponse !== false) {
743+
$debugData['result'] = $xmlResponse;
744+
$this->_setCachedQuotes($xmlRequest, $xmlResponse);
745+
} else {
746+
$debugData['result'] = ['error' => curl_error($ch)];
747+
}
748+
curl_close($ch);
745749
} catch (\Exception $e) {
746750
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
747751
$xmlResponse = '';
@@ -1002,7 +1006,11 @@ protected function _getXmlTracking($trackings)
10021006
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
10031007
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
10041008
$xmlResponse = curl_exec($ch);
1005-
$debugData['result'] = $xmlResponse;
1009+
if ($xmlResponse !== false) {
1010+
$debugData['result'] = $xmlResponse;
1011+
} else {
1012+
$debugData['result'] = ['error' => curl_error($ch)];
1013+
}
10061014
curl_close($ch);
10071015
} catch (\Exception $e) {
10081016
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/Method.php

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ class Method extends Block
4343
protected $blockWaitElement = '._block-content-loading';
4444

4545
/**
46-
* Wait until shipping rates will appear.
46+
* Shipping method row locator.
4747
*
48-
* @return void
48+
* @var string
4949
*/
50-
private function waitForShippingRates()
51-
{
52-
// Code under test uses JavaScript setTimeout at this point as well.
53-
sleep(3);
54-
$this->waitForElementNotVisible($this->blockWaitElement);
55-
}
50+
private $shippingMethodRow = '#checkout-step-shipping_method tbody tr.row';
51+
52+
/**
53+
* Shipping error row locator.
54+
*
55+
* @var string
56+
*/
57+
private $shippingError = '#checkout-step-shipping_method tbody tr.row-error';
5658

5759
/**
5860
* Select shipping method.
@@ -85,4 +87,62 @@ function () use ($browser, $selector) {
8587
}
8688
);
8789
}
90+
91+
/**
92+
* Wait until shipping rates will appear.
93+
*
94+
* @return void
95+
*/
96+
public function waitForShippingRates()
97+
{
98+
// Code under test uses JavaScript setTimeout at this point as well.
99+
sleep(3);
100+
$this->waitForElementNotVisible($this->blockWaitElement);
101+
}
102+
103+
/**
104+
* Return available shipping methods with prices.
105+
*
106+
* @return array
107+
*/
108+
public function getAvailableMethods()
109+
{
110+
$this->waitForShippingRates();
111+
$methods = $this->_rootElement->getElements($this->shippingMethodRow);
112+
$result = [];
113+
foreach ($methods as $method) {
114+
$methodName = trim($method->find('td.col-method:not(:first-child)')->getText());
115+
$methodPrice = trim($method->find('td.col-price')->getText());
116+
$methodPrice = $this->escapeCurrency($methodPrice);
117+
118+
$result[$methodName] = $methodPrice;
119+
}
120+
121+
return $result;
122+
}
123+
124+
/**
125+
* Is shipping rates estimation error present.
126+
*
127+
* @return bool
128+
*/
129+
public function isErrorPresent()
130+
{
131+
$this->waitForShippingRates();
132+
133+
return $this->_rootElement->find($this->shippingError)->isVisible();
134+
}
135+
136+
/**
137+
* Escape currency in price.
138+
*
139+
* @param string $price
140+
* @return string|null
141+
*/
142+
private function escapeCurrency($price)
143+
{
144+
preg_match("/^\\D*\\s*([\\d,\\.]+)\\s*\\D*$/", $price, $matches);
145+
146+
return (isset($matches[1])) ? $matches[1] : null;
147+
}
88148
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\Constraint;
8+
9+
use Magento\Checkout\Test\Page\CheckoutOnepage;
10+
use Magento\Mtf\Client\BrowserInterface;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
13+
/**
14+
* Asserts shipping methods estimation on checkout page.
15+
*/
16+
abstract class AssertShippingMethodsEstimate extends AbstractConstraint
17+
{
18+
/**
19+
* Asserts shipping methods estimation on checkout page.
20+
*
21+
* @param CheckoutOnepage $checkoutOnepage
22+
* @param BrowserInterface $browser
23+
* @return void
24+
*/
25+
protected function assert(
26+
CheckoutOnepage $checkoutOnepage,
27+
BrowserInterface $browser
28+
) {
29+
if ($this->shouldOpenCheckout($checkoutOnepage, $browser)) {
30+
$checkoutOnepage->open();
31+
}
32+
33+
\PHPUnit_Framework_Assert::assertFalse(
34+
$checkoutOnepage->getShippingMethodBlock()->isErrorPresent(),
35+
'Shipping estimation error is present.'
36+
);
37+
38+
$methods = $checkoutOnepage->getShippingMethodBlock()->getAvailableMethods();
39+
\PHPUnit_Framework_Assert::assertNotEmpty(
40+
$methods,
41+
'No shipping methods are present.'
42+
);
43+
}
44+
45+
/**
46+
* Should open checkout page or not.
47+
*
48+
* @param CheckoutOnepage $checkoutOnepage
49+
* @param BrowserInterface $browser
50+
* @return bool
51+
*/
52+
private function shouldOpenCheckout(CheckoutOnepage $checkoutOnepage, BrowserInterface $browser)
53+
{
54+
$result = true;
55+
56+
foreach (['checkout/', $checkoutOnepage::MCA] as $path) {
57+
$length = strlen($path);
58+
if (substr($browser->getUrl(), -$length) === $path) {
59+
$result = false;
60+
break;
61+
}
62+
}
63+
64+
return $result;
65+
}
66+
67+
/**
68+
* Returns a string representation of the object.
69+
*
70+
* @return string
71+
*/
72+
public function toString()
73+
{
74+
return "Shipping methods estimation on checkout page.";
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\Constraint;
8+
9+
use Magento\Checkout\Test\Page\CheckoutOnepage;
10+
use Magento\Mtf\Client\BrowserInterface;
11+
12+
/**
13+
* Asserts that shipping methods are present on checkout page.
14+
*/
15+
class AssertShippingMethodsSuccessEstimate extends AssertShippingMethodsEstimate
16+
{
17+
/**
18+
* Asserts that shipping methods are present on checkout page.
19+
*
20+
* @param CheckoutOnepage $checkoutOnepage
21+
* @param BrowserInterface $browser
22+
* @return void
23+
*/
24+
public function processAssert(CheckoutOnepage $checkoutOnepage, BrowserInterface $browser)
25+
{
26+
$this->assert($checkoutOnepage, $browser);
27+
}
28+
29+
/**
30+
* Returns a string representation of the object.
31+
*
32+
* @return string
33+
*/
34+
public function toString()
35+
{
36+
return "Shipping methods are present on checkout page.";
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\Constraint;
8+
9+
use Magento\Checkout\Test\Page\CheckoutOnepage;
10+
use Magento\Checkout\Test\TestStep\FillShippingAddressStep;
11+
use Magento\Mtf\Client\BrowserInterface;
12+
use Magento\Mtf\Fixture\FixtureFactory;
13+
use Magento\Mtf\TestStep\TestStepFactory;
14+
15+
/**
16+
* Asserts that shipping methods are present on checkout page after address modification.
17+
*/
18+
class AssertShippingMethodsSuccessEstimateAfterAddressEdit extends AssertShippingMethodsEstimate
19+
{
20+
/**
21+
* Asserts that shipping methods are present on checkout page after address modification.
22+
*
23+
* @param CheckoutOnepage $checkoutOnepage
24+
* @param TestStepFactory $testStepFactory
25+
* @param FixtureFactory $fixtureFactory
26+
* @param BrowserInterface $browser
27+
* @param array $editAddressData
28+
* @return void
29+
*/
30+
public function processAssert(
31+
CheckoutOnepage $checkoutOnepage,
32+
TestStepFactory $testStepFactory,
33+
FixtureFactory $fixtureFactory,
34+
BrowserInterface $browser,
35+
array $editAddressData = []
36+
) {
37+
if (!empty ($editAddressData)) {
38+
$address = $fixtureFactory->createByCode('address', ['data' => $editAddressData]);
39+
$testStepFactory->create(
40+
FillShippingAddressStep::class,
41+
[
42+
'checkoutOnepage' => $checkoutOnepage,
43+
'shippingAddress' => $address,
44+
]
45+
)->run();
46+
47+
$this->assert($checkoutOnepage, $browser);
48+
}
49+
}
50+
51+
/**
52+
* Returns a string representation of the object.
53+
*
54+
* @return string
55+
*/
56+
public function toString()
57+
{
58+
return "Shipping methods are present on checkout page after address modification.";
59+
}
60+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\TestCase;
8+
9+
use Magento\Mtf\TestCase\Scenario;
10+
11+
/**
12+
* Preconditions:
13+
* 1. Configure shipping method according dataset.
14+
* 2. Create product(-s)
15+
*
16+
* Steps:
17+
* 1. Go to Frontend.
18+
* 2. Add product(-s) to the cart.
19+
* 3. Proceed to Checkout.
20+
* 4. Fill shipping address according to dataset.
21+
* 5. Wait until shipping methods will appear.
22+
* 6. Perform assertions.
23+
*
24+
* @group One_Page_Checkout_(CS)
25+
* @ZephyrId MAGETWO-71002
26+
*/
27+
class OnePageEstimateShippingMethodsTest extends Scenario
28+
{
29+
/**
30+
* Runs test.
31+
*
32+
* @return void
33+
*/
34+
public function test()
35+
{
36+
$this->executeScenario();
37+
}
38+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function run()
5151
{
5252
if ($this->shippingAddress) {
5353
$this->checkoutOnepage->getShippingBlock()->fill($this->shippingAddress);
54+
$this->checkoutOnepage->getShippingMethodBlock()->waitForShippingRates();
5455
}
5556
}
5657
}

0 commit comments

Comments
 (0)