/** * Assert configurable product is added to cart together with the proper related product * * @param Product $product * @param Product[] $assigned * @return void */ protected function assertOnTheFrontEnd(Product $product, array $assigned) { /** @var Product $simple2 */ /** @var Product $configurable */ list($simple2, $configurable) = $assigned; //Open up simple1 product page $productPage = Factory::getPageFactory()->getCatalogProductView(); Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->assertEquals($product->getName(), $productPage->getViewBlock()->getProductName()); /** @var \Magento\Catalog\Test\Block\Product\ProductList\Related $relatedBlock */ $relatedBlock = $productPage->getRelatedProductBlock(); //Verify related simple2 and configurable on Simple1 product page $this->assertTrue($relatedBlock->isRelatedProductVisible($simple2->getName())); $this->assertTrue($relatedBlock->isRelatedProductSelectable($simple2->getName())); $this->assertTrue($relatedBlock->isRelatedProductVisible($configurable->getName())); $this->assertFalse($relatedBlock->isRelatedProductSelectable($configurable->getName())); //Open and verify configurable page $relatedBlock->openRelatedProduct($configurable->getName()); $this->assertEquals($configurable->getName(), $productPage->getViewBlock()->getProductName()); //Verify related simple2 on Configurable product page and add to cart it $relatedBlock = $productPage->getRelatedProductBlock(); $this->assertTrue($relatedBlock->isRelatedProductVisible($simple2->getName())); $this->assertTrue($relatedBlock->isRelatedProductSelectable($simple2->getName())); $relatedBlock->selectProductForAddToCart($simple2->getName()); $productPage->getViewBlock()->addToCart($configurable); //Verify that both configurable product and simple product 2 are added to shopping cart $checkoutCartPage = Factory::getPageFactory()->getCheckoutCartIndex(); $checkoutCartBlock = $checkoutCartPage->getCartBlock(); $checkoutCartPage->getMessagesBlock()->waitSuccessMessage(); $this->assertTrue($checkoutCartBlock->isProductInShoppingCart($configurable), 'Configurable product was not found in the shopping cart.'); $this->assertTrue($checkoutCartBlock->isProductInShoppingCart($simple2), 'Related product was not found in the shopping cart.'); }
/** * Product Cross-selling. Assign cross-selling to products and see them related on the front-end. * * @ZephyrId MAGETWO-12390 * @return void */ public function testCreateCrosssell() { $simple1 = Factory::getFixtureFactory()->getMagentoCatalogSimpleProduct(); $simple1->switchData('simple'); $simple1->persist(); $simple2 = Factory::getFixtureFactory()->getMagentoCatalogSimpleProduct(); $simple2->switchData('simple'); $simple2->persist(); $configurable = Factory::getFixtureFactory()->getMagentoConfigurableProductConfigurableProduct(); $configurable->switchData('configurable'); $configurable->persist(); $this->addCrosssellProducts($simple1, [$simple2, $configurable]); $this->addCrosssellProducts($configurable, [$simple1, $simple2]); //Ensure shopping cart is empty $checkoutCartPage = Factory::getPageFactory()->getCheckoutCartIndex(); $checkoutCartPage->open(); $checkoutCartPage->getCartBlock()->clearShoppingCart(); $productPage = Factory::getPageFactory()->getCatalogProductView(); Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $simple1->getUrlKey() . '.html'); $productPage->getViewBlock()->addToCart($simple1); $checkoutCartPage = Factory::getPageFactory()->getCheckoutCartIndex(); $checkoutCartPage->getMessagesBlock()->waitSuccessMessage(); $cartBlock = $checkoutCartPage->getCartBlock(); $this->assertTrue($cartBlock->isProductInShoppingCart($simple1)); $crosssellBlock = $checkoutCartPage->getCrosssellBlock(); $this->assertTrue($crosssellBlock->isVisible(), "cross-sell view not found"); $this->assertTrue($crosssellBlock->verifyProductcrosssell($configurable), 'Cross-sell product ' . $configurable->getName() . ' was not found in the first product page.'); $this->assertTrue($crosssellBlock->verifyProductcrosssell($simple2), 'Upsell product ' . $simple2->getName() . ' was not found in the first product page.'); $crosssellBlock = $checkoutCartPage->getCrosssellBlock(); $crosssellBlock->clickLink($configurable); $productPage = Factory::getPageFactory()->getCatalogProductView(); Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $configurable->getUrlKey() . '.html'); $productPage->getViewBlock()->addToCart($configurable); $checkoutCartPage = Factory::getPageFactory()->getCheckoutCartIndex(); $cartBlock = $checkoutCartPage->getCartBlock(); $this->assertTrue($cartBlock->isProductInShoppingCart($configurable)); $this->assertTrue($cartBlock->isProductInShoppingCart($simple1)); $crosssellBlock = $checkoutCartPage->getCrosssellBlock(); $crosssellBlock->clickLink($simple2); $productPage = Factory::getPageFactory()->getCatalogProductView(); Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $simple2->getUrlKey() . '.html'); $productPage->getViewBlock()->addToCart($simple2); $checkoutCartPage = Factory::getPageFactory()->getCheckoutCartIndex(); $cartBlock = $checkoutCartPage->getCartBlock(); $this->assertTrue($cartBlock->isProductInShoppingCart($configurable)); $this->assertTrue($cartBlock->isProductInShoppingCart($simple1)); $this->assertTrue($cartBlock->isProductInShoppingCart($simple2)); $this->assertFalse($checkoutCartPage->getCrosssellBlock()->isVisible()); }
/** * @param Product $product * @param Product[] $assigned * @return void */ protected function assertOnTheFrontEnd(Product $product, array $assigned) { /** @var Product $simple2 */ /** @var Product $configurable */ list($simple2, $configurable) = $assigned; //Open up simple1 product page $productPage = Factory::getPageFactory()->getCatalogProductView(); Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->assertEquals($product->getName(), $productPage->getViewBlock()->getProductName()); /** @var \Magento\Catalog\Test\Block\Product\ProductList\Upsell $upsellBlock */ $upsellBlock = $productPage->getUpsellBlock(); //Verify upsell simple2 and configurable on Simple1 product page $this->assertTrue($upsellBlock->isUpsellProductVisible($simple2->getName())); $this->assertTrue($upsellBlock->isUpsellProductVisible($configurable->getName())); //Open and verify configurable page $upsellBlock->openUpsellProduct($configurable->getName()); $this->assertEquals($configurable->getName(), $productPage->getViewBlock()->getProductName()); //Verify upsell simple2 on Configurable product page and open it $upsellBlock = $productPage->getUpsellBlock(); $this->assertTrue($upsellBlock->isUpsellProductVisible($simple2->getName())); $upsellBlock->openUpsellProduct($simple2->getName()); $this->assertEquals($simple2->getName(), $productPage->getViewBlock()->getProductName()); $this->assertFalse($productPage->getUpsellBlock()->isVisible()); }
/** * Assert product data on product page * * @param SimpleProduct $productOld * @param SimpleProduct $productEdited * @return void */ protected function assertOnProductPage(SimpleProduct $productOld, SimpleProduct $productEdited) { Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $productOld->getUrlKey() . '.html'); $productPage = Factory::getPageFactory()->getCatalogProductView(); $productViewBlock = $productPage->getViewBlock(); $this->assertEquals($productEdited->getName(), $productViewBlock->getProductName()); $price = $productViewBlock->getPriceBlock()->getPrice(); $this->assertEquals(number_format($productEdited->getProductPrice(), 2), $price); }