/** * Open product on frontend and click Checkout with PayPal button. * * @return void */ public function run() { $product = reset($this->products); $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $parentWindow = $this->catalogProductView->getViewBlock()->braintreePaypalCheckout(); $this->catalogProductView->getBraintreePaypalBlock()->process($parentWindow); }
/** * Assert that displayed category data on category page equals to passed from fixture. * * @param Category $category * @param Category $initialCategory * @param FixtureFactory $fixtureFactory * @param CatalogCategoryView $categoryView * @param BrowserInterface $browser * @return void */ public function processAssert(Category $category, Category $initialCategory, FixtureFactory $fixtureFactory, CatalogCategoryView $categoryView, BrowserInterface $browser) { $this->browser = $browser; $this->categoryViewPage = $categoryView; $categoryData = $this->prepareData($fixtureFactory, $category, $initialCategory); $this->browser->open($this->getCategoryUrl($category)); $this->assertGeneralInformation($category, $categoryData); $this->assertDisplaySetting($category, $categoryData); }
/** * Add products to the cart * * @return void */ public function run() { // Ensure that shopping cart is empty $this->checkoutCart->open()->getCartBlock()->clearShoppingCart(); foreach ($this->products as $product) { $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->catalogProductView->getViewBlock()->addToCart($product); $this->catalogProductView->getMessagesBlock()->waitSuccessMessage(); } }
/** * Add products to the wish list * * @return void */ public function run() { foreach ($this->products as $product) { $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); if ($this->configure) { $this->catalogProductView->getViewBlock()->addToWishlist($product); } else { $this->catalogProductView->getViewBlock()->clickAddToWishlist(); } } }
/** * Assert that category name is different on different store view. * * @param BrowserInterface $browser * @param CatalogCategoryView $categoryView * @param Category $category * @param Category $initialCategory * @param CmsIndex $cmsIndex * @return void */ public function processAssert(BrowserInterface $browser, CatalogCategoryView $categoryView, Category $category, Category $initialCategory, CmsIndex $cmsIndex) { $cmsIndex->open(); $cmsIndex->getLinksBlock()->waitWelcomeMessage(); $browser->open($_ENV['app_frontend_url'] . $initialCategory->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertEquals($initialCategory->getName(), $categoryView->getTitleBlock()->getTitle(), 'Wrong category name is displayed for default store.'); $store = $category->getDataFieldConfig('store_id')['source']->store->getName(); $cmsIndex->getStoreSwitcherBlock()->selectStoreView($store); $cmsIndex->getLinksBlock()->waitWelcomeMessage(); $browser->open($_ENV['app_frontend_url'] . $initialCategory->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertEquals($category->getName(), $categoryView->getTitleBlock()->getTitle(), 'Wrong category name is displayed for ' . $store); }
/** * Assert that displayed category data on category page equals to passed from fixture. * * @param Category $category * @param CatalogCategoryView $categoryView * @param BrowserInterface $browser * @return void */ public function processAssert(Category $category, CatalogCategoryView $categoryView, BrowserInterface $browser) { $this->browser = $browser; $this->category = $category; $this->categoryViewPage = $categoryView; $this->browser->open($this->getCategoryUrl($category)); $categoryData = $this->prepareFixtureData($category->getData()); $diff = $this->verifyGeneralInformation($categoryData); $diff = array_merge($diff, $this->verifyContent($categoryData)); $diff = array_merge($diff, $this->verifyDisplaySettings($categoryData)); $diff = array_merge($diff, $this->verifySearchEngineOptimization($categoryData)); \PHPUnit_Framework_Assert::assertEmpty($diff, "Category settings on Storefront page are different.\n" . implode(' ', $diff)); }
/** * Open category. * * @param Category $category * @return void */ protected function openCategory(Category $category) { $categoryUrlKey = []; while ($category) { $categoryUrlKey[] = $category->hasData('url_key') ? strtolower($category->getUrlKey()) : trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-'); $category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory(); if ($category !== null && 1 == $category->getParentId()) { $category = null; } } $categoryUrlKey = $_ENV['app_frontend_url'] . implode('/', array_reverse($categoryUrlKey)) . '.html'; $this->browser->open($categoryUrlKey); }
/** * Assert that product rating is not displayed on frontend on product review * * @param CatalogProductView $catalogProductView * @param CatalogProductSimple $product * @param Rating $productRating * @param BrowserInterface $browser * @return void */ public function processAssert(CatalogProductView $catalogProductView, CatalogProductSimple $product, Rating $productRating, BrowserInterface $browser) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $catalogProductView->getReviewSummary()->getAddReviewLink()->click(); $reviewForm = $catalogProductView->getReviewFormBlock(); \PHPUnit_Framework_Assert::assertFalse($reviewForm->isVisibleRating($productRating), 'Product rating "' . $productRating->getRatingCode() . '" is displayed.'); }
/** * Assert that created entity was found on search page * * @param UrlRewrite $initialRewrite * @param UrlRewrite $urlRewrite * @param BrowserInterface $browser * @param CatalogCategoryView $categoryView * @return void */ public function processAssert(UrlRewrite $initialRewrite, UrlRewrite $urlRewrite, BrowserInterface $browser, CatalogCategoryView $categoryView) { $urlRequestPath = $urlRewrite->hasData('request_path') ? $urlRewrite->getRequestPath() : $initialRewrite->getRequestPath(); $browser->open($_ENV['app_frontend_url'] . $urlRequestPath); $entity = $urlRewrite->getDataFieldConfig('target_path')['source']->getEntity()->getName(); \PHPUnit_Framework_Assert::assertTrue($categoryView->getListProductBlock()->isProductVisible($entity), "Created entity '{$entity}' isn't found."); }
/** * Assert that product is not displayed in up-sell section * * @param BrowserInterface $browser * @param CatalogProductSimple $product * @param InjectableFixture[] $relatedProducts * @param CatalogProductView $catalogProductView * @return void */ public function processAssert(BrowserInterface $browser, CatalogProductSimple $product, array $relatedProducts, CatalogProductView $catalogProductView) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); foreach ($relatedProducts as $relatedProduct) { \PHPUnit_Framework_Assert::assertFalse($catalogProductView->getUpsellBlock()->isUpsellProductVisible($relatedProduct->getName()), 'Product \'' . $relatedProduct->getName() . '\' is exist in up-sells products.'); } }
/** * 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; }
/** * Assert that displayed price view for bundle product on product page equals passed from fixture. * * @param CatalogProductView $catalogProductView * @param BrowserInterface $browser * @param BundleProduct $product * @return void */ public function processAssert(CatalogProductView $catalogProductView, BrowserInterface $browser, BundleProduct $product) { //Open product view page $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); //Process assertions $this->assertPrice($product, $catalogProductView); }
/** * Assert that the category cannot be accessed from the navigation bar in the frontend * * @param CmsIndex $cmsIndex * @param Category $category * @param BrowserInterface $browser * @return void */ public function processAssert(CmsIndex $cmsIndex, Category $category, BrowserInterface $browser) { $cmsIndex->open(); \PHPUnit_Framework_Assert::assertFalse($cmsIndex->getTopmenu()->isCategoryVisible($category->getName()), 'Category can be accessed from the navigation bar in the frontend.'); $browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertEquals(self::NOT_FOUND_MESSAGE, $cmsIndex->getTitleBlock()->getTitle(), 'Wrong page is displayed.'); }
/** * Assert check URL rewrite custom redirect * * @param UrlRewrite $urlRewrite * @param BrowserInterface $browser * @param CmsIndex $cmsIndex * @return void */ public function processAssert(UrlRewrite $urlRewrite, BrowserInterface $browser, CmsIndex $cmsIndex) { $browser->open($_ENV['app_frontend_url'] . $urlRewrite->getRequestPath()); $entity = $urlRewrite->getDataFieldConfig('target_path')['source']->getEntity(); $title = $entity->hasData('name') ? $entity->getName() : $entity->getContentHeading(); $pageTitle = $cmsIndex->getTitleBlock()->getTitle(); \PHPUnit_Framework_Assert::assertEquals($pageTitle, $title, 'URL rewrite product redirect false.' . "\nExpected: " . $title . "\nActual: " . $pageTitle); }
/** * Add products to compare list * * @param array $products * @return void */ protected function addProducts(array $products) { foreach ($products as $itemProduct) { $this->browser->open($_ENV['app_frontend_url'] . $itemProduct->getUrlKey() . '.html'); $this->catalogProductView->getViewBlock()->clickAddToCompare(); $this->catalogProductView->getMessagesBlock()->waitSuccessMessage(); } }
/** * Assertion that tier prices are displayed correctly * * @param BrowserInterface $browser * @param CatalogProductView $catalogProductView * @param FixtureInterface $product * @return void */ public function processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product) { // TODO fix initialization url for frontend page //Open product view page $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); //Process assertions $this->assertPrice($product, $catalogProductView->getViewBlock()); }
/** * Assert that outside redirect was success * * @param UrlRewrite $urlRewrite * @param BrowserInterface $browser * @param UrlRewrite|null $initialRewrite [optional] * @return void */ public function processAssert(UrlRewrite $urlRewrite, BrowserInterface $browser, UrlRewrite $initialRewrite = null) { $urlRequestPath = $urlRewrite->hasData('request_path') ? $urlRewrite->getRequestPath() : $initialRewrite->getRequestPath(); $urlTargetPath = $urlRewrite->hasData('target_path') ? $urlRewrite->getTargetPath() : $initialRewrite->getTargetPath(); $browser->open($_ENV['app_frontend_url'] . $urlRequestPath); $browserUrl = $browser->getUrl(); \PHPUnit_Framework_Assert::assertEquals($browserUrl, $urlTargetPath, 'URL rewrite redirect false.' . "\nExpected: " . $urlTargetPath . "\nActual: " . $browserUrl); }
/** * Assert that displayed product data on product page(front-end) equals passed from fixture: * 1. Product Name * 2. Price * 3. Special price * 4. SKU * 5. Description * 6. Short Description * * @param BrowserInterface $browser * @param CatalogProductView $catalogProductView * @param FixtureInterface $product * @return void */ public function processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->product = $product; $this->productView = $catalogProductView->getViewBlock(); $errors = $this->verify(); \PHPUnit_Framework_Assert::assertEmpty($errors, "\nFound the following errors:\n" . implode(" \n", $errors)); }
/** * Check that product available by new URL on the front * * @param UrlRewrite $urlRewrite * @param CatalogProductView $catalogProductView * @param BrowserInterface $browser * @param InjectableFixture $product * @return void */ public function processAssert(UrlRewrite $urlRewrite, CatalogProductView $catalogProductView, BrowserInterface $browser, InjectableFixture $product = null) { $browser->open($_ENV['app_frontend_url'] . $urlRewrite->getRequestPath()); if ($product === null) { $product = $urlRewrite->getDataFieldConfig('target_path')['source']->getEntity(); } \PHPUnit_Framework_Assert::assertEquals($catalogProductView->getTitleBlock()->getTitle(), $product->getName(), 'URL rewrite product redirect false.' . "\nExpected: " . $product->getName() . "\nActual: " . $catalogProductView->getTitleBlock()->getTitle()); }
/** * Check whether there is an opportunity to compare products using given attribute. * * @param InjectableFixture $product * @param CatalogProductAttribute $attribute * @param BrowserInterface $browser * @param CatalogProductView $catalogProductView * @param CatalogProductCompare $catalogProductCompare * @return void */ public function processAssert(InjectableFixture $product, CatalogProductAttribute $attribute, BrowserInterface $browser, CatalogProductView $catalogProductView, CatalogProductCompare $catalogProductCompare) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $catalogProductView->getViewBlock()->clickAddToCompare(); $catalogProductCompare->open(); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue($catalogProductCompare->getCompareProductsBlock()->isAttributeVisible($label), 'Attribute is absent on product compare page.'); }
/** * Assert that displayed price for bundle items on shopping cart page equals to passed from fixture. * Price for bundle items has two options: * 1. Fixed (price of bundle product) * 2. Dynamic (price of bundle item) * * @param CatalogProductView $catalogProductView * @param BundleProduct $product * @param CheckoutCart $checkoutCartView * @param BrowserInterface $browser * @param BundleProduct $originalProduct [optional] * @return void */ public function processAssert(CatalogProductView $catalogProductView, BundleProduct $product, CheckoutCart $checkoutCartView, BrowserInterface $browser, BundleProduct $originalProduct = null) { $checkoutCartView->open()->getCartBlock()->clearShoppingCart(); //Open product view page $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); //Process assertions $this->assertPrice($product, $catalogProductView, $checkoutCartView, $originalProduct); }
/** * Asserts that user has only related permissions. * * @param BrowserInterface $browser * @param Dashboard $dashboard * @param User $user * @param array $restrictedAccess * @param string $denyUrl * @return void */ public function processAssert(BrowserInterface $browser, Dashboard $dashboard, User $user, array $restrictedAccess, $denyUrl) { $this->objectManager->create('Magento\\User\\Test\\TestStep\\LoginUserOnBackendStep', ['user' => $user])->run(); $menuItems = $dashboard->getMenuBlock()->getTopMenuItems(); \PHPUnit_Framework_Assert::assertEquals($menuItems, $restrictedAccess, 'Wrong display menu.'); $browser->open($_ENV['app_backend_url'] . $denyUrl); $deniedMessage = $dashboard->getAccessDeniedBlock()->getTextFromAccessDeniedBlock(); \PHPUnit_Framework_Assert::assertEquals(self::DENIED_ACCESS, $deniedMessage, 'Possible access to denied page.'); }
/** * Add product to cart. * * @param CatalogProductSimple $product * @param int $qty * @return void */ protected function addProductToCart(CatalogProductSimple $product, $qty) { $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $productView = $this->catalogProductView->getViewBlock(); $productView->fillOptions($product); $productView->setQty($qty); $productView->clickAddToCart(); $this->catalogProductView->getMessagesBlock()->waitSuccessMessage(); }
/** * Assert that product can be added to active gift registry from shopping cart. * * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param InjectableFixture $product * @param GiftRegistry $giftRegistry * @param GiftRegistryItems $giftRegistryItems * @param BrowserInterface $browser * @return void */ public function processAssert(CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, InjectableFixture $product, GiftRegistry $giftRegistry, GiftRegistryItems $giftRegistryItems, BrowserInterface $browser) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $catalogProductView->getViewBlock()->addToCart($product); $catalogProductView->getMessagesBlock()->waitSuccessMessage(); $checkoutCart->open(); $checkoutCart->getGiftRegistryBlock()->addToGiftRegistry($giftRegistry); \PHPUnit_Framework_Assert::assertTrue($giftRegistryItems->getGiftRegistryItemsBlock()->isProductInGrid($product), "Product can not be added to active gift registry '{$giftRegistry->getTitle()}' from shopping cart."); }
/** * Assert that deleted configurable attributes are absent on product page on frontend. * * @param CatalogProductAttribute[] $deletedProductAttributes * @param BrowserInterface $browser * @param CatalogProductView $catalogProductView * @param ConfigurableProduct $product * @return void */ public function processAssert(array $deletedProductAttributes, BrowserInterface $browser, CatalogProductView $catalogProductView, ConfigurableProduct $product) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $pageOptions = $catalogProductView->getViewBlock()->getOptions($product)['configurable_options']; foreach ($deletedProductAttributes as $attribute) { $attributeLabel = $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertFalse(isset($pageOptions[$attributeLabel]), "Configurable attribute '{$attributeLabel}' found on product page on frontend."); } }
/** * Open products * * @param array $products * @param string $total * @return void */ protected function openProducts(array $products, $total) { $total = explode(', ', $total); foreach ($products as $key => $product) { for ($i = 0; $i < $total[$key]; $i++) { $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); } } }
/** * Assert Sample block for downloadable product on front-end * * @param CatalogProductView $productView * @param DownloadableProduct $product * @param BrowserInterface $browser * @return void */ public function processAssert(CatalogProductView $productView, DownloadableProduct $product, BrowserInterface $browser) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $fixtureSampleLinks = $this->prepareFixtureData($product); $pageOptions = $productView->getViewBlock()->getOptions($product); $pageSampleLinks = isset($pageOptions['downloadable_options']['downloadable_sample']) ? $this->preparePageData($pageOptions['downloadable_options']['downloadable_sample']) : []; $error = $this->verifyData($fixtureSampleLinks, $pageSampleLinks); \PHPUnit_Framework_Assert::assertEmpty($error, $error); }
/** * Assertion that tier prices are displayed correctly * * @param BrowserInterface $browser * @param CatalogProductView $catalogProductView * @param FixtureInterface $product * @return void */ public function processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product) { //Open product view page $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $viewBlock = $catalogProductView->getBundleViewBlock(); $viewBlock->clickCustomize(); //Process assertions $this->assertPrice($product, $viewBlock); }
/** * Assert that widget with type Recently Viewed Products is present on category page * * @param CmsIndex $cmsIndex * @param AdminCache $adminCache * @param CatalogCategoryView $catalogCategoryView * @param BrowserInterface $browser * @param CatalogProductSimple $productSimple * @param Category $category * @param Customer $customer * @return void */ public function processAssert(CmsIndex $cmsIndex, AdminCache $adminCache, CatalogCategoryView $catalogCategoryView, BrowserInterface $browser, CatalogProductSimple $productSimple, Category $category, Customer $customer) { $this->browser = $browser; $this->cmsIndex = $cmsIndex; $this->catalogCategoryView = $catalogCategoryView; // Flush cache $adminCache->open(); $adminCache->getActionsBlock()->flushMagentoCache(); $adminCache->getMessagesBlock()->waitSuccessMessage(); // Log in customer $customer->persist(); $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); // Open products $productSimple->persist(); $category->persist(); $this->browser->open($_ENV['app_frontend_url'] . $productSimple->getUrlKey() . '.html'); $this->checkRecentlyViewedBlockOnCategory($productSimple, $category); }
/** * Assert that displayed assigned products on category page equals passed from fixture * * @param Category $category * @param CatalogCategoryView $categoryView * @param BrowserInterface $browser * @return void */ public function processAssert(Category $category, CatalogCategoryView $categoryView, BrowserInterface $browser) { $categoryUrlKey = $category->hasData('url_key') ? strtolower($category->getUrlKey()) : trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-'); $products = $category->getDataFieldConfig('category_products')['source']->getProducts(); $browser->open($_ENV['app_frontend_url'] . $categoryUrlKey . '.html'); foreach ($products as $productFixture) { \PHPUnit_Framework_Assert::assertTrue($categoryView->getListProductBlock()->getProductItem($productFixture)->isVisible(), "Products '{$productFixture->getName()}' not find."); } }