Skip to content

Commit

Permalink
MAGETWO-60958: [Backport] Incorrect province code sent on Checkout to…
Browse files Browse the repository at this point in the history
… UPS #6564 - for 2.1

- MAGETWO-70727: [GitHub] Shipping method randomly dissapear when page refreshed for 2.1 #7497
  • Loading branch information
ameysar committed Jul 26, 2017
1 parent 0987a02 commit e97a673
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 8 deletions.
Expand Up @@ -44,6 +44,13 @@ define(
addressData.region.region_code = region['code'];
addressData.region.region = region['name'];
}
} else if (
!addressData.region_id
&& countryData()[addressData.country_id]
&& countryData()[addressData.country_id]['regions']
) {
addressData.region.region_code = '';
addressData.region.region = '';
}
delete addressData.region_id;

Expand Down
Expand Up @@ -177,7 +177,7 @@ define(
address;

if (this.validateAddressData(addressFlat)) {
addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat);
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
selectShippingAddress(address);
}
Expand Down
16 changes: 12 additions & 4 deletions app/code/Magento/Ups/Model/Carrier.php
Expand Up @@ -739,9 +739,13 @@ protected function _getXmlQuotes()
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (bool)$this->getConfigFlag('mode_xml'));
$xmlResponse = curl_exec($ch);

$debugData['result'] = $xmlResponse;
$this->_setCachedQuotes($xmlRequest, $xmlResponse);
if ($xmlResponse !== false) {
$debugData['result'] = $xmlResponse;
$this->_setCachedQuotes($xmlRequest, $xmlResponse);
} else {
$debugData['result'] = ['error' => curl_error($ch)];
}
curl_close($ch);
} catch (\Exception $e) {
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
$xmlResponse = '';
Expand Down Expand Up @@ -1002,7 +1006,11 @@ protected function _getXmlTracking($trackings)
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$xmlResponse = curl_exec($ch);
$debugData['result'] = $xmlResponse;
if ($xmlResponse !== false) {
$debugData['result'] = $xmlResponse;
} else {
$debugData['result'] = ['error' => curl_error($ch)];
}
curl_close($ch);
} catch (\Exception $e) {
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
Expand Down
Expand Up @@ -42,6 +42,20 @@ class Method extends Block
*/
protected $blockWaitElement = '._block-content-loading';

/**
* Shipping method row locator.
*
* @var string
*/
private $shippingMethodRow = '#checkout-step-shipping_method tbody tr.row';

/**
* Shipping error row locator.
*
* @var string
*/
private $shippingError = '#checkout-step-shipping_method tbody tr.row-error';

/**
* Select shipping method.
*
Expand All @@ -50,10 +64,9 @@ class Method extends Block
*/
public function selectShippingMethod(array $method)
{
// Code under test uses JavaScript setTimeout at this point as well.
sleep(3);
$this->waitForShippingRates();

$selector = sprintf($this->shippingMethod, $method['shipping_method'], $method['shipping_service']);
$this->waitForElementNotVisible($this->blockWaitElement);
$this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->click();
}

Expand All @@ -74,4 +87,62 @@ function () use ($browser, $selector) {
}
);
}

/**
* Wait until shipping rates will appear.
*
* @return void
*/
public function waitForShippingRates()
{
// Code under test uses JavaScript setTimeout at this point as well.
sleep(3);
$this->waitForElementNotVisible($this->blockWaitElement);
}

/**
* Return available shipping methods with prices.
*
* @return array
*/
public function getAvailableMethods()
{
$this->waitForShippingRates();
$methods = $this->_rootElement->getElements($this->shippingMethodRow);
$result = [];
foreach ($methods as $method) {
$methodName = trim($method->find('td.col-method:not(:first-child)')->getText());
$methodPrice = trim($method->find('td.col-price')->getText());
$methodPrice = $this->escapeCurrency($methodPrice);

$result[$methodName] = $methodPrice;
}

return $result;
}

/**
* Is shipping rates estimation error present.
*
* @return bool
*/
public function isErrorPresent()
{
$this->waitForShippingRates();

return $this->_rootElement->find($this->shippingError)->isVisible();
}

/**
* Escape currency in price.
*
* @param string $price
* @return string|null
*/
private function escapeCurrency($price)
{
preg_match("/^\\D*\\s*([\\d,\\.]+)\\s*\\D*$/", $price, $matches);

return (isset($matches[1])) ? $matches[1] : null;
}
}
@@ -0,0 +1,97 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Checkout\Test\Constraint;

use Magento\Checkout\Test\Page\CheckoutOnepage;
use Magento\Checkout\Test\TestStep\FillShippingAddressStep;
use Magento\Mtf\Client\BrowserInterface;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Mtf\Fixture\FixtureFactory;
use Magento\Mtf\TestStep\TestStepFactory;

/**
* Asserts that shipping methods are present on checkout page after address modification.
*/
class AssertShippingMethodsSuccessEstimateAfterAddressEdit extends AbstractConstraint
{
/**
* Asserts that shipping methods are present on checkout page after address modification.
*
* @param CheckoutOnepage $checkoutOnepage
* @param TestStepFactory $testStepFactory
* @param FixtureFactory $fixtureFactory
* @param BrowserInterface $browser
* @param array $editAddressData
* @return void
*/
public function processAssert(
CheckoutOnepage $checkoutOnepage,
TestStepFactory $testStepFactory,
FixtureFactory $fixtureFactory,
BrowserInterface $browser,
array $editAddressData = []
) {
if ($this->shouldOpenCheckout($checkoutOnepage, $browser)) {
$checkoutOnepage->open();
}

if (!empty ($editAddressData)) {

$address = $fixtureFactory->createByCode('address', ['data' => $editAddressData]);
$testStepFactory->create(
FillShippingAddressStep::class,
[
'checkoutOnepage' => $checkoutOnepage,
'shippingAddress' => $address
]
)->run();

\PHPUnit_Framework_Assert::assertFalse(
$checkoutOnepage->getShippingMethodBlock()->isErrorPresent(),
'Shipping estimation error is present.'
);

$methods = $checkoutOnepage->getShippingMethodBlock()->getAvailableMethods();
\PHPUnit_Framework_Assert::assertNotEmpty(
$methods,
'No shipping methods are present.'
);
}
}

/**
* Should open checkout page or not.
*
* @param CheckoutOnepage $checkoutOnepage
* @param BrowserInterface $browser
* @return bool
*/
private function shouldOpenCheckout(CheckoutOnepage $checkoutOnepage, BrowserInterface $browser)
{
$result = true;

foreach (['checkout/', $checkoutOnepage::MCA] as $path) {
$length = strlen($path);
if (substr($browser->getUrl(), -$length) === $path) {
$result = false;
break;
}
}

return $result;
}

/**
* Returns a string representation of the object.
*
* @return string
*/
public function toString()
{
return "Shipping methods are present on checkout page after address modification.";
}
}
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Checkout\Test\TestCase;

use Magento\Mtf\TestCase\Scenario;

/**
* Preconditions:
* 1. Configure shipping method according dataset.
* 2. Create product(-s)
*
* Steps:
* 1. Go to Frontend.
* 2. Add product(-s) to the cart.
* 3. Proceed to Checkout.
* 4. Fill shipping address according to dataset.
* 5. Wait until shipping methods will appear.
* 6. Perform assertions.
*
* @group One_Page_Checkout_(CS)
* @ZephyrId MAGETWO-71002
*/
class OnePageEstimateShippingMethodsTest extends Scenario
{
/**
* Runs test.
*
* @return void
*/
public function test()
{
$this->executeScenario();
}
}
Expand Up @@ -51,6 +51,7 @@ public function run()
{
if ($this->shippingAddress) {
$this->checkoutOnepage->getShippingBlock()->fill($this->shippingAddress);
$this->checkoutOnepage->getShippingMethodBlock()->waitForShippingRates();
}
}
}
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Checkout\Test\TestStep;

use Magento\Checkout\Test\Page\CheckoutOnepage;
use Magento\Mtf\TestStep\TestStepInterface;

/**
* Resolve shipping methods from checkout page.
*/
class ResolveShippingMethodsStep implements TestStepInterface
{
/**
* Checkout view page.
*
* @var CheckoutOnepage
*/
private $checkoutOnepage;

/**
* Open checkout page or not.
*
* @var bool
*/
private $openPage = false;

/**
* @param CheckoutOnepage $checkoutOnepage
* @param bool $openPage
*/
public function __construct(CheckoutOnepage $checkoutOnepage, $openPage = false)
{
$this->checkoutOnepage = $checkoutOnepage;
$this->openPage = $openPage;
}

/**
* Run step flow.
*
* @return array
*/
public function run()
{
if ($this->openPage) {
$this->checkoutOnepage->open();
}

$methods = $this->checkoutOnepage->getShippingMethodBlock()->getAvailableMethods();
return ['shippingMethods' => $methods];
}
}
Expand Up @@ -28,4 +28,12 @@
<step name="addProductsToTheCart" module="Magento_Checkout" next="removeProductsFromTheCart" />
<step name="removeProductsFromTheCart" module="Magento_Checkout" />
</scenario>
<scenario name="OnePageEstimateShippingMethodsTest" firstStep="setupConfiguration">
<step name="setupConfiguration" module="Magento_Config" next="createProducts" />
<step name="createProducts" module="Magento_Catalog" next="addProductsToTheCart" />
<step name="addProductsToTheCart" module="Magento_Checkout" next="proceedToCheckout" />
<step name="proceedToCheckout" module="Magento_Checkout" next="fillShippingAddress" />
<step name="fillShippingAddress" module="Magento_Checkout" next="resolveShippingMethods" />
<step name="resolveShippingMethods" module="Magento_Checkout" />
</scenario>
</config>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
<testCase name="Magento\Checkout\Test\TestCase\OnePageEstimateShippingMethodsTest" summary="Estimate shipping methods at checkout" ticketId="MAGETWO-71002">
<variation name="OnePageEstimateShippingMethodsTestUpsVariation" ticketId="MAGETWO-71003">
<data name="products" xsi:type="string">catalogProductSimple::default</data>
<data name="shippingAddress/dataset" xsi:type="string">US_address_1_without_email</data>
<data name="editAddressData" xsi:type="array">
<item name="city" xsi:type="string">Birmingham</item>
<item name="region_id" xsi:type="string">Alabama</item>
<item name="postcode" xsi:type="string">35201</item>
</data>
<data name="configData" xsi:type="string">ups, shipping_origin_US_CA</data>
<constraint name="Magento\Checkout\Test\Constraint\AssertShippingMethodsSuccessEstimateAfterAddressEdit" />
</variation>
</testCase>
</config>

0 comments on commit e97a673

Please sign in to comment.