/** * 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 update message is appears on customer grid (Customers > All Customers) * * @param CustomerInjectable|CustomerInjectable[] $customer * @param CustomerIndex $pageCustomerIndex * @return void */ public function processAssert($customer, CustomerIndex $pageCustomerIndex) { $customers = is_array($customer) ? $customer : [$customer]; $customerCount = count($customers); $actualMessage = $pageCustomerIndex->getMessagesBlock()->getSuccessMessages(); \PHPUnit_Framework_Assert::assertEquals(sprintf(self::UPDATE_MESSAGE, $customerCount), $actualMessage); }
/** * Create customer on backend. * * @param Customer $customer * @param string $customerAction * @param Address $address * @return void */ public function test(Customer $customer, $customerAction, Address $address = null) { // Steps $this->pageCustomerIndex->open(); $this->pageCustomerIndex->getPageActionsBlock()->addNew(); $this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($customer, $address); $this->pageCustomerIndexNew->getPageActionsBlock()->{$customerAction}(); }
/** * Assert customer availability in Customer Grid * * @param Customer $customer * @param CustomerIndex $pageCustomerIndex * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(Customer $customer, CustomerIndex $pageCustomerIndex) { $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.'); }
/** * 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."); }
/** * Create customer on backend. * * @param Customer $customer * @param Address $address * @param string $customerAction * @return void */ public function test(Customer $customer, Address $address, $customerAction) { // Prepare data $address = $address->hasData() ? $address : null; // Steps $this->pageCustomerIndex->open(); $this->pageCustomerIndex->getPageActionsBlock()->addNew(); $this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($customer, $address); $this->pageCustomerIndexNew->getPageActionsBlock()->{$customerAction}(); }
/** * 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(); }
/** * 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); }
/** * @param CustomerInjectable $customer * @param AddressInjectable $address */ public function testCreateCustomerBackendEntity(CustomerInjectable $customer, AddressInjectable $address) { // Prepare data $address = $address->hasData() ? $address : null; // Steps $this->pageCustomerIndex->open(); $this->pageCustomerIndex->getPageActionsBlock()->addNew(); $this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($customer, $address); $this->pageCustomerIndexNew->getPageActionsBlock()->save(); }
/** * Create customer on backend. * * @param Customer $customer * @return void */ public function test(Customer $customer) { // Precondition $customer->persist(); // Steps $this->pageCustomerIndex->open(); $this->pageCustomerIndex->getPageActionsBlock()->addNew(); $this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($customer); $this->pageCustomerIndexNew->getPageActionsBlock()->save(); }
/** * New Accounts Report. * * @param Customer $customer * @param array $customersReport * @return void */ public function test(Customer $customer, array $customersReport) { $this->markTestIncomplete('Bug: MAGETWO-35037'); // 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 customer name is present in search results * * @param Dashboard $dashboard * @param GlobalSearch $search * @param CustomerIndex $customerIndex * @return void */ public function processAssert(Dashboard $dashboard, GlobalSearch $search, CustomerIndex $customerIndex) { $customer = $search->getDataFieldConfig('query')['source']->getEntity(); $customerName = $customer->getFirstname() . " " . $customer->getLastname(); $isVisibleInResult = $dashboard->getAdminPanelHeader()->isSearchResultVisible($customerName); \PHPUnit_Framework_Assert::assertTrue($isVisibleInResult, 'Customer name ' . $customerName . ' is absent in search results'); $dashboard->getAdminPanelHeader()->navigateToGrid("Customers"); $isCustomerGridVisible = $customerIndex->getCustomerGridBlock()->isVisible(); \PHPUnit_Framework_Assert::assertTrue($isCustomerGridVisible, 'Customer grid is not visible'); \PHPUnit_Framework_Assert::assertContains((string) $customer->getId(), $customerIndex->getCustomerGridBlock()->getAllIds(), 'Customer grid does not have ' . $customerName . ' in search results'); }
/** * 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(); }
/** * Configure customer wish list on backend. * * @param Customer $customer * @param string $product * @param CustomerIndex $customerIndex * @param CustomerIndexEdit $customerIndexEdit * @return array */ public function test(Customer $customer, $product, CustomerIndex $customerIndex, CustomerIndexEdit $customerIndexEdit) { // Preconditions $product = $this->createProducts($product)[0]; $this->loginCustomer($customer); $this->addToWishlist([$product], true); // Steps $customerIndex->open(); $customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $customerIndexEdit->getCustomerForm()->openTab('wishlist'); return ['product' => $product]; }
/** * @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(); }
/** * Runs Delete Customer Backend Entity test * * @param int $customersQty * @param int $customersQtyToDelete * @return array */ public function test($customersQty, $customersQtyToDelete) { // Preconditions: $customers = $this->createCustomers($customersQty); $deleteCustomers = []; for ($i = 0; $i < $customersQtyToDelete; $i++) { $deleteCustomers[] = ['email' => $customers[$i]->getEmail()]; } // Steps: $this->customerIndexPage->open(); $this->customerIndexPage->getCustomerGridBlock()->massaction($deleteCustomers, 'Delete', true); return ['customers' => $customers]; }
/** * Assert that customer group find on account information page. * * @param FixtureFactory $fixtureFactory * @param CustomerGroup $customerGroup * @param CustomerIndexNew $customerIndexNew * @param CustomerIndex $customerIndex * @return void */ public function processAssert(FixtureFactory $fixtureFactory, CustomerGroup $customerGroup, CustomerIndexNew $customerIndexNew, CustomerIndex $customerIndex) { /** @var Customer $customer */ $customer = $fixtureFactory->createByCode('customer', ['dataset' => 'defaultBackend', 'data' => ['group_id' => ['customerGroup' => $customerGroup]]]); $filter = ['email' => $customer->getEmail()]; $customerIndexNew->open(); $customerIndexNew->getCustomerForm()->fillCustomer($customer); $customerIndexNew->getPageActionsBlock()->save(); $customerIndex->getCustomerGridBlock()->searchAndOpen($filter); $customerFormData = $customerIndexNew->getCustomerForm()->getData($customer); $customerFixtureData = $customer->getData(); $diff = array_diff($customerFixtureData, $customerFormData); \PHPUnit_Framework_Assert::assertTrue(empty($diff), "Customer group {$customerGroup->getCustomerGroupCode()} not in account information page."); }
/** * 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.'); }
/** * Delete product from customer wishlist on backend * * @param Customer $customer * @param string $product * @param CustomerIndex $customerIndex * @param CustomerIndexEdit $customerIndexEdit * @return array */ public function test(Customer $customer, $product, CustomerIndex $customerIndex, CustomerIndexEdit $customerIndexEdit) { //Preconditions $product = $this->createProducts($product)[0]; $this->loginCustomer($customer); $this->addToWishlist([$product]); //Steps $customerIndex->open(); $customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $customerForm = $customerIndexEdit->getCustomerForm(); $customerForm->openTab('wishlist'); $filter = ['product_name' => $product->getName()]; $customerForm->getTab('wishlist')->getSearchGridBlock()->searchAndAction($filter, 'Delete'); return ['products' => [$product]]; }
/** * Move last ordered products on order page. * * @param OrderInjectable $order * @return array */ public function test(OrderInjectable $order) { // Preconditions: $order->persist(); $customer = $order->getDataFieldConfig('customer_id')['source']->getCustomer(); // Steps: $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $this->customerIndexEdit->getPageActionsBlock()->createOrder(); $this->orderCreateIndex->getStoreBlock()->selectStoreView(); $products = $order->getEntityId()['products']; $activitiesBlock = $this->orderCreateIndex->getCustomerActivitiesBlock(); $activitiesBlock->getLastOrderedItemsBlock()->addProductsToOrder($products); $activitiesBlock->updateChanges(); return ['products' => $products]; }
/** * Assert that displayed customer data on edit page(backend) equals passed from fixture. * * @param Customer $customer * @param CustomerIndex $pageCustomerIndex * @param CustomerIndexEdit $pageCustomerIndexEdit * @param Address $address[optional] * @return void */ public function processAssert(Customer $customer, CustomerIndex $pageCustomerIndex, CustomerIndexEdit $pageCustomerIndexEdit, Address $address = null) { $data = []; $filter = []; $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)); }
/** * 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]; }
/** * 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]]; }
/** * 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]; }
/** * Run manage product review test * * @param ReviewInjectable $reviewInitial * @param ReviewInjectable $review * @param CustomerInjectable $customer * @return array */ public function test(ReviewInjectable $reviewInitial, ReviewInjectable $review, CustomerInjectable $customer) { // Preconditions $this->login($customer); /** @var CatalogProductSimple $product */ $product = $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity(); $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->catalogProductView->getReviewSummary()->getAddReviewLink()->click(); $this->catalogProductView->getReviewFormBlock()->fill($reviewInitial); $this->catalogProductView->getReviewFormBlock()->submit(); $this->reviewInitial = $reviewInitial; // Steps $this->customerIndex->open(); $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); $this->customerIndexEdit->getCustomerForm()->openTab('product_reviews'); $filter = ['title' => $reviewInitial->getTitle(), 'sku' => $product->getSku()]; $this->customerIndexEdit->getCustomerForm()->getTabElement('product_reviews')->getReviewsGrid()->searchAndOpen($filter); $this->reviewEdit->getReviewForm()->fill($review); $this->reviewEdit->getPageActions()->save(); return ['reviewInitial' => $reviewInitial, 'product' => $product]; }
/** * 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]; }
/** * 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.'); }
/** * Asserts that actual delete message equals expected * * @param CustomerIndex $customerIndexPage * @return void */ public function processAssert(CustomerIndex $customerIndexPage) { $actualMessage = $customerIndexPage->getMessagesBlock()->getSuccessMessage(); \PHPUnit_Framework_Assert::assertEquals(self::DELETE_MESSAGE, $actualMessage, 'Wrong success message is displayed.' . "\nExpected: " . self::DELETE_MESSAGE . "\nActual: " . $actualMessage); }
/** * Assert that message "A total of "x" record(s) were deleted." * * @param $customersQtyToDelete * @param CustomerIndex $customerIndexPage * @return void */ public function processAssert($customersQtyToDelete, CustomerIndex $customerIndexPage) { \PHPUnit_Framework_Assert::assertEquals(sprintf(self::SUCCESS_DELETE_MESSAGE, $customersQtyToDelete), $customerIndexPage->getMessagesBlock()->getSuccessMessage(), 'Wrong delete message is displayed.'); }
/** * Asserts that "Back" button works on customer edit page (returns to customers grid). * * @param CustomerIndexEdit $customerEditPage * @param CustomerIndex $customerGridPage * @return void */ public function processAssert(CustomerIndexEdit $customerEditPage, CustomerIndex $customerGridPage) { $customerEditPage->getPageActionsBlock()->back(); \PHPUnit_Framework_Assert::assertTrue($customerGridPage->getCustomerGridBlock()->isVisible(), 'Clicking on "Back" button does not redirect to customers grid.'); }