/** * 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.'); }
/** * @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()); }
/** * Retrieve original request path * * @return string */ public function getOriginalRequestPath() { $categoryPath = str_replace(' ', '-', strtolower($this->product->getCategoryName())); return $categoryPath . '/' . $this->product->getUrlKey() . '.html'; }