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 27, 2017
1 parent 3758d4c commit 0f27eba
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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\Mtf\Client\BrowserInterface;
use Magento\Mtf\Constraint\AbstractConstraint;

/**
* Asserts shipping methods estimation on checkout page.
*/
abstract class AssertShippingMethodsEstimate extends AbstractConstraint
{
/**
* Asserts shipping methods estimation on checkout page.
*
* @param CheckoutOnepage $checkoutOnepage
* @param BrowserInterface $browser
* @return void
*/
protected function assert(
CheckoutOnepage $checkoutOnepage,
BrowserInterface $browser
) {
if ($this->shouldOpenCheckout($checkoutOnepage, $browser)) {
$checkoutOnepage->open();
}

\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 estimation on checkout page.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
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.
*/
class AssertShippingMethodsSuccessEstimate extends AbstractConstraint
class AssertShippingMethodsSuccessEstimate extends AssertShippingMethodsEstimate
{
/**
* Asserts that shipping methods are present on checkout page.
Expand All @@ -25,46 +21,9 @@ class AssertShippingMethodsSuccessEstimate extends AbstractConstraint
* @param BrowserInterface $browser
* @return void
*/
public function processAssert(
CheckoutOnepage $checkoutOnepage,
BrowserInterface $browser
) {
if ($this->shouldOpenCheckout($checkoutOnepage, $browser)) {
$checkoutOnepage->open();
}

\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)
public function processAssert(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;
$this->assert($checkoutOnepage, $browser);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
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
class AssertShippingMethodsSuccessEstimateAfterAddressEdit extends AssertShippingMethodsEstimate
{
/**
* Asserts that shipping methods are present on checkout page after address modification.
Expand All @@ -35,53 +34,18 @@ public function processAssert(
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
'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;
}
$this->assert($checkoutOnepage, $browser);
}

return $result;
}

/**
Expand Down

0 comments on commit 0f27eba

Please sign in to comment.