/** * Create customer * * @return array */ public function run() { if ($this->persistCustomer) { $this->customer->persist(); } return ['customer' => $this->customer]; }
/** * Injection data * * @param CustomerAccountCreate $customerAccountCreate * @param CustomerAccountLogout $customerAccountLogout * @param CmsIndex $cmsIndex * @param CustomerInjectable $customer * @return array */ public function __inject(CustomerAccountCreate $customerAccountCreate, CustomerAccountLogout $customerAccountLogout, CmsIndex $cmsIndex, CustomerInjectable $customer) { $this->customerAccountLogout = $customerAccountLogout; $this->customerAccountCreate = $customerAccountCreate; $this->cmsIndex = $cmsIndex; //Precondition $customer->persist(); return ['customer' => $customer]; }
/** * Runs Delete Customer Backend Entity test * * @param CustomerInjectable $customer * @return void */ public function testDeleteCustomerBackendEntity(CustomerInjectable $customer) { // Preconditions: $customer->persist(); // Steps: $filter = ['email' => $customer->getEmail()]; $this->customerIndexPage->open(); $this->customerIndexPage->getCustomerGridBlock()->searchAndOpen($filter); $this->customerIndexEditPage->getPageActionsBlock()->delete(); }
/** * Assert that deleted customers address is not displayed on backend during order creation * * @param OrderIndex $orderIndex * @param OrderCreateIndex $orderCreateIndex * @param AddressInjectable $deletedAddress * @param CustomerInjectable $customer * @return void */ public function processAssert(OrderIndex $orderIndex, OrderCreateIndex $orderCreateIndex, AddressInjectable $deletedAddress, CustomerInjectable $customer) { $filter = ['email' => $customer->getEmail()]; $orderIndex->open()->getGridPageActions()->addNew(); $orderCreateIndex->getCustomerBlock()->searchAndOpen($filter); $orderCreateIndex->getStoreBlock()->selectStoreView(); $actualAddresses = $orderCreateIndex->getCreateBlock()->getBillingAddressBlock()->getExistingAddresses(); $addressRenderer = $this->objectManager->create('Magento\\Customer\\Test\\Block\\Address\\Renderer', ['address' => $deletedAddress]); $addressToSearch = $addressRenderer->render(); \PHPUnit_Framework_Assert::assertFalse(in_array($addressToSearch, $actualAddresses), 'Deleted address is present on backend during order creation'); }
/** * Assert customer availability in Customer Grid * * @param CustomerInjectable $customer * @param CustomerIndex $pageCustomerIndex * @param CustomerInjectable $initialCustomer [optional] * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(CustomerInjectable $customer, CustomerIndex $pageCustomerIndex, CustomerInjectable $initialCustomer = null) { if ($initialCustomer) { $customer = $customer->hasData() ? array_merge($initialCustomer->getData(), $customer->getData()) : $initialCustomer->getData(); } else { $customer = $customer->getData(); } $name = (isset($customer['prefix']) ? $customer['prefix'] . ' ' : '') . $customer['firstname'] . (isset($customer['middlename']) ? ' ' . $customer['middlename'] : '') . ' ' . $customer['lastname'] . (isset($customer['suffix']) ? ' ' . $customer['suffix'] : ''); $filter = ['name' => $name, 'email' => $customer['email']]; $pageCustomerIndex->open(); \PHPUnit_Framework_Assert::assertTrue($pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter), 'Customer with ' . 'name \'' . $filter['name'] . '\', ' . 'email \'' . $filter['email'] . '\' ' . 'is absent in Customer grid.'); }
/** * Authorize customer on frontend * * @param CustomerInjectable $customer * @throws \Exception * @return void */ protected function authorize(CustomerInjectable $customer) { $url = $_ENV['app_frontend_url'] . 'customer/account/login/'; $this->transport->write(CurlInterface::POST, $url); $this->read(); $url = $_ENV['app_frontend_url'] . 'customer/account/loginPost/'; $data = ['login[username]' => $customer->getEmail(), 'login[password]' => $customer->getPassword(), 'form_key' => $this->formKey]; $this->transport->write(CurlInterface::POST, $url, '1.0', ['Set-Cookie:' . $this->cookies], $data); $response = $this->read(); if (strpos($response, 'customer/account/login')) { throw new \Exception($customer->getFirstname() . ', cannot be logged in by curl handler!'); } }
/** * @param CustomerInjectable $initialCustomer * @param CustomerInjectable $customer * @param AddressInjectable $address */ public function testUpdateCustomerBackendEntity(CustomerInjectable $initialCustomer, CustomerInjectable $customer, AddressInjectable $address) { // Prepare data $address = $address->hasData() ? $address : null; // Preconditions: $initialCustomer->persist(); // Steps $filter = ['email' => $initialCustomer->getEmail()]; $this->customerIndexPage->open(); $this->customerIndexPage->getCustomerGridBlock()->searchAndOpen($filter); $this->customerIndexEditPage->getCustomerForm()->updateCustomer($customer, $address); $this->customerIndexEditPage->getPageActionsBlock()->save(); }
/** * Asserts all Product Review variables in the reviews grid on customer page * * @param CustomerInjectable $customer * @param ReviewInjectable $reviewInitial * @param ReviewInjectable $review * @param CustomerIndexEdit $customerIndexEdit * @param CustomerIndex $customerIndex * @param AssertProductReviewInGrid $assertProductReviewInGrid * @return void */ public function processAssert(CustomerInjectable $customer, ReviewInjectable $reviewInitial, ReviewInjectable $review, CustomerIndexEdit $customerIndexEdit, CustomerIndex $customerIndex, AssertProductReviewInGrid $assertProductReviewInGrid) { /** var CatalogProductSimple $product */ $product = $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity(); $customerIndex->open(); $customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $customerIndexEdit->getCustomerForm()->openTab('product_reviews'); $filter = $assertProductReviewInGrid->prepareFilter($product, $this->prepareData($review, $reviewInitial)); /** @var ReviewsGrid $reviewsGrid */ $reviewsGrid = $customerIndexEdit->getCustomerForm()->getTabElement('product_reviews')->getReviewsGrid(); $reviewsGrid->search($filter); unset($filter['visible_in']); \PHPUnit_Framework_Assert::assertTrue($reviewsGrid->isRowVisible($filter, false), 'Review is absent in Review grid on customer page.'); }
/** * New Accounts Report * * @param CustomerInjectable $customer * @param array $customersReport * @return void */ public function test(CustomerInjectable $customer, array $customersReport) { // Preconditions $this->customerIndexPage->open(); $this->customerIndexPage->getCustomerGridBlock()->massaction([], 'Delete', true, 'Select All'); $customer->persist(); // Steps $this->customerAccounts->open(); $this->customerAccounts->getGridBlock()->searchAccounts($customersReport); }
/** * Assert that displayed customer data on edit page(backend) equals passed from fixture * * @param CustomerInjectable $customer * @param CustomerIndex $pageCustomerIndex * @param CustomerIndexEdit $pageCustomerIndexEdit * @param AddressInjectable $address [optional] * @param CustomerInjectable $initialCustomer [optional] * @return void */ public function processAssert(CustomerInjectable $customer, CustomerIndex $pageCustomerIndex, CustomerIndexEdit $pageCustomerIndexEdit, AddressInjectable $address = null, CustomerInjectable $initialCustomer = null) { $data = []; $filter = []; if ($initialCustomer) { $data['customer'] = $customer->hasData() ? array_merge($initialCustomer->getData(), $customer->getData()) : $initialCustomer->getData(); } else { $data['customer'] = $customer->getData(); } if ($address) { $data['addresses'][1] = $address->hasData() ? $address->getData() : []; } else { $data['addresses'] = []; } $filter['email'] = $data['customer']['email']; $pageCustomerIndex->open(); $pageCustomerIndex->getCustomerGridBlock()->searchAndOpen($filter); $dataForm = $pageCustomerIndexEdit->getCustomerForm()->getDataCustomer($customer, $address); $dataDiff = $this->verify($data, $dataForm); \PHPUnit_Framework_Assert::assertTrue(empty($dataDiff), 'Customer data on edit page(backend) not equals to passed from fixture.' . "\nFailed values: " . implode(', ', $dataDiff)); }
/** * Prepare data * * @param CustomerInjectable $customer * @return array */ public function __prepare(CustomerInjectable $customer) { $customer->persist(); return ['customer' => $customer]; }
/** * Assert that error message "Please correct this email address: "%email%"." is displayed * after customer with invalid email save * * @param CustomerInjectable $customer * @param CustomerIndexNew $pageCustomerIndexNew * @return void */ public function processAssert(CustomerInjectable $customer, CustomerIndexNew $pageCustomerIndexNew) { $expectMessage = str_replace('%email%', $customer->getEmail(), self::ERROR_EMAIL_MESSAGE); $actualMessage = $pageCustomerIndexNew->getMessagesBlock()->getErrorMessages(); \PHPUnit_Framework_Assert::assertEquals($expectMessage, $actualMessage, 'Wrong success message is displayed.' . "\nExpected: " . $expectMessage . "\nActual: " . $actualMessage); }
/** * Open customer review report * * @param CustomerInjectable $customer * @return void */ public function openReview(CustomerInjectable $customer) { $customerName = $customer->getFirstName() . ' ' . $customer->getLastName(); $this->_rootElement->find(sprintf($this->searchRow, $customerName), Locator::SELECTOR_XPATH)->click(); }
/** * Asserts that customer is not in customer's grid * * @param CustomerInjectable $customer * @param CustomerIndex $customerIndexPage * @return void */ public function processAssert(CustomerInjectable $customer, CustomerIndex $customerIndexPage) { $customerIndexPage->open(); \PHPUnit_Framework_Assert::assertFalse($customerIndexPage->getCustomerGridBlock()->isRowVisible(['email' => $customer->getEmail()]), 'Customer with email ' . $customer->getEmail() . 'is present in Customer grid.'); }
/** * Prepare data * * @param FixtureFactory $fixtureFactory * @param CustomerInjectable $customer * @return void */ public function __prepare(FixtureFactory $fixtureFactory, CustomerInjectable $customer) { $this->fixtureFactory = $fixtureFactory; $customer->persist(); $this->customer = $customer; }
/** * Run Update Customer Entity test * * @param CustomerInjectable $initialCustomer * @param CustomerInjectable $customer * @param AddressInjectable $address * @param AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage * @return void */ public function test(CustomerInjectable $initialCustomer, CustomerInjectable $customer, AddressInjectable $address, AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage) { // Preconditions $initialCustomer->persist(); // Steps $this->cmsIndex->open(); $this->cmsIndex->getLinksBlock()->openLink('Log In'); $this->customerAccountLogin->getLoginBlock()->fill($initialCustomer); $this->customerAccountLogin->getLoginBlock()->submit(); $this->customerAccountIndex->getInfoBlock()->openEditContactInfo(); $this->customerAccountEdit->getAccountInfoForm()->fill($customer); $this->customerAccountEdit->getAccountInfoForm()->submit(); \PHPUnit_Framework_Assert::assertThat($this->getName(), $assertCustomerInfoSuccessSavedMessage); $this->customerAccountIndex->getDashboardAddress()->editBillingAddress(); $this->customerAddressEdit->getEditForm()->fill($address); $this->customerAddressEdit->getEditForm()->saveAddress(); }
/** * Assert customer is subscribed to newsletter * * @param CustomerInjectable $customer * @param SubscriberIndex $subscriberIndex * @return void */ public function processAssert(CustomerInjectable $customer, SubscriberIndex $subscriberIndex) { $filter = ['email' => $customer->getEmail(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'status' => 'Subscribed']; $subscriberIndex->open(); \PHPUnit_Framework_Assert::assertTrue($subscriberIndex->getSubscriberGrid()->isRowVisible($filter), 'Customer with email \'' . $customer->getEmail() . '\' is absent in Newsletter Subscribers grid.'); }
/** * Asserts that customer is not in customer's grid * * @param CustomerInjectable $initialCustomer * @param CustomerIndex $pageCustomerIndex * @return void */ public function processAssert(CustomerInjectable $customer, CustomerIndex $customerIndexPage) { $filter = ['email' => $customer->getEmail()]; $customerIndexPage->open(); \PHPUnit_Framework_Assert::assertFalse($customerIndexPage->getCustomerGridBlock()->isRowVisible($filter), "Customer with email {$filter['email']} is present in Customer grid."); }
/** * Runs Delete Customer Address test * * @param CustomerInjectable $customer * @return array */ public function test(CustomerInjectable $customer) { // Precondition: $customer->persist(); $addressToDelete = $customer->getDataFieldConfig('address')['source']->getAddresses()[1]; // Steps: $this->cmsIndex->open(); $this->cmsIndex->getLinksBlock()->openLink("Log In"); $this->customerAccountLogin->getLoginBlock()->login($customer); $this->customerAccountIndex->getAccountMenuBlock()->openMenuItem('Address Book'); $this->customerAccountIndex->getAdditionalAddressBlock()->deleteAdditionalAddress($addressToDelete); return ['deletedAddress' => $addressToDelete]; }
/** * Mass assign customer group * * @param CustomerInjectable $customer * @param CustomerGroupInjectable $customerGroup * @return void */ public function test(CustomerInjectable $customer, CustomerGroupInjectable $customerGroup) { // Steps $customerGroup->persist(); $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->massaction([['email' => $customer->getEmail()]], [$this->customersGridActions => $customerGroup->getCustomerGroupCode()]); }
/** * Assert product reviews qty column in Review Report by Customer grid * * @param CustomerReportReview $customerReportReview * @param CustomerInjectable $customer * @param int $reviewsCount * @return void */ public function processAssert(CustomerReportReview $customerReportReview, CustomerInjectable $customer, $reviewsCount) { $customerName = $customer->getFirstName() . ' ' . $customer->getLastName(); $customerReportReview->open(); \PHPUnit_Framework_Assert::assertEquals($reviewsCount, $customerReportReview->getGridBlock()->getQtyReview($customerName), 'Wrong qty review in Customer Reviews Report grid.'); }
/** * Prepare data * * @param CustomerInjectable $customer * @param CatalogProductSimple $product * @return array */ public function __prepare(CustomerInjectable $customer, CatalogProductSimple $product) { $customer->persist(); $product->persist(); return ['customer' => $customer, 'product' => $product]; }