Skip to content

Commit a4de0fa

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-46206: Fix random fails of Magento\Checkout\Test\TestCase\OnePageCheckoutTest functional test
- fixed fields order for shipping address form
1 parent 562466f commit a4de0fa

File tree

1 file changed

+26
-0
lines changed
  • dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Shipping extends Form
4545

4646
/**
4747
* Fields that are used in estimation shipping form.
48+
* Indexes of this array should be numeric, they are used in compare() method.
4849
*
4950
* @var array
5051
*/
@@ -91,6 +92,29 @@ public function selectShippingMethod(array $shipping)
9192
}
9293
}
9394

95+
/**
96+
* Compare elements according to $this->estimationFields order
97+
*
98+
* @param $a
99+
* @param $b
100+
* @return int
101+
*/
102+
public function compare($a, $b)
103+
{
104+
$a = array_search($a, $this->estimationFields);
105+
$b = array_search($b, $this->estimationFields);
106+
switch (true) {
107+
case false !== $a && false !== $b:
108+
return $a - $b;
109+
case false !== $a:
110+
return -1;
111+
case false !== $b:
112+
return 1;
113+
default:
114+
return 0;
115+
}
116+
}
117+
94118
/**
95119
* Fill shipping and tax form.
96120
*
@@ -102,6 +126,8 @@ public function fillEstimateShippingAndTax(Address $address)
102126
$this->openEstimateShippingAndTax();
103127
$data = $address->getData();
104128
$mapping = $this->dataMapping(array_intersect_key($data, array_flip($this->estimationFields)));
129+
// sort array according to $this->estimationFields element order
130+
uksort($mapping, [$this, 'compare']);
105131

106132
// Test environment may become unstable when form fields are filled in a default manner.
107133
// Imitating behavior closer to the real user.

0 commit comments

Comments
 (0)