Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateCustomerFrontendEntityTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Cms\Test\Page\CmsIndex;
11 use Magento\Customer\Test\Fixture\Address;
13 use Magento\Customer\Test\Page\CustomerAccountEdit;
14 use Magento\Customer\Test\Page\CustomerAccountIndex;
15 use Magento\Customer\Test\Page\CustomerAddressEdit;
16 use Magento\Mtf\Fixture\FixtureFactory;
17 use Magento\Mtf\TestCase\Injectable;
18 
37 class UpdateCustomerFrontendEntityTest extends Injectable
38 {
39  /* tags */
40  const MVP = 'yes';
41  const TEST_TYPE = 'acceptance_test, extended_acceptance_test';
42  /* end tags */
43 
49  protected $fixtureFactory;
50 
56  protected $cmsIndex;
57 
64 
71 
78 
89  public function __inject(
90  CmsIndex $cmsIndex,
91  FixtureFactory $fixtureFactory,
92  CustomerAccountIndex $customerAccountIndex,
93  CustomerAccountEdit $customerAccountEdit,
94  CustomerAddressEdit $customerAddressEdit
95  ) {
96  $this->cmsIndex = $cmsIndex;
97  $this->fixtureFactory = $fixtureFactory;
98  $this->customerAccountIndex = $customerAccountIndex;
99  $this->customerAccountEdit = $customerAccountEdit;
100  $this->customerAddressEdit = $customerAddressEdit;
101  }
102 
110  private function prepareCustomer(
111  Customer $customer,
112  Customer $initialCustomer
113  ) {
114  if (!$customer->hasData()) {
115  return $initialCustomer;
116  }
117  $data = array_replace_recursive($initialCustomer->getData(), $customer->getData());
118  $data['group_id'] = [
119  'customerGroup' => $initialCustomer->getDataFieldConfig('group_id')['source']->getCustomerGroup()
120  ];
121 
122  return $this->fixtureFactory->createByCode('customer', ['data' => $data]);
123  }
124 
134  public function test(
135  Customer $initialCustomer,
136  Customer $customer,
138  AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage
139  ) {
140  // Preconditions
141  $initialCustomer->persist();
142 
143  // Steps
144  $this->objectManager->create(
145  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
146  ['customer' => $initialCustomer]
147  )->run();
148  $this->customerAccountIndex->getInfoBlock()->openEditContactInfo();
149  $this->customerAccountEdit->getAccountInfoForm()->fill($customer);
150  $this->customerAccountEdit->getAccountInfoForm()->submit();
151 
152  \PHPUnit\Framework\Assert::assertThat($this->getName(), $assertCustomerInfoSuccessSavedMessage);
153 
154  $this->cmsIndex->getCmsPageBlock()->waitPageInit();
155  $this->customerAccountIndex->getDashboardAddress()->editBillingAddress();
156  $this->customerAddressEdit->getEditForm()->fill($address);
157  $this->customerAddressEdit->getEditForm()->saveAddress();
158 
159  return [
160  'customer' => $this->prepareCustomer($customer, $initialCustomer),
161  'shippingAddress' => $address,
162  'billingAddress' => $address
163  ];
164  }
165 }
$customer
Definition: customers.php:11
test(Customer $initialCustomer, Customer $customer, Address $address, AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage)
$address
Definition: customer.php:38
__inject(CmsIndex $cmsIndex, FixtureFactory $fixtureFactory, CustomerAccountIndex $customerAccountIndex, CustomerAccountEdit $customerAccountEdit, CustomerAddressEdit $customerAddressEdit)