/**
  * Assert that product is present in products grid and can be found by sku, type, status and attribute set.
  *
  * @param FixtureInterface $product
  * @param CatalogProductIndex $productIndex
  * @return void
  */
 public function processAssert(FixtureInterface $product, CatalogProductIndex $productIndex)
 {
     $this->product = $product;
     $productIndex->open();
     $productIndex->getProductGrid()->resetFilter();
     \PHPUnit_Framework_Assert::assertTrue($productIndex->getProductGrid()->isRowVisible($this->prepareFilter()), 'Product \'' . $this->product->getName() . '\' is absent in Products grid.');
 }
Пример #2
0
 /**
  * Verify displayed product name on product page(front-end) equals passed from fixture
  *
  * @return string|null
  */
 protected function verifyName()
 {
     $fixtureProductName = $this->product->getName();
     $formProductName = $this->productView->getProductName();
     if ($fixtureProductName == $formProductName) {
         return null;
     }
     return "Displayed product name on product page(front-end) not equals passed from fixture. " . "Actual: {$formProductName}, expected: {$fixtureProductName}.";
 }
 /**
  * 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.');
 }
Пример #4
0
 /**
  * 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(), 'root_category_id' => $categoryId, 'website_id' => $websiteId, 'group_id' => $fixture->hasData('group_id') ? $fixture->getGroupId() : ''], 'store_action' => 'add', 'store_type' => 'group'];
     return $data;
 }
 /**
  * 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()->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 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);
 }
 /**
  * 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.');
 }
Пример #8
0
 /**
  * Fill the product form.
  *
  * @param FixtureInterface $product
  * @param SimpleElement|null $element [optional]
  * @param FixtureInterface|null $category [optional]
  * @return $this
  */
 public function fill(FixtureInterface $product, SimpleElement $element = null, FixtureInterface $category = null)
 {
     $sections = $this->getFixtureFieldsByContainers($product);
     ksort($sections);
     if ($category) {
         $sections['product-details']['category_ids']['value'] = $category->getName();
     }
     return $this->fillContainers($sections, $element);
 }
Пример #9
0
 /**
  * Fill the product form
  *
  * @param FixtureInterface $product
  * @param SimpleElement|null $element [optional]
  * @param FixtureInterface|null $category [optional]
  * @return FormTabs
  */
 public function fill(FixtureInterface $product, SimpleElement $element = null, FixtureInterface $category = null)
 {
     $tabs = $this->getFieldsByTabs($product);
     ksort($tabs);
     if ($category) {
         $tabs['product-details']['category_ids']['value'] = $category->getName();
     }
     $this->showAdvancedSettings();
     return $this->fillTabs($tabs, $element);
 }
 /**
  * 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.');
     }
 }
Пример #11
0
 /**
  * Select entity in grid on layout tab.
  *
  * @param FixtureInterface $product
  * @return void
  */
 protected function selectEntityInGrid(FixtureInterface $product)
 {
     $this->_rootElement->find($this->chooser, Locator::SELECTOR_XPATH)->click();
     $this->getTemplateBlock()->waitLoader();
     /** @var Grid $productGrid */
     $productGrid = $this->blockFactory->create('Magento\\Widget\\Test\\Block\\Adminhtml\\Widget\\Instance\\Edit\\Tab\\WidgetInstanceType\\Product\\Grid', ['element' => $this->_rootElement->find($this->productGrid, Locator::SELECTOR_XPATH)]);
     $productGrid->searchAndSelect(['name' => $product->getName()]);
     $this->getTemplateBlock()->waitLoader();
     $this->_rootElement->find($this->apply, Locator::SELECTOR_XPATH)->click();
 }
 /**
  * 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.');
     }
 }
 /**
  * Verify full image on product page(front-end) is displayed correctly
  *
  * @return string|null
  */
 protected function verifyFullImage()
 {
     // click base image to see full image
     $this->productView->clickBaseImage();
     if (!$this->productView->isFullImageVisible()) {
         return 'Full image for product ' . $this->product->getName() . ' should be visible after click on base one';
     }
     if (!$this->isImageLoaded($this->productView->getFullImageSource())) {
         return 'Full image file is corrupted or does not exist for product ' . $this->product->getName();
     }
     $this->productView->closeFullImage();
     return null;
 }
Пример #14
0
 /**
  * Get cart item block
  *
  * @param FixtureInterface $product
  * @return 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\\Weee\\Test\\Block\\Cart\\CartItem', ['element' => $cartItemBlock]);
     }
     return $cartItem;
 }
 /**
  * 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.');
     }
 }
 /**
  * Assert that product review available on product page.
  *
  * @param CatalogProductView $catalogProductView
  * @param Review $review
  * @param FixtureInterface $product
  * @param BrowserInterface $browser
  * @param AdminCache $cachePage
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, Review $review, FixtureInterface $product, BrowserInterface $browser, AdminCache $cachePage)
 {
     $errors = [];
     $cachePage->open()->getActionsBlock()->flushMagentoCache();
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $reviewBlock = $catalogProductView->getCustomerReviewBlock();
     $catalogProductView->getViewBlock()->selectTab('Reviews');
     \PHPUnit_Framework_Assert::assertContains(sprintf("You're reviewing:\n%s", $product->getName()), $catalogProductView->getReviewFormBlock()->getLegend()->getText());
     foreach ($review->getData() as $name => $value) {
         $reviewValue = $reviewBlock->getFieldValue($name);
         if ($reviewValue !== null && 0 !== strcasecmp($value, trim($reviewValue))) {
             $errors[] = '- field "' . $name . '" is not equals submitted one, error value "' . $value . '"';
         }
     }
     \PHPUnit_Framework_Assert::assertEmpty($errors, 'The Review contains the following errors:' . PHP_EOL . implode(PHP_EOL, $errors));
 }
Пример #17
0
 /**
  * Fill the product form.
  *
  * @param FixtureInterface $product
  * @param SimpleElement|null $element
  * @param FixtureInterface|null $category
  * @return $this
  * @throws \Exception
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function fill(FixtureInterface $product, SimpleElement $element = null, FixtureInterface $category = null)
 {
     $this->waitPageToLoad();
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     if ($this->hasRender($typeId)) {
         $renderArguments = ['product' => $product, 'element' => $element, 'category' => $category];
         $this->callRender($typeId, 'fill', $renderArguments);
     } else {
         $sections = $this->getFixtureFieldsByContainers($product);
         if ($category) {
             $sections['product-details']['category_ids']['value'] = $category->getName();
         }
         $this->fillContainers($sections, $element);
     }
     return $this;
 }
Пример #18
0
 /**
  * Select order item.
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function selectItem(FixtureInterface $product)
 {
     /** @var BundleProduct $product */
     $checkoutData = $product->getCheckoutData();
     $bundleSelection = $product->getBundleSelections();
     $bundleOptions = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : [];
     $labels = [];
     foreach ($bundleOptions as $optionKey => $option) {
         $optionKey = substr($optionKey, -1);
         $productKey = substr($option['value']['name'], -1);
         $labels[] = $bundleSelection[$optionKey]['assigned_products'][$productKey]['name'];
     }
     $this->searchAndSelect(['name' => $product->getName()]);
     $this->getTemplateBlock()->waitLoader();
     $this->getSelectItemsBlock()->fill($labels);
     $this->getTemplateBlock()->waitLoader();
 }
Пример #19
0
 /**
  * @constructor
  * @param FixtureInterface $product
  */
 public function __construct(FixtureInterface $product)
 {
     /** @var GroupedProduct $product */
     $checkoutData = $product->getCheckoutData();
     $this->data = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : [];
     $products = $product->getDataFieldConfig('associated')['source']->getProducts();
     $cartItem = [];
     $associatedProducts = [];
     foreach ($products as $key => $product) {
         $key = 'product_key_' . $key;
         $associatedProducts[$key] = $product;
     }
     // Replace key in checkout data
     foreach ($this->data as $fieldName => $fieldValues) {
         foreach ($fieldValues as $key => $value) {
             $cartItem[$fieldName][$associatedProducts[$key]->getSku()] = $value;
         }
     }
     // Add empty "options" field
     foreach ($associatedProducts as $product) {
         $cartItem['options'][] = ['title' => $product->getName(), 'value' => $cartItem['qty'][$product->getSku()]];
     }
     $this->data = $cartItem;
 }
 /**
  * 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.');
 }
 /**
  * Assert success message is presented on page
  *
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, FixtureInterface $product)
 {
     $successMessage = sprintf(self::SUCCESS_MESSAGE, $product->getName());
     $actualMessage = $catalogProductView->getMessagesBlock()->getSuccessMessages();
     \PHPUnit_Framework_Assert::assertEquals($successMessage, $actualMessage, 'Wrong success message is displayed.' . "\nExpected: " . $successMessage . "\nActual: " . $actualMessage);
 }
 /**
  * Return product item block.
  *
  * @param FixtureInterface $product
  * @return ProductItem
  */
 public function getProductItem(FixtureInterface $product)
 {
     $locator = sprintf($this->productItemByName, $product->getName());
     return $this->blockFactory->create('Magento\\Catalog\\Test\\Block\\Product\\ProductList\\ProductItem', ['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)]);
 }
 /**
  * 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.');
 }
Пример #24
0
 /**
  * Get item product block.
  *
  * @param FixtureInterface $product
  * @return Product
  */
 public function getItemProduct(FixtureInterface $product)
 {
     $productBlock = sprintf($this->itemBlock, $product->getName());
     return $this->blockFactory->create('Magento\\Wishlist\\Test\\Block\\Customer\\Wishlist\\Items\\Product', ['element' => $this->_rootElement->find($productBlock, Locator::SELECTOR_XPATH)]);
 }
 /**
  * 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()->getSuccessMessage();
     \PHPUnit_Framework_Assert::assertEquals($successMessage, $actualMessage, 'Wrong success message is displayed.');
 }
Пример #26
0
 /**
  * Fill the product form.
  *
  * @param FixtureInterface $product
  * @param SimpleElement|null $element [optional]
  * @param FixtureInterface|null $category [optional]
  * @return FormTabs
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function fill(FixtureInterface $product, SimpleElement $element = null, FixtureInterface $category = null)
 {
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     if ($this->hasRender($typeId)) {
         $renderArguments = ['product' => $product, 'element' => $element, 'category' => $category];
         $this->callRender($typeId, 'fill', $renderArguments);
     } else {
         $tabs = $this->getFieldsByTabs($product);
         if ($category) {
             $tabs['product-details']['category_ids']['value'] = $category->getName();
         }
         $this->showAdvancedSettings();
         $this->fillTabs($tabs, $element);
         if ($product->hasData('custom_attribute')) {
             $this->createCustomAttribute($product);
         }
     }
     return $this;
 }
 /**
  * Assert success message is appeared on Shopping Cart page
  *
  * @param CheckoutCart $checkoutCart
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(CheckoutCart $checkoutCart, FixtureInterface $product)
 {
     \PHPUnit_Framework_Assert::assertEquals(sprintf(self::SUCCESS_MESSAGE, $product->getName()), $checkoutCart->getMessagesBlock()->getSuccessMessage());
 }
 /**
  * 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;
 }