/** * Assert that products' MAP has been applied before checkout. * * @param CatalogCategory $category * @param Customer $customer * @param Address $address * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param CatalogProductView $catalogProductView * @param CheckoutCart $cart * @param CheckoutOnepage $checkoutOnePage * @param array $products * @return void */ public function processAssert(CatalogCategory $category, Customer $customer, Address $address, CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, CatalogProductView $catalogProductView, CheckoutCart $cart, CheckoutOnepage $checkoutOnePage, array $products) { for ($i = 0; $i < count($products); $i++) { $cart->getCartBlock()->clearShoppingCart(); $productName = $products[$i]->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($category->getName()); // Check that price is not present on category page. $listProductBlock = $catalogCategoryView->getListProductBlock(); $productPriceBlock = $listProductBlock->getProductPriceBlock($productName); $productPriceBlock->clickForPrice(); \PHPUnit_Framework_Assert::assertFalse($productPriceBlock->getMapBlock()->isPriceVisible(), 'Price is present in MSRP dialog on category page.'); // Check that price is not present on product page. $listProductBlock->openProductViewPage($productName); \PHPUnit_Framework_Assert::assertFalse($catalogProductView->getViewBlock()->getPriceBlock()->isRegularPriceVisible(), 'Price is present in View block on product page.'); // Check that price is not present on cart. $catalogProductView->getViewBlock()->addToCart($products[$i]); \PHPUnit_Framework_Assert::assertTrue($cart->getCartBlock()->getCartItem($products[$i])->isMsrpVisible(), "MSRP link is not visible in cart."); // Check that price is present on review block in onepage checkout page. $cart->getCartBlock()->getProceedToCheckoutBlock()->proceedToCheckout(); $checkoutMethodBlock = $checkoutOnePage->getLoginBlock(); $billingBlock = $checkoutOnePage->getBillingBlock(); $paymentMethodBlock = $checkoutOnePage->getPaymentMethodsBlock(); $shippingBlock = $checkoutOnePage->getShippingMethodBlock(); $checkoutMethodBlock->guestCheckout(); $checkoutMethodBlock->clickContinue(); $billingBlock->fillBilling($address, $customer); $billingBlock->clickContinue(); $shippingBlock->selectShippingMethod(['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed']); $shippingBlock->clickContinue(); $paymentMethodBlock->selectPaymentMethod(['method' => 'checkmo']); $paymentMethodBlock->clickContinue(); \PHPUnit_Framework_Assert::assertEquals(number_format($products[$i]->getPrice(), 2), $checkoutOnePage->getReviewBlock()->getTotalBlock()->getData('subtotal'), "Subtotal in checkout one page for {$productName} is not equal to expected."); } }
/** * Assert that apache redirect works by opening category page and asserting index.php in its url. * * @param CatalogCategory $category * @param CmsIndex $homePage * @param BrowserInterface $browser */ public function processAssert(CatalogCategory $category, CmsIndex $homePage, BrowserInterface $browser) { $category->persist(); $homePage->open(); $homePage->getTopmenu()->selectCategory($category->getName()); \PHPUnit_Framework_Assert::assertTrue(strpos($browser->getUrl(), 'index.php') === false, 'Apache redirect for category does not work.'); }
/** * Assert that Wishlist can't be find by another Customer (or guest) via "Wishlist Search". * * @param CustomerAccountLogout $customerAccountLogout * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param SearchResult $searchResult * @param CatalogCategory $category * @param Customer $customer * @param Wishlist $wishlist * @return void */ public function processAssert(CustomerAccountLogout $customerAccountLogout, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, SearchResult $searchResult, CatalogCategory $category, Customer $customer, Wishlist $wishlist) { $customerAccountLogout->open(); $cmsIndex->open()->getTopmenu()->selectCategory($category->getName()); $catalogCategoryView->getWishlistSearchBlock()->searchByCustomer($customer); \PHPUnit_Framework_Assert::assertFalse($searchResult->getWishlistSearchResultBlock()->isWishlistVisibleInGrid($wishlist), "Multiple wishlist is visible on wishlist search result page."); }
/** * Assert that filtered product is present on category page by attribute and another products are absent. * * @param CatalogCategoryView $catalogCategoryView * @param ProcessList $processList * @param Browser $browser * @param CatalogCategory $category * @param InjectableFixture[] $products * @param string $searchProductsIndexes * @param string $filterLink * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, ProcessList $processList, Browser $browser, CatalogCategory $category, array $products, $searchProductsIndexes, $filterLink) { $processList->open()->getIndexManagementGrid()->massactionForAll('Reindex Data'); $browser->open($_ENV['app_frontend_url'] . strtolower($category->getUrlKey()) . '.html'); $filter = $this->prepareFilter($products[$searchProductsIndexes], $filterLink); $catalogCategoryView->getLayeredNavigationBlock()->selectAttribute($filter); $this->verify($catalogCategoryView, $products, $searchProductsIndexes); }
/** * 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), "Products '{$productFixture->getName()}' is not find."); } }
/** * Delete category. * * @param CatalogCategory $category * @return void */ public function test(CatalogCategory $category) { // Preconditions: $category->persist(); // Steps: $this->catalogCategoryIndex->open(); $this->catalogCategoryIndex->getTreeCategories()->selectCategory($category); $this->catalogCategoryIndex->getFormPageActions()->deleteAndAcceptAlert(); }
/** * Assert that displayed category data on edit page(backend) equals passed from fixture. * * @param CatalogCategory $category * @param CatalogCategoryIndex $catalogCategoryIndex * @return void */ public function processAssert(CatalogCategory $category, CatalogCategoryIndex $catalogCategoryIndex) { $data = $category->getData(); $catalogCategoryIndex->open(); $catalogCategoryIndex->getTreeCategories()->selectCategory($category); $dataForm = $catalogCategoryIndex->getCategoryForm()->getDataCategory($category); $error = $this->verifyData($data, $dataForm); \PHPUnit_Framework_Assert::assertEmpty($error, $error); }
/** * Assert that product is absent in the category page. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param InjectableFixture $product * @param CatalogCategory $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, InjectableFixture $product, CatalogCategory $category) { $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($category->getName()); $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); } \PHPUnit_Framework_Assert::assertFalse($isProductVisible, 'Product is present on category page.'); }
/** * Assert that sitemap.xml file contains correct content according to dataset: * - product url * - category url * - CMS page url * * @param CatalogProductSimple $product * @param CatalogCategory $category * @param CmsPage $cmsPage * @param Sitemap $sitemap * @param SitemapIndex $sitemapIndex * @return void */ public function processAssert(CatalogProductSimple $product, CatalogCategory $category, CmsPage $cmsPage, Sitemap $sitemap, SitemapIndex $sitemapIndex) { $sitemapIndex->open()->getSitemapGrid()->sortGridByField('sitemap_id'); $filter = ['sitemap_filename' => $sitemap->getSitemapFilename(), 'sitemap_path' => $sitemap->getSitemapPath()]; $sitemapIndex->getSitemapGrid()->search($filter); $content = file_get_contents($sitemapIndex->getSitemapGrid()->getLinkForGoogle()); $frontendUrl = str_replace('index.php/', '', $_ENV['app_frontend_url']); $urls = [$frontendUrl . $product->getUrlKey() . '.html', $frontendUrl . $category->getUrlKey() . '.html', $frontendUrl . $cmsPage->getIdentifier()]; \PHPUnit_Framework_Assert::assertTrue($this->checkContent($content, $urls), "File '{$sitemap->getSitemapFilename()}' does not contains correct content."); }
/** * Assert that out of stock product is visible in the assigned category. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param InjectableFixture $product * @param CatalogCategory|null $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, InjectableFixture $product, CatalogCategory $category = null) { $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); } \PHPUnit_Framework_Assert::assertTrue($isProductVisible, "Product is absent on category page."); }
/** * Assert that products are absent in category frontend page. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param CatalogCategory $category * @param array $unassignedProducts * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, CatalogCategory $category, array $unassignedProducts) { $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($category->getName()); foreach ($unassignedProducts as $product) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); } \PHPUnit_Framework_Assert::assertFalse($isProductVisible, "Product {$product->getName()} is present in category page."); } }
/** * Assert that created Order By Sku widget displayed on frontend in Catalog. * * @param CatalogCategory $category * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param Widget $widget * @param Cache $adminCache * @return void */ public function processAssert(CatalogCategory $category, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, Widget $widget, Cache $adminCache) { $category->persist(); // Flush cache $adminCache->open(); $adminCache->getPageActions()->flushCacheStorage(); $adminCache->getMessagesBlock()->waitSuccessMessage(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($category->getName()); $errors = $catalogCategoryView->getWidgetView()->checkWidget($widget, "Order by SKU"); \PHPUnit_Framework_Assert::assertEmpty($errors, $errors); }
/** * Assert that product products' MAP has been applied on gesture. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param CatalogCategory $category * @param array $products * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, CatalogCategory $category, array $products) { foreach ($products as $product) { $productName = $product->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($category->getName()); $listProductBlock = $catalogCategoryView->getListProductBlock(); // Check that price is present in MAP popup. $productPriceBlock = $listProductBlock->getProductPriceBlock($productName); $productPriceBlock->clickForPrice(); $msrpPopupBlock = $productPriceBlock->getMapBlock(); $map = $msrpPopupBlock->isVisible() ? $msrpPopupBlock->getMap() : null; \PHPUnit_Framework_Assert::assertEquals(number_format($product->getPrice(), 2), $map, "MAP of {$productName} product is not visible or not equal to product price."); } }
/** * @constructor * @param FixtureFactory $fixtureFactory * @param array $params * @param array|int $data */ public function __construct(FixtureFactory $fixtureFactory, array $params, $data = []) { $this->params = $params; if (isset($data['dataSet'])) { $this->parentCategory = $fixtureFactory->createByCode('catalogCategory', ['dataSet' => $data['dataSet']]); if (!$this->parentCategory->hasData('id')) { $this->parentCategory->persist(); } $this->data = $this->parentCategory->getId(); } elseif (isset($data['data']) && isset($data['parent_category'])) { $this->data = $data['data']; $this->parentCategory = $data['parent_category']; } else { $this->data = $data; } }
/** * Verify product displaying on frontend. * * @param InjectableFixture $product * @return array */ protected function isNotDisplayingOnFrontendAssert(InjectableFixture $product) { $errors = []; //Check that product is not available by url $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); if ($this->catalogProductView->getViewBlock()->isVisible()) { $errors[] = '- product view block is visible in product page.'; } //Check that product can't be found $this->cmsIndex->open()->getSearchBlock()->search($product->getSku()); if ($this->catalogSearchResult->getListProductBlock()->isProductVisible($product)) { $errors[] = '- successful product search.'; } //Check that product is not available in category page $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $this->category->getName(); $this->cmsIndex->open()->getTopmenu()->selectCategory($categoryName); $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product); $bottomToolBar = $this->catalogCategoryView->getBottomToolbar(); while (!$isProductVisible && $bottomToolBar->nextPage()) { $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product); } if ($isProductVisible) { $errors[] = "- product with name '{$product->getName()}' is found in this category."; } return $errors; }
/** * Assert that product is visible in the assigned category. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param InjectableFixture $product * @param CatalogCategory|null $category * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, InjectableFixture $product, CatalogCategory $category = null) { $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); } 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); }
/** * Prepare data. * * @param CatalogCategory $category * @param CatalogProduct $productGrid * @param CatalogProductEdit $editProductPage * @param FixtureFactory $fixtureFactory * @return void */ public function __prepare(CatalogCategory $category, CatalogProduct $productGrid, CatalogProductEdit $editProductPage, FixtureFactory $fixtureFactory) { $this->category = $category; $this->category->persist(); $this->productGrid = $productGrid; $this->editProductPage = $editProductPage; $this->fixtureFactory = $fixtureFactory; }
/** * Checking the product in the page of its price. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param InjectableFixture $product * @param CatalogCategory $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, InjectableFixture $product, CatalogCategory $category) { // Open category view page and check visible product $categoryName = $category->getName(); if ($product->hasData('category_ids')) { $categoryIds = $product->getCategoryIds(); $categoryName = is_array($categoryIds) ? reset($categoryIds) : $categoryName; } $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product); } \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.'); //Process price asserts $this->assertPrice($product, $catalogCategoryView); }
/** * 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.'); if (isset($categoryData['name'])) { \PHPUnit_Framework_Assert::assertEquals(strtoupper($categoryData['name']), $categoryView->getTitleBlock()->getTitle(), 'Wrong page title.'); } if (isset($categoryData['description'])) { \PHPUnit_Framework_Assert::assertEquals($categoryData['description'], $categoryView->getViewBlock()->getDescription(), 'Wrong category 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.'); } }
/** * Assert that product products' MAP has been applied in cart. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param CatalogCategory $category * @param CatalogProductView $catalogProductView * @param CheckoutCart $cart * @param array $products * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, CatalogCategory $category, CatalogProductView $catalogProductView, CheckoutCart $cart, array $products) { foreach ($products as $product) { $cart->getCartBlock()->clearShoppingCart(); $productName = $product->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($category->getName()); $listProductBlock = $catalogCategoryView->getListProductBlock(); // Check that price is not present on category page. $productPriceBlock = $listProductBlock->getProductPriceBlock($productName); $productPriceBlock->clickForPrice(); \PHPUnit_Framework_Assert::assertFalse($productPriceBlock->getMapBlock()->isPriceVisible(), 'Price is present in MSRP dialog on category page.'); // Check that price is not present on product page. $listProductBlock->openProductViewPage($productName); \PHPUnit_Framework_Assert::assertFalse($catalogProductView->getViewBlock()->getPriceBlock()->isRegularPriceVisible(), 'Price is present in View block on product page.'); // Check that price is present in cart. $catalogProductView->getViewBlock()->addToCart($product); \PHPUnit_Framework_Assert::assertEquals(number_format($product->getPrice(), 2), $cart->getCartBlock()->getCartItem($product)->getCartItemTypePrice('price'), "MAP of {$productName} product in cart is not equal to product price."); } }
/** * Get data of Category information. * * @param CatalogCategory $category * @return array */ public function getDataCategory(CatalogCategory $category) { return $category->hasData() ? parent::getData($category) : parent::getData(); }
/** * Assert that category url rewrite not in grid. * * @param UrlRewriteIndex $urlRewriteIndex * @param CatalogCategory $category * @return void */ public function processAssert(UrlRewriteIndex $urlRewriteIndex, CatalogCategory $category) { $urlRewriteIndex->open(); $filter = ['request_path' => $category->getUrlKey()]; \PHPUnit_Framework_Assert::assertFalse($urlRewriteIndex->getUrlRedirectGrid()->isRowVisible($filter), "URL Rewrite with request path '{$filter['request_path']}' is present in grid."); }
/** * Prepare configuration and create customer. * * @param Customer $customer * @param CatalogCategory $category * @return array */ public function __prepare(Customer $customer, CatalogCategory $category) { $customer->persist(); $category->persist(); return ['customer' => $customer, 'category' => $category]; }
/** * Prepare category path. * * @param CatalogCategory $category * @return array */ protected function prepareFullCategoryPath(CatalogCategory $category) { $path = []; $parentCategory = $category->getDataFieldConfig('parent_id')['source']->getParentCategory(); if ($parentCategory != null) { $path = $this->prepareFullCategoryPath($parentCategory); } return array_filter(array_merge($path, [$category->getPath(), $category->getName()])); }
/** * Prepare data. * * @param CatalogCategory $category * @return array */ public function __prepare(CatalogCategory $category) { $category->persist(); return ['category' => $category]; }
/** * Injection data. * * @param FixtureFactory $fixtureFactory * @return array */ public function __inject(FixtureFactory $fixtureFactory) { $this->category = $fixtureFactory->createByCode('catalogCategory', ['dataSet' => 'anchor_category']); $this->category->persist(); return ['category' => $this->category]; }
/** * Assert that old category URL lead to appropriate Category in frontend. * * @param CatalogCategory $category * @param Browser $browser * @param CatalogCategory $initialCategory * @param CatalogCategoryView $catalogCategoryView * @return void */ public function processAssert(CatalogCategory $category, Browser $browser, CatalogCategory $initialCategory, CatalogCategoryView $catalogCategoryView) { $browser->open(str_replace('index', 'cron', $_ENV['app_frontend_url'])); $browser->open($_ENV['app_frontend_url'] . $initialCategory->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertEquals($catalogCategoryView->getTitleBlock()->getTitle(), strtoupper($category->getName()), 'Old category URL does not lead to appropriate Category in frontend.'); }
/** * Prepare assigned products for category. * * @param CatalogCategory $category * @return string */ protected function prepareCategoryProducts(CatalogCategory $category) { $products = $category->getDataFieldConfig('category_products')['source']->getProducts(); $productIds = []; foreach ($products as $product) { $productIds[] = $product->getId(); } return implode('=&', $productIds); }
/** * Assert category is not present on frontend. * * @param Browser $browser * @param CatalogCategoryView $categoryView * @param CatalogCategory $category * @return void */ public function processAssert(Browser $browser, CatalogCategoryView $categoryView, CatalogCategory $category) { $browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertContains(self::NOT_FOUND_MESSAGE, $categoryView->getViewBlock()->getText(), 'Category is present on frontend.'); }
/** * Get category products. * * @param CatalogCategory $category * @return array */ protected function getCategoryProducts(CatalogCategory $category) { return $category->hasData('category_products') ? $category->getDataFieldConfig('category_products')['source']->getProducts() : []; }