/** * Mass assign customer group * * @param Customer $customer * @param CustomerGroup $customerGroup * @return void */ public function test(Customer $customer, CustomerGroup $customerGroup) { // Steps $customerGroup->persist(); $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->massaction([['email' => $customer->getEmail()]], [$this->customersGridActions => $customerGroup->getCustomerGroupCode()]); }
/** * Assert that products added to wishlist are present on Customers account on backend. * * @param CustomerIndex $customerIndex * @param Customer $customer * @param CustomerIndexEdit $customerIndexEdit * @param InjectableFixture $product * @return void */ public function processAssert(CustomerIndex $customerIndex, Customer $customer, CustomerIndexEdit $customerIndexEdit, InjectableFixture $product) { $customerIndex->open(); $customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $customerIndexEdit->getCustomerForm()->openTab('wishlist'); /** @var \Magento\Wishlist\Test\Block\Adminhtml\Customer\Edit\Tab\Wishlist\Grid $wishlistGrid */ $wishlistGrid = $customerIndexEdit->getCustomerForm()->getTab('wishlist')->getSearchGridBlock(); \PHPUnit_Framework_Assert::assertTrue($wishlistGrid->isRowVisible(['product_name' => $product->getName()]), $product->getName() . " is not visible in customer wishlist on backend."); }
/** * Select customer if it is present in fixture or click create new customer button. * * @param CustomerFixture $customer * @return void */ public function selectCustomer(CustomerFixture $customer) { if ($customer->hasData('id')) { $this->searchAndOpen(['email' => $customer->getEmail()]); } else { $this->_rootElement->find($this->createNewCustomer)->click(); } $this->getTemplateBlock()->waitLoader(); }
/** * Runs Delete Customer Backend Entity test * * @param Customer $customer * @return void */ public function testDeleteCustomerBackendEntity(Customer $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 Address $deletedAddress * @param Customer $customer * @return void */ public function processAssert(OrderIndex $orderIndex, OrderCreateIndex $orderCreateIndex, Address $deletedAddress, Customer $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'); }
/** * Run update customer test. * * @param Customer $initialCustomer * @param Customer $customer * @param Address $address [optional] * @return void */ public function testUpdateCustomerBackendEntity(Customer $initialCustomer, Customer $customer, Address $address = null) { // Precondition $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(); }
/** * Authorize customer on frontend. * * @param Customer $customer * @throws \Exception * @return void */ protected function authorize(Customer $customer) { $url = $_ENV['app_frontend_url'] . 'customer/account/login/'; $this->transport->write($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($url, $data, CurlInterface::POST, ['Set-Cookie:' . $this->cookies]); $response = $this->read(); if (strpos($response, 'customer/account/login')) { throw new \Exception($customer->getFirstname() . ', cannot be logged in by curl handler!'); } }
/** * Assert customer info in Abandoned Carts report (Reports > Abandoned carts): * – name and email * – products and qty * – created and updated date * * @param AbandonedCarts $abandonedCarts * @param array $products * @param Customer $customer * @return void */ public function processAssert(AbandonedCarts $abandonedCarts, $products, Customer $customer) { $abandonedCarts->open(); $qty = 0; foreach ($products as $product) { $qty += $product->getCheckoutData()['qty']; } $filter = ['customer_name' => $customer->getFirstname() . " " . $customer->getLastname(), 'email' => $customer->getEmail(), 'items_count' => count($products), 'items_qty' => $qty, 'created_at' => date('m/j/Y'), 'updated_at' => date('m/j/Y')]; $abandonedCarts->getGridBlock()->search($filter); $filter['created_at'] = date('M j, Y'); $filter['updated_at'] = date('M j, Y'); \PHPUnit_Framework_Assert::assertTrue($abandonedCarts->getGridBlock()->isRowVisible($filter, false, false), 'Expected customer info is absent in Abandoned Carts report grid.'); }
/** * Asserts all Product Review variables in the reviews grid on customer page * * @param Customer $customer * @param Review $reviewInitial * @param Review $review * @param CustomerIndexEdit $customerIndexEdit * @param CustomerIndex $customerIndex * @param AssertProductReviewInGrid $assertProductReviewInGrid * @return void */ public function processAssert(Customer $customer, Review $reviewInitial, Review $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()->getTab('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.'); }
/** * Run Lock customer on login page test. * * @param Customer $initialCustomer * @param int $attempts * @param FixtureFactory $fixtureFactory * @param $incorrectPassword * @param string $configData * @return void */ public function test(Customer $initialCustomer, $attempts, FixtureFactory $fixtureFactory, $incorrectPassword, $configData = null) { $this->configData = $configData; // Preconditions $this->objectManager->create('Magento\\Config\\Test\\TestStep\\SetupConfigurationStep', ['configData' => $this->configData])->run(); $initialCustomer->persist(); $incorrectCustomer = $fixtureFactory->createByCode('customer', ['data' => ['email' => $initialCustomer->getEmail(), 'password' => $incorrectPassword]]); // Steps for ($i = 0; $i < $attempts; $i++) { $this->customerAccountLogin->open(); $this->customerAccountLogin->getLoginBlock()->fill($incorrectCustomer); $this->customerAccountLogin->getLoginBlock()->submit(); } }
/** * Move compare products on order page. * * @param Customer $customer * @param string $products * @return array */ public function test(Customer $customer, $products) { // Preconditions // Create products $products = $this->objectManager->create('\\Magento\\Catalog\\Test\\TestStep\\CreateProductsStep', ['products' => $products])->run()['products']; // Add products to compare foreach ($products as $itemProduct) { $this->browser->open($_ENV['app_frontend_url'] . $itemProduct->getUrlKey() . '.html'); $this->catalogProductView->getViewBlock()->clickAddToCompare(); } // Steps $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $this->customerIndexEdit->getPageActionsBlock()->createOrder(); $this->orderCreateIndex->getStoreBlock()->selectStoreView(); $activitiesBlock = $this->orderCreateIndex->getCustomerActivitiesBlock(); $activitiesBlock->getProductsInComparisonBlock()->addProductsToOrder($products); $activitiesBlock->updateChanges(); return ['products' => $products, 'productsIsConfigured' => false]; }
/** * Assert that customer forgot password message is present on customer account forgot password page. * * @param CustomerAccountLogin $customerLogin * @param Customer $customer * @return void */ public function processAssert(CustomerAccountLogin $customerLogin, Customer $customer) { $message = sprintf(self::SUCCESS_MESSAGE_FIRST_PART . self::SUCCESS_MESSAGE_SECOND_PART, $customer->getEmail()); \PHPUnit_Framework_Assert::assertEquals($message, $customerLogin->getMessages()->getSuccessMessages(), 'Wrong forgot password message is displayed.'); }
/** * Assert that error message "Please correct this email address: "%email%"." is displayed * after customer with invalid email save * * @param Customer $customer * @param CustomerIndexNew $pageCustomerIndexNew * @return void */ public function processAssert(Customer $customer, CustomerIndexNew $pageCustomerIndexNew) { $expectMessage = str_replace('%email%', $customer->getEmail(), self::ERROR_EMAIL_MESSAGE); $actualMessage = $pageCustomerIndexNew->getMessagesBlock()->getErrorMessage(); \PHPUnit_Framework_Assert::assertEquals($expectMessage, $actualMessage, 'Wrong success message is displayed.' . "\nExpected: " . $expectMessage . "\nActual: " . $actualMessage); }
/** * Open customer account * * @return void */ public function run() { $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $this->customer->getEmail()]); }
/** * Assert that login again to frontend with new password was success. * * @param FixtureFactory $fixtureFactory * @param CustomerAccountIndex $customerAccountIndex * @param Customer $initialCustomer * @param Customer $customer * @return void */ public function processAssert(FixtureFactory $fixtureFactory, CustomerAccountIndex $customerAccountIndex, Customer $initialCustomer, Customer $customer) { $customer = $fixtureFactory->createByCode('customer', ['dataset' => 'default', 'data' => ['email' => $initialCustomer->getEmail(), 'password' => $customer->getPassword(), 'password_confirmation' => $customer->getPassword()]]); $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); \PHPUnit_Framework_Assert::assertTrue($customerAccountIndex->getAccountMenuBlock()->isVisible(), 'Customer Account Dashboard is not visible.'); }
/** * Assert customer is subscribed to newsletter * * @param Customer $customer * @param SubscriberIndex $subscriberIndex * @return void */ public function processAssert(Customer $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.'); }
/** * Create order from customer page (cartActions). * * @param Customer $customer * @param string $product * @return array */ public function test(Customer $customer, $product) { //Preconditions // Create product $product = $this->objectManager->create('\\Magento\\Catalog\\Test\\TestStep\\CreateProductStep', ['product' => $product])->run()['product']; // Login under customer $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->catalogProductView->getViewBlock()->addToCart($product); //Steps $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $this->customerIndexEdit->getPageActionsBlock()->createOrder(); $this->orderCreateIndex->getStoreBlock()->selectStoreView(); $this->orderCreateIndex->getCustomerActivitiesBlock()->getShoppingCartItemsBlock()->addProductsToOrder([$product]); $this->orderCreateIndex->getCustomerActivitiesBlock()->updateChanges(); return ['products' => [$product]]; }
/** * Prepare order data. * * @param array $data * @return array */ protected function prepareOrderData(array $data) { $customerGroupId = $this->customer->hasData('group_id') ? $this->customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()->getCustomerGroupId() : 1; $result = ['name' => $this->customer->getFirstname(), 'order' => ['currency' => $data['order_currency_code'], 'account' => ['group_id' => $customerGroupId, 'email' => $this->customer->getEmail()], 'shipping_method' => isset($data['shipping_method']) ? $data['shipping_method'] : ''], 'item' => $this->prepareOrderProductsData($data['entity_id']), 'billing_address' => $this->prepareBillingAddress($data['billing_address_id']), 'shipping_same_as_billing' => 'on', 'payment' => $data['payment_auth_expiration']]; return $result; }
/** * Run update customer test. * * @param Customer $initialCustomer * @param Customer $customer * @param Address|null $address * @param int|null $addressIndexToDelete * @throws \Exception * @return array */ public function testUpdateCustomerBackendEntity(Customer $initialCustomer, Customer $customer, Address $address = null, $addressIndexToDelete = null) { // Precondition $initialCustomer->persist(); $addressToDelete = null; if ($addressIndexToDelete !== null) { $addressToDelete = $initialCustomer->getDataFieldConfig('address')['source']->getAddresses()[$addressIndexToDelete]; } // Steps $filter = ['email' => $initialCustomer->getEmail()]; $this->customerIndexPage->open(); $this->customerIndexPage->getCustomerGridBlock()->searchAndOpen($filter); $this->customerIndexEditPage->getCustomerForm()->updateCustomer($customer, $address, $addressToDelete); $this->customerIndexEditPage->getPageActionsBlock()->save(); return ['customer' => $this->prepareCustomer($customer, $initialCustomer, $address, $addressToDelete), 'addressToDelete' => $addressToDelete]; }
/** * Asserts that customer is not in customer's grid * * @param Customer $customer * @param CustomerIndex $customerIndexPage * @return void */ public function processAssert(Customer $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.'); }
/** * Move recently compared products on order page. * * @param Customer $customer * @param string $products * @return array */ public function test(Customer $customer, $products) { // Preconditions // Create product $products = $this->objectManager->create('\\Magento\\Catalog\\Test\\TestStep\\CreateProductsStep', ['products' => $products])->run()['products']; // Login under customer $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); foreach ($products as $itemProduct) { $this->browser->open($_ENV['app_frontend_url'] . $itemProduct->getUrlKey() . '.html'); $this->catalogProductView->getViewBlock()->clickAddToCompare(); } $this->cmsIndex->getLinksBlock()->openLink("Compare Products"); $this->catalogProductCompare->getCompareProductsBlock()->removeAllProducts(); // Steps: $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $this->customerIndexEdit->getPageActionsBlock()->createOrder(); $this->orderCreateIndex->getStoreBlock()->selectStoreView(); $activitiesBlock = $this->orderCreateIndex->getCustomerActivitiesBlock(); $activitiesBlock->getRecentlyComparedProductsBlock()->addProductsToOrder($products); $activitiesBlock->updateChanges(); return ['products' => $products, 'productsIsConfigured' => false]; }