/** * 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.'); }
/** * 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.'); }
/** * Assert that displayed category data on category page equals to passed from fixture * * @param CatalogCategory $category * @param CatalogCategory $initialCategory * @param FixtureFactory $fixtureFactory * @param CatalogCategoryView $categoryView * @param Browser $browser * @return void */ public function processAssert(CatalogCategory $category, CatalogCategory $initialCategory, FixtureFactory $fixtureFactory, CatalogCategoryView $categoryView, Browser $browser) { $product = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'default', 'data' => ['category_ids' => ['category' => $initialCategory]]]); $categoryData = array_merge($initialCategory->getData(), $category->getData()); $product->persist(); $url = $_ENV['app_frontend_url'] . strtolower($category->getUrlKey()) . '.html'; $browser->open($url); \PHPUnit_Framework_Assert::assertEquals($url, $browser->getUrl(), 'Wrong page URL.' . "\nExpected: " . $url . "\nActual: " . $browser->getUrl()); if (isset($categoryData['name'])) { $title = $categoryView->getTitleBlock()->getTitle(); \PHPUnit_Framework_Assert::assertEquals($categoryData['name'], $title, 'Wrong page title.' . "\nExpected: " . $categoryData['name'] . "\nActual: " . $title); } if (isset($categoryData['description'])) { $description = $categoryView->getViewBlock()->getDescription(); \PHPUnit_Framework_Assert::assertEquals($categoryData['description'], $description, 'Wrong category description.' . "\nExpected: " . $categoryData['description'] . "\nActual: " . $description); } if (isset($categoryData['default_sort_by'])) { $sortBy = strtolower($categoryData['default_sort_by']); $sortType = $categoryView->getTopToolbar()->getSelectSortType(); \PHPUnit_Framework_Assert::assertEquals($sortBy, $sortType, 'Wrong sorting type.' . "\nExpected: " . $sortBy . "\nActual: " . $sortType); } if (isset($categoryData['available_sort_by'])) { $availableSortType = array_filter($categoryData['available_sort_by'], function (&$value) { return $value !== '-' && ucfirst($value); }); if ($availableSortType) { $availableSortType = array_values($availableSortType); $availableSortTypeOnPage = $categoryView->getTopToolbar()->getSortType(); \PHPUnit_Framework_Assert::assertEquals($availableSortType, $availableSortTypeOnPage, 'Wrong available sorting type.' . "\nExpected: " . implode(PHP_EOL, $availableSortType) . "\nActual: " . implode(PHP_EOL, $availableSortTypeOnPage)); } } }
/** * 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.'); }
/** * Assert that created entity was found on search page * * @param UrlRewrite $initialRewrite * @param UrlRewrite $urlRewrite * @param Browser $browser * @param CatalogCategoryView $categoryView * @return void */ public function processAssert(UrlRewrite $initialRewrite, UrlRewrite $urlRewrite, Browser $browser, CatalogCategoryView $categoryView) { $urlRequestPath = $urlRewrite->hasData('request_path') ? $urlRewrite->getRequestPath() : $initialRewrite->getRequestPath(); $browser->open($_ENV['app_frontend_url'] . $urlRequestPath); $entity = $initialRewrite->getDataFieldConfig('id_path')['source']->getEntity()->getName(); \PHPUnit_Framework_Assert::assertTrue($categoryView->getListProductBlock()->isProductVisible($entity), "Created entity '{$entity}' isn't found."); }
/** * Assert that displayed assigned products on category page equals passed from fixture * * @param CatalogCategory $category * @param CatalogCategoryView $categoryView * @param Browser $browser * @return void */ public function processAssert(CatalogCategory $category, CatalogCategoryView $categoryView, Browser $browser) { $browser->open($_ENV['app_frontend_url'] . strtolower($category->getUrlKey()) . '.html'); $products = $category->getDataFieldConfig('category_products')['source']->getProducts(); foreach ($products as $productFixture) { \PHPUnit_Framework_Assert::assertTrue($categoryView->getListProductBlock()->isProductVisible($productFixture->getName()), "Products '{$productFixture->getName()}' not find."); } }
/** * Assert that displayed breadcrumbs on category page equals to passed from fixture. * * @param BrowserInterface $browser * @param Category $category * @param CatalogCategoryView $catalogCategoryView * @return void */ public function processAssert(BrowserInterface $browser, Category $category, CatalogCategoryView $catalogCategoryView) { $this->browser = $browser; $this->openCategory($category); $breadcrumbs = $this->getBreadcrumbs($category); $pageBreadcrumbs = $catalogCategoryView->getBreadcrumbs()->getText(); \PHPUnit_Framework_Assert::assertEquals($breadcrumbs, $pageBreadcrumbs, 'Wrong breadcrumbs of category page.' . "\nExpected: " . $breadcrumbs . "\nActual: " . $pageBreadcrumbs); }
/** * 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 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.'); }
/** * Verify product price on category view page. * * @param FixtureInterface $product * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(FixtureInterface $product, CatalogCategoryView $catalogCategoryView) { $priceBlock = $catalogCategoryView->getListProductBlock()->getProductItem($product)->getPriceBlock(); \PHPUnit_Framework_Assert::assertEquals(number_format($product->getPrice(), 2, '.', ''), $priceBlock->isOldPriceVisible() ? $priceBlock->getOldPrice() : $priceBlock->getPrice(), 'Product regular price on category page is not correct.'); if ($product->hasData('special_price')) { \PHPUnit_Framework_Assert::assertEquals(number_format($product->getSpecialPrice(), 2, '.', ''), $priceBlock->getSpecialPrice(), 'Product special price on category page is not correct.'); } }
/** * Assert that displayed assigned products on category page equals passed from fixture * * @param Category $category * @param CatalogCategoryView $categoryView * @param BrowserInterface $browser * @return void */ public function processAssert(Category $category, CatalogCategoryView $categoryView, BrowserInterface $browser) { $categoryUrlKey = $category->hasData('url_key') ? strtolower($category->getUrlKey()) : trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-'); $products = $category->getDataFieldConfig('category_products')['source']->getProducts(); $browser->open($_ENV['app_frontend_url'] . $categoryUrlKey . '.html'); foreach ($products as $productFixture) { \PHPUnit_Framework_Assert::assertTrue($categoryView->getListProductBlock()->getProductItem($productFixture)->isVisible(), "Products '{$productFixture->getName()}' not find."); } }
/** * 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 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"); } }
/** * 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.'); }
/** * Verify product price on category view page * * @param CatalogProductBundle $bundle * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(CatalogProductBundle $bundle, CatalogCategoryView $catalogCategoryView) { $priceData = $bundle->getDataFieldConfig('price')['source']->getPreset(); //Price from/to verification $priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName()); $priceLow = $bundle->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice(); \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on category page is not correct.'); if ($bundle->getPriceView() == 'Price Range') { \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on category page is not correct.'); } }
/** * Assert that product is not visible in the assigned category * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @param Category|null $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, Category $category = null) { $categoryName = $category ? $category->getName() : $product->getCategoryIds()[0]; $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); } \PHPUnit_Framework_Assert::assertFalse($isProductVisible, 'Product is exist on category page.'); }
/** * Assert that after applying changes, currency symbol changed on Catalog page * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductSimple $product * @param CurrencySymbolEntity $currencySymbol * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductSimple $product, CurrencySymbolEntity $currencySymbol) { $categoryName = $product->getCategoryIds()[0]; $cmsIndex->open(); $cmsIndex->getCurrencyBlock()->switchCurrency($currencySymbol); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $price = $catalogCategoryView->getListProductBlock()->getProductItem($product)->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 Category page.'); }
/** * Assert that category name is different on different store view. * * @param BrowserInterface $browser * @param CatalogCategoryView $categoryView * @param Category $category * @param Category $initialCategory * @param CmsIndex $cmsIndex * @return void */ public function processAssert(BrowserInterface $browser, CatalogCategoryView $categoryView, Category $category, Category $initialCategory, CmsIndex $cmsIndex) { $cmsIndex->open(); $cmsIndex->getLinksBlock()->waitWelcomeMessage(); $browser->open($_ENV['app_frontend_url'] . $initialCategory->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertEquals($initialCategory->getName(), $categoryView->getTitleBlock()->getTitle(), 'Wrong category name is displayed for default store.'); $store = $category->getDataFieldConfig('store_id')['source']->store->getName(); $cmsIndex->getStoreSwitcherBlock()->selectStoreView($store); $cmsIndex->getLinksBlock()->waitWelcomeMessage(); $browser->open($_ENV['app_frontend_url'] . $initialCategory->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertEquals($category->getName(), $categoryView->getTitleBlock()->getTitle(), 'Wrong category name is displayed for ' . $store); }
/** * Assert currency rate applied on catalog page. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductSimple $product * @param CurrencySymbolEntity $currencySymbol * @param string $basePrice * @param string $convertedPrice * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductSimple $product, CurrencySymbolEntity $currencySymbol, $basePrice, $convertedPrice) { $categoryName = $product->getCategoryIds()[0]; $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $priceBlock = $catalogCategoryView->getListProductBlock()->getProductItem($product)->getPriceBlock(); $actualPrice = $priceBlock->getPrice(''); \PHPUnit_Framework_Assert::assertEquals($basePrice, $actualPrice, 'Wrong price is displayed on Category page.'); $cmsIndex->getCurrencyBlock()->switchCurrency($currencySymbol); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $actualPrice = $priceBlock->getPrice(''); \PHPUnit_Framework_Assert::assertEquals($convertedPrice, $actualPrice, 'Wrong price is displayed on Category page.'); }
/** * Assert that the category is no longer available on the top menu bar * * @param CmsIndex $cmsIndex * @param CatalogCategory $category * @param Browser $browser * @param CatalogCategoryView $categoryView * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategory $category, Browser $browser, CatalogCategoryView $categoryView) { $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($category->getName(), $categoryView->getTitleBlock()->getTitle(), 'Wrong page is displayed.'); if (isset($category->getDataFieldConfig('category_products')['source'])) { $products = $category->getDataFieldConfig('category_products')['source']->getProducts(); foreach ($products as $productFixture) { \PHPUnit_Framework_Assert::assertTrue($categoryView->getListProductBlock()->isProductVisible($productFixture->getName()), "Products '{$productFixture->getName()}' not find."); } } }
/** * Assert product MAP related data on category page. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param InjectableFixture $product * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, InjectableFixture $product) { /** @var CatalogProductSimple $product */ $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $productBlock = $catalogCategoryView->getMsrpListProductBlock()->getProductItem($product); \PHPUnit_Framework_Assert::assertTrue($productBlock->isVisible(), 'Product is invisible on Category page.'); $priceBlock = $productBlock->getPriceBlock(); \PHPUnit_Framework_Assert::assertEquals($product->getMsrp(), $priceBlock->getOldPrice(), 'Displayed on Category page MAP is incorrect.'); \PHPUnit_Framework_Assert::assertFalse($priceBlock->isRegularPriceVisible(), 'Regular price on Category page is visible and not expected.'); $productBlock->openMapBlock(); $mapBlock = $productBlock->getMapBlock(); \PHPUnit_Framework_Assert::assertEquals($product->getMsrp(), $mapBlock->getOldPrice(), 'Displayed on Category page MAP is incorrect.'); \PHPUnit_Framework_Assert::assertEquals($product->getPrice(), $mapBlock->getActualPrice(), 'Displayed on Category page price is incorrect.'); }
/** * Assert that created widget displayed on frontend on Home page and on Advanced Search and * after click on widget link on frontend system redirects you to catalog page. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $categoryView * @param Widget $widget * @param AdminCache $adminCache * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $categoryView, Widget $widget, AdminCache $adminCache) { // Flush cache $adminCache->open(); $adminCache->getActionsBlock()->flushMagentoCache(); $adminCache->getMessagesBlock()->waitSuccessMessage(); $cmsIndex->open(); $widgetText = $widget->getParameters()['anchor_text']; \PHPUnit_Framework_Assert::assertTrue($cmsIndex->getWidgetView()->isWidgetVisible($widget, $widgetText), 'Widget with type catalog category link is absent on Home page.'); $cmsIndex->getWidgetView()->clickToWidget($widget, $widgetText); $title = $categoryView->getTitleBlock()->getTitle(); \PHPUnit_Framework_Assert::assertEquals($widget->getParameters()['entities'][0]->getName(), $title, 'Wrong category title.'); $cmsIndex->getFooterBlock()->openAdvancedSearch(); \PHPUnit_Framework_Assert::assertTrue($cmsIndex->getWidgetView()->isWidgetVisible($widget, $widgetText), 'Widget with type catalog category link is absent on Advanced Search page.'); }
/** * Assert that product is visible in the assigned category * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @param CatalogCategory $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $category) { $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($category->getName()); $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); while (!$isProductVisible && $catalogCategoryView->getToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); } $isInStock = $product->getQuantityAndStockStatus(); if ($product->getVisibility() === 'Search' || isset($isInStock['is_in_stock']) && $isInStock['is_in_stock'] === 'Out of Stock') { $isProductVisible = !$isProductVisible; $this->errorMessage = 'Product found in this category.'; $this->successfulMessage = 'Asserts that the product could not be found in this category.'; } \PHPUnit_Framework_Assert::assertTrue($isProductVisible, $this->errorMessage); }
/** * Assert that product is visible in the assigned category * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @param Category|null $category * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, Category $category = null) { $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); } if ($product->getVisibility() === 'Search' || $this->getStockStatus($product) === 'Out of Stock') { $isProductVisible = !$isProductVisible; $this->errorMessage = 'Product found in this category.'; $this->successfulMessage = 'Asserts that the product could not be found in this category.'; } \PHPUnit_Framework_Assert::assertTrue($isProductVisible, $this->errorMessage); }
/** * Verify product displaying on frontend * * @param FixtureInterface $product * @return array */ protected function isNotDisplayingOnFrontendAssert(FixtureInterface $product) { $errors = []; // Check the product page is not available // TODO fix initialization url for frontend page $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $titleBlock = $this->catalogProductView->getTitleBlock(); if ($titleBlock->getTitle() !== self::NOT_FOUND_MESSAGE) { $errors[] = '- the headline on the page does not match, the text should be -> "' . self::NOT_FOUND_MESSAGE . '".'; } $this->cmsIndex->open(); $this->cmsIndex->getSearchBlock()->search($product->getSku()); if ($this->catalogSearchResult->getListProductBlock()->isProductVisible($product->getName())) { $errors[] = '- successful product search.'; } $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $this->category->getName(); $this->cmsIndex->open(); $this->cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); while (!$isProductVisible && $this->catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); } if ($isProductVisible) { $errors[] = "- product with name '{$product->getName()}' is found in this category."; } return $errors; }
/** * Assert category display settings * * @param Category $category * @param array $categoryData * @return void */ protected function assertDisplaySetting(Category $category, array $categoryData) { if (isset($categoryData['landing_page']) && isset($categoryData['display_mode']) && in_array($categoryData['display_mode'], $this->visibleCmsBlockMode)) { /** @var LandingPage $sourceLandingPage */ $sourceLandingPage = $category->getDataFieldConfig('landing_page')['source']; $fixtureContent = $sourceLandingPage->getCmsBlock()->getContent(); $pageContent = $this->categoryViewPage->getViewBlock()->getContent(); \PHPUnit_Framework_Assert::assertEquals($fixtureContent, $pageContent, 'Wrong category landing page content.' . "\nExpected: " . $fixtureContent . "\nActual: " . $pageContent); } if (isset($categoryData['default_sort_by'])) { $sortBy = strtolower($categoryData['default_sort_by']); $sortType = $this->categoryViewPage->getTopToolbar()->getSelectSortType(); \PHPUnit_Framework_Assert::assertEquals($sortBy, $sortType, 'Wrong sorting type.' . "\nExpected: " . $sortBy . "\nActual: " . $sortType); } if (isset($categoryData['available_sort_by'])) { $availableSortType = array_filter($categoryData['available_sort_by'], function (&$value) { return $value !== '-' && ucfirst($value); }); if ($availableSortType) { $availableSortType = array_values($availableSortType); $availableSortTypeOnPage = $this->categoryViewPage->getTopToolbar()->getSortType(); \PHPUnit_Framework_Assert::assertEquals($availableSortType, $availableSortTypeOnPage, 'Wrong available sorting type.' . "\nExpected: " . implode(PHP_EOL, $availableSortType) . "\nActual: " . implode(PHP_EOL, $availableSortTypeOnPage)); } } }
/** * Verify category Display Settings data: * # default_sort_by * # available_sort_by * * @param array $categoryData * @return array */ protected function verifyDisplaySettings(array $categoryData) { $errorMessage = []; //TODO: verify display_mode if (isset($categoryData['default_sort_by'])) { $expected = $categoryData['default_sort_by']; $actual = $this->categoryViewPage->getTopToolbar()->getSelectSortType(); if ($expected != $actual) { $errorMessage[] = 'Wrong sorting type.' . "\nExpected: " . $expected . "\nActual: " . $actual; } } if (isset($categoryData['available_sort_by'])) { $availableSortType = array_filter($categoryData['available_sort_by'], function (&$value) { return $value !== '-' && ucfirst($value); }); if ($availableSortType) { $expected = array_values($availableSortType); $actual = $this->categoryViewPage->getTopToolbar()->getSortType(); if ($expected != $actual) { $errorMessage[] = 'Wrong available sorting type.' . "\nExpected: " . implode(PHP_EOL, $expected) . "\nActual: " . implode(PHP_EOL, $actual); } } } // TODO: verify Layered Navigation Price Step return $errorMessage; }
/** * Verify product price on category view page. * * @param FixtureInterface $bundle * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(FixtureInterface $bundle, CatalogCategoryView $catalogCategoryView) { /** @var BundleProduct $bundle */ $priceData = $bundle->getDataFieldConfig('price')['source']->getPreset(); //Price from/to verification $priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName()); if ($bundle->hasData('special_price') || $bundle->hasData('group_price')) { $priceLow = $priceBlock->getFinalPrice(); } else { $priceLow = $bundle->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice(); } \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on category page is not correct.'); if ($bundle->getPriceView() == 'Price Range') { \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on category page is not correct.'); } }
/** * "Add to cart" button is display on Product page * * @return void */ protected function addToCardPresentOnProduct() { $this->cmsIndex->open(); $this->cmsIndex->getTopmenu()->selectCategoryByName($this->product->getCategoryIds()[0]); $this->catalogCategoryView->getListProductBlock()->openProductViewPage($this->product->getName()); \PHPUnit_Framework_Assert::assertTrue($this->catalogProductView->getViewBlock()->checkAddToCardButton(), "Button 'Add to Card' is absent on Product page."); }
/** * Assert that Catalog Price Rule is applied for product(s) in Catalog * according to Priority(Priority/Stop Further Rules Processing). * * @param CmsIndex $cmsIndexPage * @param CatalogCategoryView $catalogCategoryViewPage * @param array $products * @param array $productPrice * @param Customer $customer * @return void */ public function processAssert(CmsIndex $cmsIndexPage, CatalogCategoryView $catalogCategoryViewPage, array $products, array $productPrice, Customer $customer = null) { if ($customer !== null) { $this->objectManager->create('\\Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); } $cmsIndexPage->open(); foreach ($products as $key => $product) { $categoryName = $product->getCategoryIds()[0]; $cmsIndexPage->getTopmenu()->selectCategoryByName($categoryName); $priceBlock = $catalogCategoryViewPage->getListProductBlock()->getProductItem($product)->getPriceBlock(); $actualPrice['regular'] = (double) $priceBlock->getOldPrice(); $actualPrice['special'] = (double) $priceBlock->getSpecialPrice(); $actualPrice['discount_amount'] = $actualPrice['regular'] - $actualPrice['special']; $diff = $this->verifyData($actualPrice, $productPrice[$key]); \PHPUnit_Framework_Assert::assertTrue(empty($diff), implode(' ', $diff)); } }