/** * Assert that you will be redirected to url from dataset * * @param CmsIndex $cmsIndex * @param BrowserInterface $browser * @param CatalogSearchQuery $searchTerm * @return void */ public function processAssert(CmsIndex $cmsIndex, BrowserInterface $browser, CatalogSearchQuery $searchTerm) { $cmsIndex->open()->getSearchBlock()->search($searchTerm->getSynonymFor()); $windowUrl = $browser->getUrl(); $redirectUrl = $searchTerm->getRedirect(); \PHPUnit_Framework_Assert::assertEquals($windowUrl, $redirectUrl, 'Redirect by synonym was not executed.' . PHP_EOL . "Expected: " . $redirectUrl . PHP_EOL . "Actual: " . $windowUrl); }
/** * Assert that apache redirect works by opening category page and asserting index.php in its url * * @param Category $category * @param CmsIndex $homePage * @param BrowserInterface $browser */ public function processAssert(Category $category, CmsIndex $homePage, BrowserInterface $browser) { $category->persist(); $homePage->open(); $homePage->getTopmenu()->selectCategoryByName($category->getName()); \PHPUnit_Framework_Assert::assertTrue(strpos($browser->getUrl(), 'index.php') === false, 'Apache redirect for category does not work.'); }
/** * Create Customer account on Storefront. * * @param Customer $customer * @return void */ public function test(Customer $customer) { // Steps $this->cmsIndex->open(); $this->cmsIndex->getLinksBlock()->openLink('Create an Account'); $this->customerAccountCreate->getRegisterForm()->registerCustomer($customer); }
/** * Run step. * * @return void */ public function run() { $this->customerAccountLogout->open(); $this->cmsIndex->getFooterBlock()->clickLink('Orders and Returns'); $this->salesGuestForm->getSearchForm()->fill($this->order); $this->salesGuestForm->getSearchForm()->submit(); }
/** * Check that block Recently Viewed contains product on category page * * @param CatalogProductSimple $productSimple * @param Category $category * @return void */ protected function checkRecentlyViewedBlockOnCategory(CatalogProductSimple $productSimple, Category $category) { $this->cmsIndex->open(); $this->cmsIndex->getTopmenu()->selectCategoryByName($category->getName()); $products = $this->catalogCategoryView->getViewBlock()->getProductsFromRecentlyViewedBlock(); \PHPUnit_Framework_Assert::assertTrue(in_array($productSimple->getName(), $products), 'Product' . $productSimple->getName() . ' is absent on Recently Viewed block on Category page.'); }
/** * Create Customer account on frontend * * @param CustomerInjectable $customer */ public function testCreateCustomer(CustomerInjectable $customer) { //Steps $this->cmsIndex->open(); $this->cmsIndex->getLinksBlock()->openLink('Register'); $this->customerAccountCreate->getRegisterForm()->registerCustomer($customer); }
/** * Assert that the category cannot be accessed from the navigation bar in the frontend * * @param CmsIndex $cmsIndex * @param Category $category * @param BrowserInterface $browser * @return void */ public function processAssert(CmsIndex $cmsIndex, Category $category, BrowserInterface $browser) { $cmsIndex->open(); \PHPUnit_Framework_Assert::assertFalse($cmsIndex->getTopmenu()->isCategoryVisible($category->getName()), 'Category can be accessed from the navigation bar in the frontend.'); $browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertEquals(self::NOT_FOUND_MESSAGE, $cmsIndex->getTitleBlock()->getTitle(), 'Wrong page is displayed.'); }
/** * Assert that video is displayed on category page on Store front. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param InjectableFixture $initialProduct * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, InjectableFixture $initialProduct) { $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($initialProduct->getCategoryIds()[0]); $src = $catalogCategoryView->getListProductBlock()->getProductItem($initialProduct)->getBaseImageSource(); \PHPUnit_Framework_Assert::assertFalse(strpos($src, '/placeholder/') !== false, 'Video preview image is not displayed on category view when it should.'); }
/** * Check whether the attribute filter is displayed on the frontend in Layered navigation. * * @param CatalogCategoryView $catalogCategoryView * @param InjectableFixture $product * @param CatalogProductAttribute $attribute * @param CmsIndex $cmsIndex * @param FixtureFactory $fixtureFactory * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, InjectableFixture $product, CatalogProductAttribute $attribute, CmsIndex $cmsIndex, FixtureFactory $fixtureFactory) { $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_with_category_with_anchor', 'data' => ['category_ids' => ['presets' => null, 'category' => $product->getDataFieldConfig('category_ids')['source']->getCategories()[0]]]])->persist(); $cmsIndex->open()->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array($label, $catalogCategoryView->getLayeredNavigationBlock()->getFilters()), 'Attribute is absent in layered navigation on category page.'); }
/** * Assert that prices on order review and customer order pages are equal to specified in dataset. * * @param array $prices * @param InjectableFixture $product * @param CheckoutCart $checkoutCart * @param CheckoutOnepage $checkoutOnepage * @param CheckoutOnepageSuccess $checkoutOnepageSuccess * @param CustomerOrderView $customerOrderView * @param CmsIndex $cmsIndex * @return void */ public function processAssert(array $prices, InjectableFixture $product, CheckoutCart $checkoutCart, CheckoutOnepage $checkoutOnepage, CheckoutOnepageSuccess $checkoutOnepageSuccess, CustomerOrderView $customerOrderView, CmsIndex $cmsIndex) { $this->checkoutOnepage = $checkoutOnepage; $this->customerOrderView = $customerOrderView; $checkoutCart->getProceedToCheckoutBlock()->proceedToCheckout(); $cmsIndex->getCmsPageBlock()->waitPageInit(); $shippingMethod = ['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed']; $checkoutOnepage->getShippingMethodBlock()->selectShippingMethod($shippingMethod); $checkoutOnepage->getShippingMethodBlock()->clickContinue(); $checkoutOnepage->getPaymentBlock()->selectPaymentMethod(['method' => 'checkmo']); $actualPrices = []; $actualPrices = $this->getReviewPrices($actualPrices, $product); $actualPrices = $this->getReviewTotals($actualPrices); $prices = $this->preparePrices($prices); //Order review prices verification $message = 'Prices on order review should be equal to defined in dataset.'; \PHPUnit_Framework_Assert::assertEquals(array_diff_key($prices, ['cart_item_price_excl_tax' => null, 'cart_item_price_incl_tax' => null]), $actualPrices, $message); $checkoutOnepage->getPaymentBlock()->placeOrder(); $checkoutOnepageSuccess->getSuccessBlock()->getGuestOrderId(); $checkoutOnepageSuccess->getSuccessBlock()->openOrder(); $actualPrices = []; $actualPrices = $this->getOrderPrices($actualPrices, $product); $actualPrices = $this->getOrderTotals($actualPrices); //Frontend order prices verification $message = 'Prices on order view page should be equal to defined in dataset.'; \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); }
/** * Assert configurable product, corresponds to the category page * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param CatalogProductConfigurable $configurable * @param CatalogCategory $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, CatalogProductConfigurable $configurable, CatalogCategory $category) { //Open category view page $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($category->getName()); //process asserts $this->assertPrice($configurable, $catalogCategoryView); }
/** * Assert product is present on mini shopping cart * * @param CmsIndex $cmsIndex * @param array $products * @return void */ public function processAssert(CmsIndex $cmsIndex, array $products) { $cmsIndex->open(); foreach ($products as $product) { $cmsIndex->getCartSidebarBlock()->openMiniCart(); \PHPUnit_Framework_Assert::assertTrue($cmsIndex->getCartSidebarBlock()->getCartItem($product)->isVisible(), 'Product ' . $product->getName() . ' is absent in Mini Shopping Cart.'); } }
/** * Login customer and open Order page. * * @param Customer $customer * @return void */ protected function loginCustomerAndOpenOrderPage(Customer $customer) { $this->cmsIndex->open(); $loginCustomerOnFrontendStep = $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer]); $loginCustomerOnFrontendStep->run(); $this->cmsIndex->getLinksBlock()->openLink('My Account'); $this->customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Orders'); }
/** * Assert check URL rewrite custom redirect * * @param UrlRewrite $urlRewrite * @param BrowserInterface $browser * @param CmsIndex $cmsIndex * @return void */ public function processAssert(UrlRewrite $urlRewrite, BrowserInterface $browser, CmsIndex $cmsIndex) { $browser->open($_ENV['app_frontend_url'] . $urlRewrite->getRequestPath()); $entity = $urlRewrite->getDataFieldConfig('target_path')['source']->getEntity(); $title = $entity->hasData('name') ? $entity->getName() : $entity->getContentHeading(); $pageTitle = $cmsIndex->getTitleBlock()->getTitle(); \PHPUnit_Framework_Assert::assertEquals($pageTitle, $title, 'URL rewrite product redirect false.' . "\nExpected: " . $title . "\nActual: " . $pageTitle); }
/** * Run test creation for advanced search entity * * @param array $products * @param CatalogProductSimple $productSearch * @param CmsIndex $cmsIndex * @param AdvancedSearch $searchPage * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function testSearch(array $products, CatalogProductSimple $productSearch, CmsIndex $cmsIndex, AdvancedSearch $searchPage) { $cmsIndex->open(); $cmsIndex->getSearchBlock()->clickAdvancedSearchButton(); $searchForm = $searchPage->getForm(); $searchForm->fill($productSearch); $searchForm->submit(); }
/** * Assert that product is displayed in related products section * * @param CatalogProductSimple $product1 * @param CatalogProductSimple $product2 * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @return void */ public function processAssert(CatalogProductSimple $product1, CatalogProductSimple $product2, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView) { $categoryName = $product1->getCategoryIds()[0]; $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $catalogCategoryView->getListProductBlock()->openProductViewPage($product1->getName()); \PHPUnit_Framework_Assert::assertTrue($catalogProductView->getRelatedProductBlock()->isRelatedProductVisible($product2->getName()), 'Product \'' . $product2->getName() . '\' is absent in related products.'); }
/** * Assert that link "Compare Products..." on top menu of page * * @param array $products * @param CmsIndex $cmsIndex * @return void */ public function processAssert(array $products, CmsIndex $cmsIndex) { $productQty = count($products); $qtyOnPage = $cmsIndex->getLinksBlock()->getQtyInCompareList(); \PHPUnit_Framework_Assert::assertEquals($productQty, $qtyOnPage, 'Qty is not correct in "Compare Products" link.'); $compareProductUrl = '/catalog/product_compare/'; \PHPUnit_Framework_Assert::assertTrue(strpos($cmsIndex->getLinksBlock()->getLinkUrl('Compare Products'), $compareProductUrl) !== false, 'Compare product link isn\'t lead to Compare Product Page.'); }
/** * Assert that created CMS page with 'Status' - Disabled displays with '404 Not Found' message on Frontend. * * @param CmsPage $cms * @param FrontCmsIndex $frontCmsIndex * @param CmsPageIndex $cmsIndex * @param BrowserInterface $browser * @return void */ public function processAssert(CmsPage $cms, FrontCmsIndex $frontCmsIndex, CmsPageIndex $cmsIndex, BrowserInterface $browser) { $cmsIndex->open(); $filter = ['title' => $cms->getTitle()]; $cmsIndex->getCmsPageGridBlock()->searchAndPreview($filter); $browser->selectWindow(); \PHPUnit_Framework_Assert::assertEquals(self::NOT_FOUND_MESSAGE, $frontCmsIndex->getTitleBlock()->getTitle(), 'Wrong page is displayed.'); }
/** * Login customer. * * @return void */ public function run() { $this->logoutCustomerOnFrontend->run(); $this->cmsIndex->getLinksBlock()->openLink('Sign In'); $this->cmsIndex->getCmsPageBlock()->waitPageInit(); $this->customerAccountLogin->getLoginBlock()->login($this->customer); $this->cmsIndex->getCmsPageBlock()->waitPageInit(); }
/** * Assert that product is not displayed in up-sell section * * @param CatalogProductSimple $product1 * @param CatalogProductSimple $product2 * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @return void */ public function processAssert(CatalogProductSimple $product1, CatalogProductSimple $product2, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView) { $categoryName = $product1->getCategoryIds()[0]['name']; $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $catalogCategoryView->getListProductBlock()->openProductViewPage($product1->getName()); \PHPUnit_Framework_Assert::assertFalse($catalogProductView->getUpsellBlock()->isUpsellProductVisible($product2->getName()), 'Product \'' . $product2->getName() . '\' is exist in up-sells products.'); }
/** * Run test creation for advanced search entity. * * @param CatalogProductSimple $productSearch * @param CmsIndex $cmsIndex * @param AdvancedSearch $searchPage * @return void */ public function test(CatalogProductSimple $productSearch, CmsIndex $cmsIndex, AdvancedSearch $searchPage) { $cmsIndex->open(); $cmsIndex->getFooterBlock()->openAdvancedSearch(); $searchForm = $searchPage->getForm(); $searchForm->fill($productSearch); $searchForm->submit(); }
/** * Assert that created CMS block displayed on frontend category page (in order to assign block to category: * go to category page> Display settings> CMS Block). * * @param CmsIndex $cmsIndex * @param CmsBlock $cmsBlock * @param CatalogCategoryView $catalogCategoryView * @param FixtureFactory $fixtureFactory * @return void */ public function processAssert(CmsIndex $cmsIndex, CmsBlock $cmsBlock, CatalogCategoryView $catalogCategoryView, FixtureFactory $fixtureFactory) { $category = $fixtureFactory->createByCode('category', ['dataset' => 'default_subcategory', 'data' => ['display_mode' => 'Static block and products', 'landing_page' => $cmsBlock->getTitle()]]); $category->persist(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($category->getName()); $categoryViewContent = $catalogCategoryView->getViewBlock()->getContent(); \PHPUnit_Framework_Assert::assertEquals($cmsBlock->getContent(), $categoryViewContent, 'Wrong block content on category is displayed.'); }
/** * Assert that product is not present in Wishlist on Frontend * * @param CustomerAccountIndex $customerAccountIndex * @param WishlistIndex $wishlistIndex * @param InjectableFixture $product * @param CustomerInjectable $customer * @param CmsIndex $cmsIndex * @param CustomerAccountLogin $customerAccountLogin * @param CustomerAccountLogout $customerAccountLogout * @return void */ public function processAssert(CustomerAccountIndex $customerAccountIndex, WishlistIndex $wishlistIndex, InjectableFixture $product, CustomerInjectable $customer, CmsIndex $cmsIndex, CustomerAccountLogin $customerAccountLogin, CustomerAccountLogout $customerAccountLogout) { $productName = $product->getName(); $customerAccountLogout->open(); $cmsIndex->getLinksBlock()->openLink('Log In'); $customerAccountLogin->getLoginBlock()->login($customer); $customerAccountIndex->open()->getAccountMenuBlock()->openMenuItem("My Wish List"); \PHPUnit_Framework_Assert::assertFalse($wishlistIndex->getWishlistBlock()->getProductItemsBlock()->isProductPresent($productName), 'Product \'' . $productName . '\' is present in Wishlist on Frontend.'); }
/** * Assert that created widget is absent on frontend on Home page * * @param CmsIndex $cmsIndex * @param Widget $widget * @param AdminCache $adminCache * @return void */ public function processAssert(CmsIndex $cmsIndex, Widget $widget, AdminCache $adminCache) { // Flush cache $adminCache->open(); $adminCache->getActionsBlock()->flushMagentoCache(); $adminCache->getMessagesBlock()->waitSuccessMessage(); $cmsIndex->open(); $widgetText = $widget->getParameters()['anchor_text']; \PHPUnit_Framework_Assert::assertFalse($cmsIndex->getWidgetView()->isWidgetVisible($widget, $widgetText), 'Widget is present on Home page.'); }
/** * Assert that after applying changes, currency symbol changed on Product Details Page. * * @param CatalogProductSimple $product * @param BrowserInterface $browser * @param CmsIndex $cmsIndex * @param CatalogProductView $catalogProductView * @param CurrencySymbolEntity $currencySymbol * @return void */ public function processAssert(CatalogProductSimple $product, BrowserInterface $browser, CmsIndex $cmsIndex, CatalogProductView $catalogProductView, CurrencySymbolEntity $currencySymbol) { $cmsIndex->open(); $cmsIndex->getCurrencyBlock()->switchCurrency($currencySymbol); $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $price = $catalogProductView->getViewBlock()->getPriceBlock()->getPrice(); preg_match('`(.*?)\\d`', $price, $matches); $symbolOnPage = isset($matches[1]) ? $matches[1] : null; \PHPUnit_Framework_Assert::assertEquals($currencySymbol->getCustomCurrencySymbol(), $symbolOnPage, 'Wrong Currency Symbol is displayed on Product page.'); }
/** * Assert that product is displayed in cross-sell section * * @param CatalogProductSimple $product1 * @param CatalogProductSimple $product2 * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @return void */ public function processAssert(CatalogProductSimple $product1, CatalogProductSimple $product2, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart) { $categoryName = $product1->getCategoryIds()[0]; $checkoutCart->open(); $checkoutCart->getCartBlock()->clearShoppingCart(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $catalogCategoryView->getListProductBlock()->openProductViewPage($product1->getName()); $catalogProductView->getViewBlock()->addToCart($product1); \PHPUnit_Framework_Assert::assertTrue($checkoutCart->getCrosssellBlock()->verifyProductCrosssell($product2), 'Product \'' . $product2->getName() . '\' is absent in cross-sell section.'); }
/** * Assert that Compare Products block is presented on CMS pages. * Block contains information about compared products * * @param array $products * @param CmsIndex $cmsIndex * @param FixtureFactory $fixtureFactory * @param BrowserInterface $browser * @return void */ public function processAssert(array $products, CmsIndex $cmsIndex, FixtureFactory $fixtureFactory, BrowserInterface $browser) { $newCmsPage = $fixtureFactory->createByCode('cmsPage', ['dataset' => '3_column_template']); $newCmsPage->persist(); $browser->open($_ENV['app_frontend_url'] . $newCmsPage->getIdentifier()); foreach ($products as &$product) { $product = $product->getName(); } \PHPUnit_Framework_Assert::assertEquals($products, $cmsIndex->getCompareProductsBlock()->getProducts(), 'Compare product block contains NOT valid information about compared products.'); }
/** * Run edit search term test * * @param CatalogSearchQuery $searchTerm * @return void */ public function test(CatalogSearchQuery $searchTerm) { // Preconditions $searchText = $searchTerm->getQueryText(); // Steps $this->cmsIndex->open()->getSearchBlock()->search($searchText); $this->indexPage->open()->getGrid()->searchAndOpen(['search_query' => $searchText]); $this->editPage->getForm()->fill($searchTerm); $this->editPage->getFormPageActions()->save(); }
/** * Create Existing Customer account on frontend. * * @param Customer $customer * @return void */ public function testCreateExistingCustomer(Customer $customer) { // Precondition $existingCustomer = clone $customer; $customer->persist(); // Steps $this->cmsIndex->open(); $this->cmsIndex->getLinksBlock()->openLink('Create an Account'); $this->customerAccountCreate->getRegisterForm()->registerCustomer($existingCustomer); }
/** * Assert that Catalog Price Rule is not applied for product(s) in Catalog. * * @param CmsIndex $cmsIndexPage * @param CatalogCategoryView $catalogCategoryViewPage * @param array $products * @return void */ public function processAssert(CmsIndex $cmsIndexPage, CatalogCategoryView $catalogCategoryViewPage, array $products) { $cmsIndexPage->open(); foreach ($products as $product) { $categoryName = $product->getCategoryIds()[0]; $cmsIndexPage->getTopmenu()->selectCategoryByName($categoryName); $priceBlock = $catalogCategoryViewPage->getListProductBlock()->getProductItem($product)->getPriceBlock(); \PHPUnit_Framework_Assert::assertFalse($priceBlock->isSpecialPriceVisible(), "Catalog price rule is applied!\n"); } }