/**
  * Assert that products added to wishlist are present on Customers account on backend.
  *
  * @param CustomerIndex $customerIndex
  * @param Customer $customer
  * @param CustomerIndexEdit $customerIndexEdit
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(CustomerIndex $customerIndex, Customer $customer, CustomerIndexEdit $customerIndexEdit, InjectableFixture $product)
 {
     $customerIndex->open();
     $customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]);
     $customerIndexEdit->getCustomerForm()->openTab('wishlist');
     /** @var \Magento\Wishlist\Test\Block\Adminhtml\Customer\Edit\Tab\Wishlist\Grid $wishlistGrid */
     $wishlistGrid = $customerIndexEdit->getCustomerForm()->getTab('wishlist')->getSearchGridBlock();
     \PHPUnit_Framework_Assert::assertTrue($wishlistGrid->isRowVisible(['product_name' => $product->getName()]), $product->getName() . " is not visible in customer wishlist on backend.");
 }
 /**
  * Assert that "Add to cart" button is present 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()->isProductVisible($product->getName());
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
     \PHPUnit_Framework_Assert::assertTrue($catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisibleAddToCardButton(), "Button 'Add to Card' is absent on Category page.");
     $catalogCategoryView->getListProductBlock()->openProductViewPage($product->getName());
     \PHPUnit_Framework_Assert::assertTrue($catalogProductView->getViewBlock()->isVisibleAddToCardButton(), "Button 'Add to Card' is absent on Product page.");
 }
 /**
  * Get form prices.
  *
  * @param InjectableFixture $product
  * @param CatalogCategoryView $catalogCategoryView
  * @return array
  */
 protected function getFormPrices(InjectableFixture $product, CatalogCategoryView $catalogCategoryView)
 {
     $productPriceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($product->getName());
     $actualPrices = ['regular' => $productPriceBlock->getRegularPrice(), 'special' => $productPriceBlock->getSpecialPrice()];
     $actualPrices['discount_amount'] = number_format($actualPrices['regular'] - $actualPrices['special'], 2);
     return $actualPrices;
 }
Example #4
0
 /**
  * Returns the item price for the specified product.
  *
  * @param InjectableFixture $product
  * @return array|string
  */
 public function getPrice(InjectableFixture $product)
 {
     $productName = $product->getName();
     if ($product instanceof ConfigurableProduct) {
         // Find the price for the specific configurable product that was purchased
         $attributesData = $product->getConfigurableAttributesData()['attributes_data'];
         $matrix = $product->getConfigurableAttributesData()['matrix'];
         $checkoutOptions = $product->getCheckoutData()['options']['configurable_options'];
         $optionsDetails = [];
         $matrixKey = [];
         $optionsPrice = 0;
         foreach ($checkoutOptions as $checkoutOption) {
             $titleKey = $checkoutOption['title'];
             $valueKey = $checkoutOption['value'];
             $attributeName = $attributesData[$titleKey]['frontend_label'];
             $optionLabel = $attributesData[$titleKey]['options'][$valueKey]['label'];
             $optionsDetails[] = "{$attributeName}{$optionLabel}";
             $matrixKey[] = "{$titleKey}:{$valueKey}";
             $optionsPrice += $attributesData[$titleKey]['options'][$valueKey]['pricing_value'];
         }
         $optionsDetails = implode(' ', $optionsDetails);
         $matrixKey = implode(' ', $matrixKey);
         $productDisplay = $productName . 'SKU: ' . $matrix[$matrixKey]['sku'] . $optionsDetails;
     } else {
         $productDisplay = $productName . 'SKU: ' . $product->getSku();
     }
     $selector = '//tr[normalize-space(td)="' . $productDisplay . '"]' . $this->priceSelector;
     return $this->escapeCurrency($this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText());
 }
 /**
  * Assert that duplicated product can be found in grid by type, template, status and stock status.
  *
  * @param InjectableFixture $product
  * @param CatalogProduct $productGrid
  * @return void
  */
 public function processAssert(InjectableFixture $product, CatalogProduct $productGrid)
 {
     $config = $product->getDataConfig();
     $filter = ['name' => $product->getName(), 'visibility' => $product->getVisibility(), 'status' => 'Disabled', 'type' => ucfirst($config['create_url_params']['type']) . ' Product', 'price_to' => number_format($product->getPrice(), 2)];
     $productGrid->open()->getProductGrid()->search($filter);
     \PHPUnit_Framework_Assert::assertTrue($productGrid->getProductGrid()->isRowVisible($filter, false, false), 'Product duplicate is absent in Products grid.');
 }
 /**
  * Assert that redirect from newCategory/oldProduct is correct to new product.
  *
  * @param InjectableFixture $product
  * @param InjectableFixture $initialProduct
  * @param Browser $browser
  * @param CatalogProductView $catalogProductView
  * @return void
  */
 public function processAssert(InjectableFixture $product, InjectableFixture $initialProduct, Browser $browser, CatalogProductView $catalogProductView)
 {
     $category = $product->getDataFieldConfig('category_ids')['source']->getProductCategory();
     $productUrl = $_ENV['app_frontend_url'] . $category->getUrlKey() . '/' . $initialProduct->getUrlKey() . '.html';
     $browser->open($productUrl);
     \PHPUnit_Framework_Assert::assertEquals($catalogProductView->getViewBlock()->getProductName(), strtoupper($product->getName()));
 }
 /**
  * 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);
 }
 /**
  * Verify displayed product name on product page(front-end) equals passed from fixture.
  *
  * @return string|null
  */
 protected function verifyName()
 {
     $fixtureProductName = strtoupper($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}.";
 }
Example #9
0
 /**
  * Get item block.
  *
  * @param InjectableFixture $product
  * @param int $itemIndex
  * @return ElementInterface
  */
 public function getItemBlockElement(InjectableFixture $product, $itemIndex)
 {
     $itemBlockSelector = sprintf($this->itemBlock, $product->getName());
     ++$itemIndex;
     $itemBlockElement = $this->_rootElement->find($itemBlockSelector . "[{$itemIndex}]", Locator::SELECTOR_XPATH);
     if (!$itemBlockElement->isVisible()) {
         $itemBlockElement = $this->_rootElement->find($itemBlockSelector, Locator::SELECTOR_XPATH);
     }
     return $itemBlockElement;
 }
Example #10
0
 /**
  * Fill options, get price and add to cart.
  *
  * @return array
  */
 protected function getProductPrice()
 {
     $prices = [];
     $this->catalogCategoryView->getListProductBlock()->openProductViewPage($this->product->getName());
     $priceBlock = $this->catalogProductView->getWeeeViewBlock()->getPriceBlock();
     $this->catalogProductView->getViewBlock()->fillOptions($this->product);
     foreach ($this->expectedPrices['product'] as $key => $type) {
         $prices[$key] = $this->getPrice($priceBlock, $key);
     }
     return $prices;
 }
 /**
  * Assert form data equals fixture data.
  *
  * @param InjectableFixture $product
  * @param CatalogProduct $productGrid
  * @param CatalogProductEdit $productPage
  * @param string $urlKeyFormat [optional]
  * @return void
  */
 public function processAssert(InjectableFixture $product, CatalogProduct $productGrid, CatalogProductEdit $productPage, $urlKeyFormat = '%s')
 {
     $this->product = $product;
     $this->urlKeyFormat = $urlKeyFormat;
     $this->catalogProductEdit = $productPage;
     $filter = ['name' => $product->getName(), 'status' => 'Disabled'];
     $productGrid->open()->getProductGrid()->searchAndOpen($filter);
     $formData = $productPage->getProductForm()->getData($product);
     $fixtureData = $this->prepareFixtureData($product->getData());
     $errors = $this->verifyData($fixtureData, $formData);
     \PHPUnit_Framework_Assert::assertEmpty($errors, $errors);
 }
 /**
  * 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);
 }
Example #13
0
 /**
  * Returns the item price for the specified product.
  *
  * @param InjectableFixture $product
  * @return array|string
  */
 public function getPrice(InjectableFixture $product)
 {
     $productName = $product->getName();
     if ($product instanceof ConfigurableProduct) {
         // Find the price for the specific configurable product that was purchased
         $configurableAttributes = $product->getConfigurableAttributes();
         $productOptions = $product->getCheckoutData()['options']['configurable_options'];
         $checkoutOption = reset($productOptions);
         $attributeKey = $checkoutOption['title'];
         $optionKey = $checkoutOption['value'];
         $attributeValue = $configurableAttributes[$attributeKey]['label']['value'];
         $optionValue = $configurableAttributes[$attributeKey][$optionKey]['option_label']['value'];
         $productDisplay = $productName . ' SKU: ' . $product->getVariationSku($checkoutOption);
         $productDisplay .= ' ' . $attributeValue . ' ' . $optionValue;
     } else {
         $productDisplay = $productName . ' SKU: ' . $product->getSku();
     }
     $selector = '//tr[normalize-space(td)="' . $productDisplay . '"]' . $this->priceSelector;
     return $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText();
 }
 /**
  * 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
     $productName = $product->getName();
     $productCategory = $product->getCategoryIds()[0];
     $this->openCategory($productCategory);
     $actualPrices = $this->getCategoryPrices($productName, $actualPrices);
     $catalogCategoryView->getListProductBlock()->openProductViewPage($productName);
     $catalogProductView->getViewBlock()->fillOptions($product);
     $actualPrices = $this->getProductPagePrices($actualPrices);
     $catalogProductView->getViewBlock()->clickAddToCart();
     $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);
 }
Example #15
0
 /**
  * Get item product block.
  *
  * @param InjectableFixture $product
  * @return ItemProduct
  */
 public function getItemProduct(InjectableFixture $product)
 {
     return $this->blockFactory->create('Magento\\GiftMessage\\Test\\Block\\Adminhtml\\Order\\Create\\Items\\ItemProduct', ['element' => $this->browser->find(sprintf($this->itemProduct, $product->getName()), Locator::SELECTOR_XPATH)]);
 }
 /**
  * Assert that attribute present in sort dropdown on search results page on frontend.
  *
  * @param CmsIndex $cmsIndex
  * @param CatalogsearchResult $catalogsearchResult
  * @param CatalogProductAttribute $attribute
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(CmsIndex $cmsIndex, CatalogsearchResult $catalogsearchResult, CatalogProductAttribute $attribute, InjectableFixture $product)
 {
     $cmsIndex->open()->getSearchBlock()->search($product->getName());
     $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel();
     \PHPUnit_Framework_Assert::assertTrue(in_array($label, $catalogsearchResult->getListProductBlock()->getSortByValues()), 'Attribute is absent in sort dropdown on search results page on frontend.');
 }
 /**
  * Assert that product success add message is present on CatalogProductView page.
  *
  * @param CatalogProductView $catalogProductView
  * @param InjectableFixture $product
  * @return bool
  */
 public function processAssert(CatalogProductView $catalogProductView, InjectableFixture $product)
 {
     $successMessage = sprintf(self::SUCCESS_MESSAGE, $product->getName());
     $actualMessage = $catalogProductView->getMessagesBlock()->getSuccessMessages();
     \PHPUnit_Framework_Assert::assertEquals($successMessage, $actualMessage);
 }
Example #18
0
 /**
  * Get gift message element.
  *
  * @param InjectableFixture $giftItem
  * @return Element
  */
 protected function getGiftMessageElement(InjectableFixture $giftItem)
 {
     $itemName = $giftItem->getName();
     $this->showGiftMessageElement($itemName);
     return $this->_rootElement->find(sprintf($this->giftMessageForItem, $itemName), Locator::SELECTOR_XPATH);
 }
 /**
  * Get prices on category page.
  *
  * @param InjectableFixture $product
  * @return array
  */
 protected function getCategoryPrices(InjectableFixture $product)
 {
     return ['category_price' => $this->catalogCategoryView->getListProductBlock()->getProductPriceBlock($product->getName())->getResultPrice()];
 }
 /**
  * Assert that success message appears on My Wish List page after adding product to wishlist.
  *
  * @param WishlistIndex $wishlistIndex
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(WishlistIndex $wishlistIndex, InjectableFixture $product)
 {
     \PHPUnit_Framework_Assert::assertEquals(sprintf(self::SUCCESS_MESSAGE, $product->getName()), $wishlistIndex->getMessagesBlock()->getSuccessMessage(), "Expected success message doesn't match actual.");
 }
Example #21
0
 /**
  * Get item product block.
  *
  * @param InjectableFixture $product
  * @return ItemProduct
  */
 public function getItemProduct(InjectableFixture $product)
 {
     $name = $product->getName();
     return $this->blockFactory->create('Mage\\Adminhtml\\Test\\Block\\Sales\\Order\\Create\\Items\\ItemProduct', ['element' => $this->_rootElement->find(sprintf($this->itemProduct, $name), Locator::SELECTOR_XPATH)]);
 }
 /**
  * Verify product price on category view page.
  *
  * @param InjectableFixture $product
  * @param CatalogCategoryView $catalogCategoryView
  * @return void
  */
 protected function assertPrice(InjectableFixture $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.');
 }
 /**
  * Verify cross-sell item.
  *
  * @param InjectableFixture $product
  * @return bool
  */
 public function verifyProductCrosssell(InjectableFixture $product)
 {
     return $this->_rootElement->find(sprintf($this->crosssellProduct, $product->getName()), Locator::SELECTOR_XPATH)->isVisible();
 }
Example #24
0
 /**
  * Get item block.
  *
  * @param InjectableFixture $product
  * @return BlockInterface
  */
 public function getItemBlock(InjectableFixture $product)
 {
     return $this->blockFactory->create('Mage\\Catalog\\Test\\Block\\Product\\ProductList\\Related\\Item', ['element' => $this->_rootElement->find(sprintf($this->relatedProduct, $product->getName()), Locator::SELECTOR_XPATH)]);
 }
Example #25
0
 /**
  * Check if item is visible in print order page.
  *
  * @param \Magento\Mtf\Fixture\InjectableFixture $product
  * @return bool
  */
 public function isItemVisible($product)
 {
     return $this->_rootElement->find(sprintf($this->itemSelector, $product->getName()), Locator::SELECTOR_XPATH)->isVisible();
 }
Example #26
0
 /**
  * Get gift message item form.
  *
  * @param InjectableFixture $product
  * @return GiftMessageForm
  */
 protected function getGiftMessageItemForm(InjectableFixture $product)
 {
     $selector = sprintf($this->giftMessageItemForm, $product->getName());
     $this->waitForElementVisible($selector, Locator::SELECTOR_XPATH);
     return $this->blockFactory->create('Mage\\GiftMessage\\Test\\Block\\Message\\Inline\\GiftMessageForm', ['element' => $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)]);
 }
 /**
  * Check if product with specified name is visible.
  *
  * @param InjectableFixture $product
  * @return bool
  */
 public function isProductVisible($product)
 {
     return $this->getProductNameElement($product->getName())->isVisible();
 }
 /**
  * Return product item block.
  *
  * @param InjectableFixture $product
  * @return ProductItem
  */
 public function getProductItem(InjectableFixture $product)
 {
     $locator = sprintf($this->productItem, $product->getName());
     return $this->blockFactory->create('Mage\\Weee\\Test\\Block\\Product\\ProductList\\ProductItem', ['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)]);
 }
 /**
  * Get order product prices.
  *
  * @param InjectableFixture $product
  * @param $actualPrices
  * @return array
  */
 public function getOrderPrices($actualPrices, InjectableFixture $product)
 {
     $viewBlock = $this->customerOrderView->getOrderViewBlock();
     $actualPrices['cart_item_price_excl_tax'] = $viewBlock->getItemPriceExclTax($product->getName());
     $actualPrices['cart_item_price_incl_tax'] = $viewBlock->getItemPriceInclTax($product->getName());
     $actualPrices['cart_item_subtotal_excl_tax'] = $viewBlock->getItemSubExclTax($product->getName());
     $actualPrices['cart_item_subtotal_incl_tax'] = $viewBlock->getItemSubInclTax($product->getName());
     return $actualPrices;
 }
 /**
  * Get product name.
  *
  * @param InjectableFixture $product
  * @return string
  */
 protected function getProductName(InjectableFixture $product)
 {
     return strtoupper($product->getName());
 }