8
8
9
9
use Magento \Checkout \Test \Page \CheckoutOnepage ;
10
10
use Magento \Customer \Test \Fixture \Address ;
11
+ use Magento \Mtf \Fixture \FixtureFactory ;
11
12
use Magento \Mtf \TestStep \TestStepInterface ;
13
+ use Magento \Customer \Test \Fixture \Customer ;
14
+ use Magento \Mtf \ObjectManager ;
12
15
13
16
/**
14
17
* Fill shipping address step.
@@ -20,37 +23,109 @@ class FillShippingAddressStep implements TestStepInterface
20
23
*
21
24
* @var CheckoutOnepage
22
25
*/
23
- protected $ checkoutOnepage ;
26
+ private $ checkoutOnepage ;
24
27
25
28
/**
26
29
* Address fixture.
27
30
*
28
31
* @var Address
29
32
*/
30
- protected $ shippingAddress ;
33
+ private $ shippingAddress ;
34
+
35
+ /**
36
+ * Customer fixture.
37
+ *
38
+ * @var Customer
39
+ */
40
+ private $ customer ;
41
+
42
+ /**
43
+ * Customer shipping address data for select.
44
+ *
45
+ * @var array
46
+ */
47
+ private $ shippingAddressCustomer ;
48
+
49
+ /**
50
+ * Object manager instance.
51
+ *
52
+ * @var ObjectManager
53
+ */
54
+ private $ objectManager ;
55
+
56
+ /**
57
+ * Fixture factory.
58
+ *
59
+ * @var FixtureFactory
60
+ */
61
+ private $ fixtureFactory ;
31
62
32
63
/**
33
64
* @constructor
34
65
* @param CheckoutOnepage $checkoutOnepage
35
- * @param Address $shippingAddress
66
+ * @param Customer $customer
67
+ * @param ObjectManager $objectManager
68
+ * @param FixtureFactory $fixtureFactory
69
+ * @param Address|null $shippingAddress
70
+ * @param array|null $shippingAddressCustomer
36
71
*/
37
72
public function __construct (
38
73
CheckoutOnepage $ checkoutOnepage ,
39
- Address $ shippingAddress = null
74
+ Customer $ customer ,
75
+ ObjectManager $ objectManager ,
76
+ FixtureFactory $ fixtureFactory ,
77
+ Address $ shippingAddress = null ,
78
+ $ shippingAddressCustomer = null
40
79
) {
41
80
$ this ->checkoutOnepage = $ checkoutOnepage ;
81
+ $ this ->customer = $ customer ;
82
+ $ this ->objectManager = $ objectManager ;
83
+ $ this ->fixtureFactory = $ fixtureFactory ;
42
84
$ this ->shippingAddress = $ shippingAddress ;
85
+ $ this ->shippingAddressCustomer = $ shippingAddressCustomer ;
43
86
}
44
87
45
88
/**
46
89
* Fill shipping address.
47
90
*
48
- * @return void
91
+ * @return array
49
92
*/
50
93
public function run ()
51
94
{
95
+ $ shippingAddress = null ;
52
96
if ($ this ->shippingAddress ) {
53
- $ this ->checkoutOnepage ->getShippingBlock ()->fill ($ this ->shippingAddress );
97
+ $ shippingBlock = $ this ->checkoutOnepage ->getShippingBlock ();
98
+ if ($ shippingBlock ->isPopupNewAddressButtonVisible ()) {
99
+ $ shippingBlock ->clickPopupNewAddressButton ();
100
+ $ this ->checkoutOnepage ->getShippingAddressPopupBlock ()
101
+ ->fill ($ this ->shippingAddress )
102
+ ->clickSaveAddressButton ();
103
+ } else {
104
+ $ shippingBlock ->fill ($ this ->shippingAddress );
105
+ }
106
+ $ shippingAddress = $ this ->shippingAddress ;
107
+ }
108
+ if (isset ($ this ->shippingAddressCustomer ['new ' ])) {
109
+ $ shippingAddress = $ this ->fixtureFactory ->create (
110
+ 'address ' ,
111
+ ['dataset ' => $ this ->shippingAddressCustomer ['new ' ]]
112
+ );
113
+ $ this ->checkoutOnepage ->getShippingBlock ()->clickPopupNewAddressButton ();
114
+ $ this ->checkoutOnepage ->getShippingAddressPopupBlock ()->fill ($ shippingAddress )->clickSaveAddressButton ();
54
115
}
116
+ if (isset ($ this ->shippingAddressCustomer ['added ' ])) {
117
+ $ addressIndex = $ this ->shippingAddressCustomer ['added ' ];
118
+ $ shippingAddress = $ this ->customer ->getDataFieldConfig ('address ' )['source ' ]->getAddresses ()[$ addressIndex ];
119
+ $ address = $ this ->objectManager ->create (
120
+ \Magento \Customer \Test \Block \Address \Renderer::class,
121
+ ['address ' => $ shippingAddress , 'type ' => 'html_without_company ' ]
122
+ )->render ();
123
+ $ shippingBlock = $ this ->checkoutOnepage ->getShippingBlock ();
124
+ $ shippingBlock ->selectAddress ($ address );
125
+ }
126
+
127
+ return [
128
+ 'shippingAddress ' => $ shippingAddress ,
129
+ ];
55
130
}
56
131
}
0 commit comments