/** * Assert that product is not visible in the assigned category * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @param CatalogCategory|null $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $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 product can be searched via Quick Search using searchable product attributes (Search by SKU) * * @param CatalogsearchResult $catalogSearchResult * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @return void */ public function processAssert(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, FixtureInterface $product) { $cmsIndex->open(); $cmsIndex->getSearchBlock()->search($product->getSku()); $isInStock = $product->getQuantityAndStockStatus(); if ($product->getVisibility() === 'Catalog' || isset($isInStock['is_in_stock']) && $isInStock['is_in_stock'] === 'Out of Stock') { $isVisible = !$catalogSearchResult->getListProductBlock()->isProductVisible($product->getName()); $this->errorMessage = 'Product successfully found by SKU.'; $this->successfulMessage = 'The product has not been found by SKU.'; } else { $isVisible = $catalogSearchResult->getListProductBlock()->isProductVisible($product->getName()); } \PHPUnit_Framework_Assert::assertTrue($isVisible, $this->errorMessage); }
/** * Assert prices on the shopping cart * * @param FixtureInterface $product * @param CheckoutCart $checkoutCart * @return void */ protected function assertOnShoppingCart(FixtureInterface $product, CheckoutCart $checkoutCart) { $cartBlock = $checkoutCart->getCartBlock(); $productName = $product->getName(); $productOptions = $product->getCustomOptions(); $priceComparing = $product->getPrice(); if ($groupPrice = $product->getGroupPrice()) { $groupPrice = reset($groupPrice); $priceComparing = $groupPrice['price']; } if ($specialPrice = $product->getSpecialPrice()) { $priceComparing = $specialPrice; } if (!empty($productOptions)) { $productOption = reset($productOptions); $optionsData = reset($productOption['options']); $optionName = $cartBlock->getCartItemOptionsNameByProductName($productName); $optionValue = $cartBlock->getCartItemOptionsValueByProductName($productName); \PHPUnit_Framework_Assert::assertTrue(trim($optionName) === $productOption['title'] && trim($optionValue) === $optionsData['title'], 'In the cart wrong option product.'); if ($optionsData['price_type'] === 'Percent') { $priceComparing = $priceComparing * (1 + $optionsData['price'] / 100); } else { $priceComparing += $optionsData['price']; } } $price = $checkoutCart->getCartBlock()->getProductPriceByName($productName); \PHPUnit_Framework_Assert::assertEquals(number_format($priceComparing, 2), $price, 'Product price in shopping cart is not correct.'); }
/** * Assert that product is visible in the assigned category * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @param CatalogCategory|null $category * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $category = null) { $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName()); } 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 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 duplicated product is found by sku and has correct product type, product template, * product status disabled and out of stock * * @param FixtureInterface $product * @param CatalogProductIndex $productGrid * @return void */ public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid) { $config = $product->getDataConfig(); $filter = ['name' => $product->getName(), 'visibility' => $product->getVisibility(), 'status' => 'Disabled', 'sku' => $product->getSku() . '-1', 'type' => ucfirst($config['create_url_params']['type']) . ' Product', 'price_to' => number_format($product->getPrice(), 2)]; $productGrid->open()->getProductGrid()->search($filter); $filter['price_to'] = '$' . $filter['price_to']; \PHPUnit_Framework_Assert::assertTrue($productGrid->getProductGrid()->isRowVisible($filter, false), 'Product duplicate is absent in Products grid.'); }
/** * Assert that product can be searched via Quick Search using searchable product attributes (Search by SKU) * * @param CatalogsearchResult $catalogSearchResult * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, FixtureInterface $product) { $cmsIndex->open(); $sku = $product->hasData('sku') !== false ? $product->getSku() : $product->getName(); $cmsIndex->getSearchBlock()->search($sku); $quantityAndStockStatus = $product->getQuantityAndStockStatus(); $stockStatus = isset($quantityAndStockStatus['is_in_stock']) ? $quantityAndStockStatus['is_in_stock'] : null; $isVisible = $catalogSearchResult->getListProductBlock()->isProductVisible($product->getName()); while (!$isVisible && $catalogSearchResult->getBottomToolbar()->nextPage()) { $isVisible = $catalogSearchResult->getListProductBlock()->isProductVisible($product->getName()); } if ($product->getVisibility() === 'Catalog' || $stockStatus === 'Out of Stock') { $isVisible = !$isVisible; list($this->errorMessage, $this->successfulMessage) = [$this->successfulMessage, $this->errorMessage]; } \PHPUnit_Framework_Assert::assertTrue($isVisible, $this->errorMessage); }
/** * Prepare array for assert * * @param CatalogProductView $catalogProductView * @return array */ protected function prepareData(CatalogProductView $catalogProductView) { $viewBlock = $catalogProductView->getViewBlock(); $price = $viewBlock->getProductPriceBlock()->getPrice(); $data = ['onPage' => ['name' => $viewBlock->getProductName(), 'sku' => $viewBlock->getProductSku()], 'fixture' => ['name' => $this->product->getName(), 'sku' => $this->product->getSku()]]; list($priceOnPage, $priceFixture) = $this->preparePrice($price); $data['onPage'] += $priceOnPage; $data['fixture'] += $priceFixture; if ($productShortDescription = $this->product->getShortDescription()) { $data['fixture']['short_description'] = $productShortDescription; $data['onPage']['short_description'] = $viewBlock->getProductShortDescription(); } if ($productDescription = $this->product->getDescription()) { $data['fixture']['description'] = $productDescription; $data['onPage']['description'] = $viewBlock->getProductDescription(); } return $data; }
/** * Assert prices on the product view page * * @param CatalogProductView $catalogProductView * @return void */ protected function assertOnProductView(CatalogProductView $catalogProductView) { $viewBlock = $catalogProductView->getViewBlock(); $price = $viewBlock->getProductPriceBlock()->getPrice(); $errorsMessages = ['name' => '- product name on product view page is not correct.', 'sku' => '- product sku on product view page is not correct.', 'regular_price' => '- product regular price on product view page is not correct.', 'short_description' => '- product short description on product view page is not correct.', 'description' => '- product description on product view page is not correct.']; $dataOnPage = ['name' => $viewBlock->getProductName(), 'sku' => $viewBlock->getProductSku(), 'regular_price' => $price['price_regular_price']]; $compareData = ['name' => $this->product->getName(), 'sku' => $this->product->getSku(), 'regular_price' => number_format($this->product->getPrice(), 2)]; if ($productShortDescription = $this->product->getShortDescription()) { $compareData['short_description'] = $productShortDescription; $dataOnPage['short_description'] = $viewBlock->getProductShortDescription(); } if ($productDescription = $this->product->getDescription()) { $compareData['description'] = $productDescription; $dataOnPage['description'] = $viewBlock->getProductDescription(); } $badValues = array_diff($dataOnPage, $compareData); $errorsMessages = array_merge($this->assertSpecialPrice($price), array_intersect_key($errorsMessages, array_keys($badValues))); \PHPUnit_Framework_Assert::assertTrue(empty($errorsMessages), PHP_EOL . 'Found the following errors:' . PHP_EOL . implode(' ' . PHP_EOL, $errorsMessages)); }
/** * Assert the product is not displayed on Compare Products page * * @param CatalogProductCompare $comparePage * @param FixtureInterface $product * @param int $countProducts [optional] * @return void */ public function processAssert(CatalogProductCompare $comparePage, FixtureInterface $product, $countProducts = 0) { $comparePage->open(); $compareBlock = $comparePage->getCompareProductsBlock(); if ($countProducts > 1) { \PHPUnit_Framework_Assert::assertFalse($compareBlock->isProductVisibleInCompareBlock($product->getName()), 'The product displays on Compare Products page.'); } else { \PHPUnit_Framework_Assert::assertEquals(self::SUCCESS_MESSAGE, $compareBlock->getEmptyMessage(), 'The product displays on Compare Products page.'); } }
/** * Assert the product is not displayed on Compare Products block on my account page * * @param CmsIndex $cmsIndex * @param CustomerAccountIndex $customerAccountIndex * @param int $countProducts [optional] * @param FixtureInterface $product [optional] * @return void */ public function processAssert(CmsIndex $cmsIndex, CustomerAccountIndex $customerAccountIndex, $countProducts = 0, FixtureInterface $product = null) { $cmsIndex->open(); $cmsIndex->getLinksBlock()->openLink("My Account"); $compareBlock = $customerAccountIndex->getCompareProductsBlock(); if ($countProducts > 1 && $product !== null) { \PHPUnit_Framework_Assert::assertFalse($compareBlock->isProductVisibleInCompareBlock($product->getName()), 'The product displays on Compare Products block on my account page.'); } else { \PHPUnit_Framework_Assert::assertEquals(self::SUCCESS_MESSAGE, $compareBlock->getEmptyMessage(), 'The product displays on Compare Products block on my account page.'); } }
/** * Get cart item block * * @param FixtureInterface $product * @return \Magento\Checkout\Test\Block\Cart\CartItem */ public function getCartItem(FixtureInterface $product) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; $cartItem = null; if ($this->hasRender($typeId)) { $cartItem = $this->callRender($typeId, 'getCartItem', ['product' => $product]); } else { $cartItemBlock = $this->_rootElement->find(sprintf($this->cartItemByProductName, $product->getName()), Locator::SELECTOR_XPATH); $cartItem = $this->blockFactory->create('Magento\\Checkout\\Test\\Block\\Cart\\CartItem', ['element' => $cartItemBlock]); } return $cartItem; }
/** * 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; }
/** * Get cart item block * * @param FixtureInterface $product * @return \Magento\Checkout\Test\Block\Cart\CartItem */ public function getCartItem(FixtureInterface $product) { $cartItem = $this->_rootElement->find(sprintf($this->cartItemByProductName, $product->getName()), Locator::SELECTOR_XPATH); return $this->blockFactory->create('Magento\\Checkout\\Test\\Block\\Cart\\CartItem', ['element' => $cartItem]); }
/** * Verify product price on category view page * * @param FixtureInterface $product * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(FixtureInterface $product, CatalogCategoryView $catalogCategoryView) { $price = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($product->getName())->getRegularPrice(); \PHPUnit_Framework_Assert::assertEquals(number_format($product->getPrice(), 2), $price, 'Product regular price on category page is not correct.'); }
/** * Fill the product form * * @param FixtureInterface $product * @param Element|null $element [optional] * @param FixtureInterface|null $category [optional] * @return FormTabs */ public function fill(FixtureInterface $product, Element $element = null, FixtureInterface $category = null) { $tabs = $this->getFieldsByTabs($product); if ($category) { $tabs['product-details']['category_ids']['value'] = $category instanceof InjectableFixture ? $category->getName() : $category->getCategoryName(); } $this->showAdvancedSettings(); return parent::fillTabs($tabs, $element); }
/** * Prepare data from text to values * * @param FixtureInterface $fixture * @return array */ protected function prepareData(FixtureInterface $fixture) { $categoryId = $fixture->getDataFieldConfig('root_category_id')['source']->getCategory()->getId(); $websiteId = $fixture->getDataFieldConfig('website_id')['source']->getWebsite()->getWebsiteId(); $data['group']['name'] = $fixture->getName(); $data['group']['root_category_id'] = $categoryId; $data['group']['website_id'] = $websiteId; $data['store_action'] = isset($data['store_action']) ? $data['store_action'] : 'add'; $data['store_type'] = isset($data['store_type']) ? $data['store_type'] : 'group'; return $data; }
/** * Assert that product cannot be found via Quick Search using searchable product attributes. * * @param CatalogsearchResult $catalogSearchResult * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @return void */ public function processAssert(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, FixtureInterface $product) { $cmsIndex->open(); $cmsIndex->getSearchBlock()->search($product->getSku()); \PHPUnit_Framework_Assert::assertFalse($catalogSearchResult->getListProductBlock()->isProductVisible($product->getName()), 'Product was found by SKU.'); }
/** * Assert message is appeared on "Compare Products" block on myAccount page * * @param CatalogProductCompare $catalogProductCompare * @param FixtureInterface $product * @return void */ public function processAssert(CatalogProductCompare $catalogProductCompare, FixtureInterface $product) { $successMessage = sprintf(self::SUCCESS_MESSAGE, $product->getName()); $actualMessage = $catalogProductCompare->getMessagesBlock()->getSuccessMessages(); \PHPUnit_Framework_Assert::assertEquals($successMessage, $actualMessage, 'Wrong success message is displayed.'); }
/** * Asserts that SKU successfully generated * * @param FixtureInterface $product * @param CatalogProductIndex $productGrid * @return void */ public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid) { $filter = ['sku' => $product->getName()]; $productGrid->open(); \PHPUnit_Framework_Assert::assertTrue($productGrid->getProductGrid()->isRowVisible($filter), 'SKU is not automatically generated for a product.'); }
/** * Verify cross-sell item * * @param FixtureInterface $crosssell * @return bool */ public function verifyProductCrosssell(FixtureInterface $crosssell) { $match = $this->_rootElement->find(sprintf($this->linkSelector, $crosssell->getName()), Locator::SELECTOR_CSS); return $match->isVisible(); }
/** * Return the name of the specified product. * * @param FixtureInterface $product * @return string */ private function getProductName($product) { $productName = $product->getName(); if ($product instanceof ConfigurableProduct) { $productOptions = $product->getProductOptions(); if (!empty($productOptions)) { $productName = $productName . ' ' . key($productOptions) . ' ' . current($productOptions); } } return $productName; }