8
8
9
9
use Magento \Tax \Test \Fixture \TaxRule ;
10
10
use Magento \Checkout \Test \Fixture \Cart ;
11
- use Magento \Customer \Test \Fixture \Customer ;
12
11
use Magento \Config \Test \Fixture \ConfigData ;
13
12
use Magento \Checkout \Test \Page \CheckoutCart ;
14
13
use Magento \Sales \Test \Fixture \OrderInjectable ;
15
- use Magento \Catalog \Test \Fixture \CatalogProductSimple ;
16
14
use Magento \Customer \Test \TestCase \AbstractApplyVatIdTest ;
17
15
18
16
/**
@@ -80,23 +78,28 @@ public function test(
80
78
) {
81
79
// Preconditions
82
80
$ this ->configData = $ configData ;
81
+ $ this ->customer = $ order ->getDataFieldConfig ('customer_id ' )['source ' ]->getCustomer ();
83
82
$ this ->objectManager ->create (
84
83
\Magento \Config \Test \TestStep \SetupConfigurationStep::class,
85
84
['configData ' => $ this ->configData ]
86
85
)->run ();
87
- $ taxRule -> persist ();
86
+
88
87
// Prepare data
89
- $ this ->customer = $ order ->getDataFieldConfig ('customer_id ' )['source ' ]->getCustomer ();
90
- $ address = $ this ->customer ->getDataFieldConfig ('address ' )['source ' ]->getAddresses ()[0 ];
91
- $ this ->prepareVatConfig ($ vatConfig , $ customerGroup );
92
- $ poducts = $ order ->getEntityId ()['products ' ];
88
+ $ taxRule ->persist ();
89
+ $ this ->prepareVatConfiguration ($ vatConfig );
90
+ $ this ->prepareCustomer ($ customerGroup );
91
+
92
+ $ products = $ order ->getEntityId ()['products ' ];
93
93
$ cart = $ this ->fixtureFactory ->createByCode (
94
94
'cart ' ,
95
- ['data ' => array_merge ($ cart ->getData (), ['items ' => ['products ' => $ poducts ]])]
95
+ ['data ' => array_merge ($ cart ->getData (), ['items ' => ['products ' => $ products ]])]
96
96
);
97
+ $ address = $ this ->customer ->getDataFieldConfig ('address ' )['source ' ]->getAddresses ()[0 ];
97
98
98
- // Steps
99
99
$ order ->persist ();
100
+ $ this ->updateCustomer ($ customerGroup );
101
+
102
+ // Steps
100
103
$ this ->objectManager ->create (
101
104
\Magento \Customer \Test \TestStep \LoginCustomerOnFrontendStep::class,
102
105
['customer ' => $ this ->customer ]
@@ -115,8 +118,72 @@ public function test(
115
118
'address ' => $ address ,
116
119
'orderId ' => $ order ->getId (),
117
120
'cart ' => $ cart ,
118
- 'products ' => $ poducts
121
+ 'products ' => $ products
122
+ ];
123
+ }
124
+
125
+ /**
126
+ * Persist vat configuration
127
+ *
128
+ * @param string $vatConfig
129
+ * @return void
130
+ */
131
+ private function prepareVatConfiguration ($ vatConfig )
132
+ {
133
+ $ groupConfig = [
134
+ 'customer/create_account/viv_domestic_group ' => [
135
+ 'value ' => $ this ->vatGroups ['valid_domestic_group ' ]->getCustomerGroupId ()
136
+ ],
137
+ 'customer/create_account/viv_intra_union_group ' => [
138
+ 'value ' => $ this ->vatGroups ['valid_intra_union_group ' ]->getCustomerGroupId ()
139
+ ],
140
+ 'customer/create_account/viv_invalid_group ' => [
141
+ 'value ' => $ this ->vatGroups ['invalid_group ' ]->getCustomerGroupId ()
142
+ ],
143
+ 'customer/create_account/viv_error_group ' => [
144
+ 'value ' => $ this ->vatGroups ['error_group ' ]->getCustomerGroupId ()
145
+ ]
119
146
];
147
+ $ vatConfig = $ this ->fixtureFactory ->createByCode (
148
+ 'configData ' ,
149
+ ['data ' => array_replace_recursive ($ vatConfig ->getSection (), $ groupConfig )]
150
+ );
151
+ $ vatConfig ->persist ();
152
+ }
153
+
154
+ /**
155
+ * Persist customer with valid customer group
156
+ *
157
+ * @param string $customerGroup
158
+ * @return void
159
+ */
160
+ private function prepareCustomer ($ customerGroup )
161
+ {
162
+ $ customerData = array_merge (
163
+ $ this ->customer ->getData (),
164
+ ['group_id ' => ['value ' => $ this ->vatGroups [$ customerGroup ]->getCustomerGroupId ()]],
165
+ ['address ' => ['addresses ' => $ this ->customer ->getDataFieldConfig ('address ' )['source ' ]->getAddresses ()]],
166
+ ['email ' => 'JohnDoe%isolation%@example.com ' ]
167
+ );
168
+
169
+ unset($ customerData ['id ' ]);
170
+ $ this ->customer = $ this ->fixtureFactory ->createByCode ('customer ' , ['data ' => $ customerData ]);
171
+ $ this ->customer ->persist ();
172
+ }
173
+
174
+ /**
175
+ * Update customer with customer group code for assert
176
+ *
177
+ * @param string $customerGroup
178
+ * @return void
179
+ */
180
+ private function updateCustomer ($ customerGroup ){
181
+ $ customerData = array_merge (
182
+ $ this ->customer ->getData (),
183
+ ['group_id ' => ['value ' => $ this ->vatGroups [$ customerGroup ]->getCustomerGroupCode ()]]
184
+ );
185
+
186
+ $ this ->customer = $ this ->fixtureFactory ->createByCode ('customer ' , ['data ' => $ customerData ]);
120
187
}
121
188
122
189
/**
0 commit comments