/** * 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 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 Catalog Price Rule is applied for product(s) in Catalog * according to Priority(Priority/Stop Further Rules Processing). * * @param InjectableFixture $product * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param array $prices * @return void */ public function processAssert(InjectableFixture $product, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, array $prices) { $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($product->getCategoryIds()[0]); $formPrices = $this->getFormPrices($product, $catalogCategoryView); $fixturePrices = $this->prepareFixturePrices($prices); $diff = $this->verifyData($fixturePrices, $formPrices); \PHPUnit_Framework_Assert::assertEmpty($diff, $diff . "\n On: " . date('l jS \\of F Y h:i:s A')); }
/** * Assert that Catalog Price Rule is applied for product(s) in Shopping Cart * according to Priority(Priority/Stop Further Rules Processing). * * @param InjectableFixture $product * @param CatalogProductView $pageCatalogProductView * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CheckoutCart $pageCheckoutCart * @param array $prices * @return void */ public function processAssert(InjectableFixture $product, CatalogProductView $pageCatalogProductView, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CheckoutCart $pageCheckoutCart, array $prices) { $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($product->getCategoryIds()[0]); $catalogCategoryView->getListProductBlock()->openProductViewPage($product->getName()); $pageCatalogProductView->getViewBlock()->addToCart($product); $actualGrandTotal = $pageCheckoutCart->getCartBlock()->getCartItem($product)->getCartItemTypePrice('price'); \PHPUnit_Framework_Assert::assertEquals($prices['grand_total'], $actualGrandTotal); }
/** * Get prices on category page. * * @return array */ protected function getCategoryPrice() { $prices = []; $this->cmsIndex->open(); $this->cmsIndex->getTopmenu()->selectCategory($this->product->getCategoryIds()[0]); $priceBlock = $this->catalogCategoryView->getWeeeListProductBlock()->getProductItem($this->product)->getPriceBlock(); foreach ($this->expectedPrices['category'] as $key => $type) { $prices[$key] = $this->getPrice($priceBlock, $key); } return $prices; }
/** * 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 Catalog Price Rule is applied & it impacts on product's discount price on Product page. * * @param InjectableFixture $product * @param CatalogProductView $pageCatalogProductView * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param array $prices * @return void */ public function processAssert(InjectableFixture $product, CatalogProductView $pageCatalogProductView, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, array $prices) { $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($product->getCategoryIds()[0]); $catalogCategoryView->getListProductBlock()->openProductViewPage($product->getName()); $productPriceBlock = $pageCatalogProductView->getViewBlock()->getPriceBlock(); $actualPrices['regular'] = $productPriceBlock->getRegularPrice(); $actualPrices['special'] = $productPriceBlock->getSpecialPrice(); $actualPrices['discount_amount'] = number_format($actualPrices['regular'] - $actualPrices['special'], 2); $diff = $this->verifyData($actualPrices, $prices); \PHPUnit_Framework_Assert::assertEmpty($diff, $diff); }
/** * Assert that "Add to cart" button is not display on page. * * @param InjectableFixture $product * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param Category $category [optional] * * @return void */ public function processAssert(InjectableFixture $product, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, Category $category = null) { $cmsIndex->open(); $categoryName = $category === null ? $product->getCategoryIds()[0] : $category->getName(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); } \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.'); \PHPUnit_Framework_Assert::assertFalse($catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisibleAddToCardButton(), "Button 'Add to Card' is present on Category page."); $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); \PHPUnit_Framework_Assert::assertFalse($catalogProductView->getViewBlock()->isVisibleAddToCardButton(), "Button 'Add to Card' is present on Product page."); }
/** * 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 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); }
/** * Assert product MAP related data on product view page. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param InjectableFixture $product * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, InjectableFixture $product) { /** @var CatalogProductSimple $product */ $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); $viewBlock = $catalogProductView->getMsrpViewBlock(); $priceBlock = $viewBlock->getPriceBlock(); \PHPUnit_Framework_Assert::assertEquals($product->getMsrp(), $priceBlock->getOldPrice(), 'Displayed on Product view page MAP is incorrect'); \PHPUnit_Framework_Assert::assertFalse($priceBlock->isRegularPriceVisible(), 'Regular price on Product view page is visible and not expected.'); $viewBlock->openMapBlock(); $mapBlock = $viewBlock->getMapBlock(); \PHPUnit_Framework_Assert::assertContains($product->getMsrp(), $mapBlock->getOldPrice(), 'Displayed on Product view page MAP is incorrect.'); $priceData = $product->getDataFieldConfig('price')['source']->getPriceData(); $price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice(); \PHPUnit_Framework_Assert::assertEquals($price, $mapBlock->getActualPrice(), 'Displayed on Product view page price is incorrect.'); }
/** * 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 product MAP related data in Shopping Cart. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param InjectableFixture $product * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, InjectableFixture $product) { /** @var CatalogProductSimple $product */ $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); if ($product->hasData('checkout_data')) { $catalogProductView->getViewBlock()->addToCart($product); } else { $catalogProductView->getMsrpViewBlock()->openMapBlock(); $catalogProductView->getMsrpViewBlock()->getMapBlock()->addToCart(); } $catalogProductView->getMessagesBlock()->waitSuccessMessage(); $checkoutCart->open(); $productPrice = $product->hasData('checkout_data') ? $product->getCheckoutData()['cartItem']['price'] : $product->getPrice(); $unitPrice = $checkoutCart->getCartBlock()->getCartItem($product)->getPrice(); \PHPUnit_Framework_Assert::assertEquals($productPrice, $unitPrice, 'Incorrect unit price is displayed in Cart'); }
/** * Assert that specified prices are actual on category, product and cart pages. * * @param InjectableFixture $product * @param array $prices * @param int $qty * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param FixtureFactory $fixtureFactory * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function processAssert(InjectableFixture $product, array $prices, $qty, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, FixtureFactory $fixtureFactory) { $this->cmsIndex = $cmsIndex; $this->catalogCategoryView = $catalogCategoryView; $this->catalogProductView = $catalogProductView; $this->checkoutCart = $checkoutCart; $actualPrices = []; //Assertion steps $productCategory = $product->getCategoryIds()[0]; $this->openCategory($productCategory); $actualPrices = $this->getCategoryPrices($product, $actualPrices); $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); $catalogProductView->getViewBlock()->fillOptions($product); $actualPrices = $this->getProductPagePrices($actualPrices); $catalogProductView->getViewBlock()->clickAddToCart(); $catalogProductView->getMessagesBlock()->waitSuccessMessage(); $actualPrices = $this->getCartPrices($product, $actualPrices); $actualPrices = $this->getTotals($actualPrices); //Prices verification $message = 'Prices from dataset should be equal to prices on frontend'; \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); }
/** * 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 * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, InjectableFixture $product, CatalogProductAttribute $attribute, CmsIndex $cmsIndex) { $cmsIndex->open()->getTopmenu()->selectCategory($product->getCategoryIds()[0]); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array(strtoupper($label), $catalogCategoryView->getLayeredNavigationBlock()->getFilters()), 'Attribute is absent in layered navigation on category page.'); }
/** * Assert that specified prices are actual on category, product and cart pages. * * @param InjectableFixture $product * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param Address $address * @param Cache $cachePage * @param array $prices * @param array $arguments * @return void */ public function processAssert(InjectableFixture $product, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, Address $address, Cache $cachePage, array $prices, array $arguments) { $cachePage->open()->getPageActions()->flushCacheStorage(); $this->cmsIndex = $cmsIndex; $this->catalogCategoryView = $catalogCategoryView; $this->catalogProductView = $catalogProductView; $this->checkoutCart = $checkoutCart; $prices = $this->prepareVerifyFields($prices); //Assertion steps $productName = $product->getName(); $this->cmsIndex->open()->getTopmenu()->selectCategory($product->getCategoryIds()[0]); $actualPrices = $this->getCategoryPrices($product); $catalogCategoryView->getListProductBlock()->openProductViewPage($productName); $this->fillCheckoutData($product); $actualPrices = array_merge($actualPrices, $this->getProductPagePrices()); $catalogProductView->getViewBlock()->clickAddToCart(); if (isset($arguments['shipping'])) { $this->fillEstimateBlock($address, $arguments['shipping']); } $actualPrices = array_merge($actualPrices, $this->getCartPrices($product), $this->getTotals($actualPrices)); //Prices verification $error = $this->verifyData($prices, $actualPrices); \PHPUnit_Framework_Assert::assertTrue(empty($error), $error); }
/** * Assert that specified prices are actual on category, product and cart pages. * * @param InjectableFixture $product * @param array $prices * @param int $qty * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param FixtureFactory $fixtureFactory * @return void */ public function processAssert(InjectableFixture $product, array $prices, $qty, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, FixtureFactory $fixtureFactory) { $this->cmsIndex = $cmsIndex; $this->catalogCategoryView = $catalogCategoryView; $this->catalogProductView = $catalogProductView; $this->checkoutCart = $checkoutCart; //Preconditions $address = $fixtureFactory->createByCode('address', ['dataset' => 'US_address_NY']); $shipping = ['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed']; $actualPrices = []; //Assertion steps $productCategory = $product->getCategoryIds()[0]; $this->openCategory($productCategory); $actualPrices = $this->getCategoryPrices($product, $actualPrices); $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); $catalogProductView->getViewBlock()->fillOptions($product); $actualPrices = $this->getProductPagePrices($actualPrices); $catalogProductView->getViewBlock()->setQtyAndClickAddToCart($qty); $catalogProductView->getMessagesBlock()->waitSuccessMessage(); $this->checkoutCart->open(); $this->fillEstimateBlock($address, $shipping); $actualPrices = $this->getCartPrices($product, $actualPrices); $actualPrices = $this->getTotals($actualPrices); //Prices verification $message = 'Prices from dataset should be equal to prices on frontend.'; \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); }