Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateCustomerBackendEntityTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\FixtureFactory;
10 use Magento\Mtf\Fixture\FixtureInterface;
11 use Magento\Mtf\TestCase\Injectable;
12 use Magento\Customer\Test\Fixture\Address;
14 use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
15 use Magento\Customer\Test\Page\Adminhtml\CustomerIndexNew;
17 use Magento\User\Test\Page\Adminhtml\UserEdit;
18 use Magento\User\Test\Page\Adminhtml\UserIndex;
19 
31 class CreateCustomerBackendEntityTest extends Injectable
32 {
33  /* tags */
34  const MVP = 'yes';
35  const TEST_TYPE = 'extended_acceptance_test';
36  /* end tags */
37 
43  protected $customer;
44 
48  private $address;
49 
51  private $allowedCountriesData = [];
52 
58  protected $pageCustomerIndex;
59 
66 
68  private $fixtureFactory;
69 
73  private $userEdit;
74 
78  private $userIndex;
79 
85  private $steps;
86 
97  public function __inject(
98  CustomerIndex $pageCustomerIndex,
99  CustomerIndexNew $pageCustomerIndexNew,
100  \Magento\Mtf\Fixture\FixtureFactory $fixtureFactory,
101  UserEdit $userEdit,
102  UserIndex $userIndex
103  ) {
104  $this->pageCustomerIndex = $pageCustomerIndex;
105  $this->pageCustomerIndexNew = $pageCustomerIndexNew;
106  $this->fixtureFactory = $fixtureFactory;
107  $this->userEdit = $userEdit;
108  $this->userIndex = $userIndex;
109  }
110 
121  public function test(
122  Customer $customer,
123  $customerAction,
124  Address $address = null,
125  array $steps = [],
126  array $beforeActionCallback = []
127  ) {
128  $this->steps = $steps;
130  foreach ($steps as $methodName => $stepData) {
131  if (method_exists($this, $methodName)) {
132  call_user_func_array([$this, $methodName], $stepData);
133  }
134  }
135 
136  $this->pageCustomerIndex->open();
137  $this->pageCustomerIndex->getPageActionsBlock()->addNew();
138  $this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($customer, $address);
139  $this->address = $address;
140  $this->customer = $customer;
141 
142  foreach ($beforeActionCallback as $methodName) {
143  if (method_exists($this, $methodName)) {
144  call_user_func([$this, $methodName]);
145  }
146  }
147 
148  $this->pageCustomerIndexNew->getPageActionsBlock()->$customerAction();
149  }
150 
155  protected function assertAllowedCountries()
156  {
158  $assert = $this->objectManager->get(
159  \Magento\Customer\Test\Constraint\AssertChangingWebsiteChangeCountries::class
160  );
161 
162  foreach ($this->allowedCountriesData as $dataPerWebsite) {
163  $customerWithWebsite = $this->fixtureFactory->createByCode(
164  'customer',
165  [
166  'data' => [
167  'website_id' => $dataPerWebsite['website']->getName()
168  ]
169  ]
170  );
171  $assert->processAssert(
172  $this->pageCustomerIndexNew,
173  $customerWithWebsite,
174  $dataPerWebsite['countries']
175  );
176  }
177 
178  $this->pageCustomerIndexNew->getCustomerForm()->openTab('account_information');
179  $this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($this->customer);
180  $this->pageCustomerIndexNew->getCustomerForm()->openTab('addresses');
181  $this->pageCustomerIndexNew->getCustomerForm()->getTab('addresses')->updateAddresses($this->address);
182  }
183 
187  private function createWebsiteFixture()
188  {
190  $websiteFixture = $this->fixtureFactory->createByCode('website', ['dataset' => 'custom_website']);
191  $websiteFixture->persist();
192  $storeGroupFixture = $this->fixtureFactory->createByCode(
193  'storeGroup',
194  [
195  'data' => [
196  'website_id' => [
197  'fixture' => $websiteFixture
198  ],
199  'root_category_id' => [
200  'dataset' => 'default_category'
201  ],
202  'name' => 'Store_Group_%isolation%',
203  ]
204  ]
205  );
206  $storeGroupFixture->persist();
208  $storeFixture = $this->fixtureFactory->createByCode(
209  'store',
210  [
211  'data' => [
212  'website_id' => $websiteFixture->getWebsiteId(),
213  'group_id' => [
214  'fixture' => $storeGroupFixture
215  ],
216  'is_active' => true,
217  'name' => 'Store_%isolation%',
218  'code' => 'store_%isolation%'
219  ]
220  ]
221  );
222  $storeFixture->persist();
223 
224  return $websiteFixture;
225  }
226 
230  protected function configureAllowedCountries(array $countryList = [])
231  {
232  foreach ($countryList as $countries) {
233  $websiteFixture = $this->createWebsiteFixture();
235  $configFixture = $this->fixtureFactory->createByCode(
236  'configData',
237  [
238  'data' => [
239  'general/country/allow' => [
240  'value' => $countries
241  ],
242  'scope' => [
243  'fixture' => $websiteFixture,
244  'scope_type' => 'website',
245  'website_id' => $websiteFixture->getWebsiteId(),
246  'set_level' => 'website',
247  ]
248  ]
249  ]
250  );
251 
252  $configFixture->persist();
253  $this->allowedCountriesData[] = [
254  'website' => $websiteFixture,
255  'countries' => explode(",", $countries)
256  ];
257  }
258  }
259 
265  protected function changeAdminLocale(array $userData)
266  {
268  $adminUser = $this->fixtureFactory->createByCode('user', ['data' => $userData]);
269  $this->userIndex->open();
270  $this->userIndex->getUserGrid()->searchAndOpen(['username' => $adminUser->getUsername()]);
271  $this->userEdit->getUserForm()->fill($adminUser);
272  $this->userEdit->getPageActions()->save();
273  }
274 
278  protected function changeAdminLocaleRollback()
279  {
281  $defaultAdminUser = $this->fixtureFactory->createByCode('user');
282  $adminUserData = $defaultAdminUser->getData();
283  unset($adminUserData['user_id']);
284  $defaultAdminUser = $this->fixtureFactory->createByCode('user', ['data' => $adminUserData]);
285  $this->userIndex->open();
286  $this->userIndex->getUserGrid()->searchAndOpen(['username' => $defaultAdminUser->getUsername()]);
287  $this->userEdit->getUserForm()->fill($defaultAdminUser);
288  $this->userEdit->getPageActions()->save();
289  }
290 
294  protected function tearDown()
295  {
296  foreach ($this->steps as $key => $stepData) {
297  if (method_exists($this, $key . 'Rollback')) {
298  call_user_func_array([$this, $key . 'Rollback'], $stepData);
299  }
300  }
301  }
302 }
test(Customer $customer, $customerAction, Address $address=null, array $steps=[], array $beforeActionCallback=[])
__inject(CustomerIndex $pageCustomerIndex, CustomerIndexNew $pageCustomerIndexNew, \Magento\Mtf\Fixture\FixtureFactory $fixtureFactory, UserEdit $userEdit, UserIndex $userIndex)