/**
  * Check that block Recently Viewed contains product on category page
  *
  * @param CatalogProductSimple $productSimple
  * @param Category $category
  * @return void
  */
 protected function checkRecentlyViewedBlockOnCategory(CatalogProductSimple $productSimple, Category $category)
 {
     $this->cmsIndex->open();
     $this->cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
     $products = $this->catalogCategoryView->getViewBlock()->getProductsFromRecentlyViewedBlock();
     \PHPUnit_Framework_Assert::assertTrue(in_array($productSimple->getName(), $products), 'Product' . $productSimple->getName() . ' is absent on Recently Viewed block on Category page.');
 }
 /**
  * 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.');
 }
 /**
  * Inject page end prepare default category
  *
  * @param Category $initialCategory
  * @param CatalogCategoryIndex $catalogCategoryIndex
  * @param CatalogCategoryEdit $catalogCategoryEdit
  * @return array
  */
 public function __inject(Category $initialCategory, CatalogCategoryIndex $catalogCategoryIndex, CatalogCategoryEdit $catalogCategoryEdit)
 {
     $this->catalogCategoryIndex = $catalogCategoryIndex;
     $this->catalogCategoryEdit = $catalogCategoryEdit;
     $initialCategory->persist();
     return ['initialCategory' => $initialCategory];
 }
 /**
  * Delete category
  *
  * @param Category $category
  * @return void
  */
 public function test(Category $category)
 {
     $category->persist();
     $this->catalogCategoryIndex->open();
     $this->catalogCategoryIndex->getTreeCategories()->selectCategory($category);
     $this->catalogCategoryEdit->getFormPageActions()->delete();
 }
 /**
  * Assert that apache redirect works by opening category page and asserting index.php in its url
  *
  * @param Category $category
  * @param CmsIndex $homePage
  * @param BrowserInterface $browser
  */
 public function processAssert(Category $category, CmsIndex $homePage, BrowserInterface $browser)
 {
     $category->persist();
     $homePage->open();
     $homePage->getTopmenu()->selectCategoryByName($category->getName());
     \PHPUnit_Framework_Assert::assertTrue(strpos($browser->getUrl(), 'index.php') === false, 'Apache redirect for category does not work.');
 }
 /**
  * Prepare data.
  *
  * @param Category $category
  * @param CatalogProductIndex $productGrid
  * @param CatalogProductEdit $editProductPage
  * @param FixtureFactory $fixtureFactory
  * @return void
  */
 public function __prepare(Category $category, CatalogProductIndex $productGrid, CatalogProductEdit $editProductPage, FixtureFactory $fixtureFactory)
 {
     $this->category = $category;
     $this->category->persist();
     $this->productGrid = $productGrid;
     $this->editProductPage = $editProductPage;
     $this->fixtureFactory = $fixtureFactory;
 }
Example #7
0
 /**
  * Add new category to product.
  *
  * @param Category $category
  * @return void
  */
 public function addNewCategory(Category $category)
 {
     $data = ['name' => $category->getName(), 'parent_category' => $category->getDataFieldConfig('parent_id')['source']->getParentCategory()->getName()];
     $this->openNewCategoryDialog();
     $this->_fill($this->dataMapping($data));
     $this->_rootElement->find($this->createCategoryButton)->click();
     $this->waitForElementNotVisible($this->createCategoryButton);
 }
 /**
  * Filtering product in the Frontend via layered navigation.
  *
  * @param string $configData
  * @param Category $category
  * @return array
  */
 public function test($configData, Category $category)
 {
     $this->configData = $configData;
     // Preconditions
     $this->objectManager->create('Magento\\Config\\Test\\TestStep\\SetupConfigurationStep', ['configData' => $this->configData])->run();
     // Steps
     $category->persist();
 }
Example #9
0
 /**
  * Select category by its name.
  *
  * @param Category|null $category
  * @return void
  */
 public function selectCategory($category)
 {
     if ($category != null && $category->hasData('name')) {
         $this->_rootElement->find("//a[contains(text(),'{$category->getName()}')]", Locator::SELECTOR_XPATH)->click();
     } else {
         $this->skipCategorySelection();
     }
 }
 /**
  * Assert that sitemap.xml file contains correct content according to dataset:
  *  - product url
  *  - category url
  *  - CMS page url
  *
  * @param CatalogProductSimple $product
  * @param Category $catalog
  * @param CmsPage $cmsPage
  * @param Sitemap $sitemap
  * @param SitemapIndex $sitemapIndex
  * @return void
  */
 public function processAssert(CatalogProductSimple $product, Category $catalog, CmsPage $cmsPage, Sitemap $sitemap, SitemapIndex $sitemapIndex)
 {
     $sitemapIndex->open()->getSitemapGrid()->sortGridByField('sitemap_id');
     $filter = ['sitemap_filename' => $sitemap->getSitemapFilename(), 'sitemap_path' => $sitemap->getSitemapPath()];
     $sitemapIndex->getSitemapGrid()->search($filter);
     $content = file_get_contents($sitemapIndex->getSitemapGrid()->getLinkForGoogle());
     $urls = [$_ENV['app_frontend_url'] . $product->getUrlKey() . '.html', $_ENV['app_frontend_url'] . $catalog->getUrlKey() . '.html', $_ENV['app_frontend_url'] . $cmsPage->getIdentifier()];
     \PHPUnit_Framework_Assert::assertTrue($this->checkContent($content, $urls), 'Content of file sitemap.xml does not include one or more of next urls:' . implode("\n", $urls));
 }
 /**
  * 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.");
     }
 }
 /**
  * Prepare datasets and pages
  *
  * @param UrlRewriteIndex $urlRewriteIndex
  * @param UrlRewriteEdit $urlRewriteEdit
  * @param FixtureFactory $fixtureFactory
  * @param Category $category
  * @return array
  */
 public function __inject(UrlRewriteIndex $urlRewriteIndex, UrlRewriteEdit $urlRewriteEdit, FixtureFactory $fixtureFactory, Category $category)
 {
     $this->urlRewriteIndex = $urlRewriteIndex;
     $this->urlRewriteEdit = $urlRewriteEdit;
     $category->persist();
     $categoryRedirect = $fixtureFactory->createByCode('urlRewrite', ['dataset' => 'default', 'data' => ['target_path' => $category->getUrlKey() . '.html']]);
     $categoryRedirect->persist();
     return ['categoryRedirect' => $categoryRedirect, 'category' => $category];
 }
Example #13
0
 /**
  * Prepare category path.
  *
  * @param Category $category
  * @return array
  */
 protected function prepareFullCategoryPath(Category $category)
 {
     $path = [];
     $parentCategory = $category->hasData('parent_id') ? $category->getDataFieldConfig('parent_id')['source']->getParentCategory() : null;
     if ($parentCategory !== null) {
         $path = $this->prepareFullCategoryPath($parentCategory);
     }
     return array_filter(array_merge($path, [$category->getName()]));
 }
Example #14
0
 /**
  * Verify category on the frontend
  *
  * @param Category $category
  */
 protected function assertCategoryOnFrontend(Category $category)
 {
     //Open created category on frontend
     $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex();
     $frontendHomePage->open();
     $navigationMenu = $frontendHomePage->getTopmenu();
     $navigationMenu->selectCategoryByName($category->getCategoryName());
     $this->assertEquals($category->getCategoryName(), $frontendHomePage->getTitleBlock()->getTitle());
 }
 /**
  * Delete category.
  *
  * @param Category $category
  * @return void
  */
 public function test(Category $category)
 {
     $category->persist();
     $this->catalogCategoryIndex->open();
     $this->catalogCategoryIndex->getTreeCategories()->selectCategory($category);
     if ($this->catalogCategoryEdit->getFormPageActions()->checkDeleteButton()) {
         $this->catalogCategoryEdit->getFormPageActions()->delete();
         $this->catalogCategoryEdit->getModalBlock()->acceptAlert();
     }
 }
 /**
  * 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.');
 }
 /**
  * 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);
 }
 /**
  * Get category url to open.
  *
  * @param Category $category
  * @return string
  */
 protected function getCategoryUrl(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 (1 == $category->getParentId()) {
             $category = null;
         }
     }
     return $_ENV['app_frontend_url'] . implode('/', array_reverse($categoryUrlKey)) . '.html';
 }
Example #19
0
 /**
  * @constructor
  * @param FixtureFactory $fixtureFactory
  * @param array $params
  * @param array|int $data
  */
 public function __construct(FixtureFactory $fixtureFactory, array $params, $data = [])
 {
     $this->params = $params;
     if (isset($data['dataSet']) && $data['dataSet'] !== '-') {
         $this->parentCategory = $fixtureFactory->createByCode('category', ['dataSet' => $data['dataSet']]);
         if (!$this->parentCategory->hasData('id')) {
             $this->parentCategory->persist();
         }
         $this->data = $this->parentCategory->getId();
     } else {
         $this->data = $data;
     }
 }
 /**
  * Prepare and return category breadcrumbs.
  *
  * @param Category $category
  * @return string
  */
 protected function getBreadcrumbs(Category $category)
 {
     $breadcrumbs = [];
     while ($category) {
         $breadcrumbs[] = $category->getName();
         $category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
         if ($category !== null && 1 == $category->getParentId()) {
             $category = null;
         }
     }
     $breadcrumbs[] = self::HOME_PAGE;
     return implode(' ', array_reverse($breadcrumbs));
 }
 /**
  * Assert that "Add to cart" button is not display 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()->getProductItem($product)->isVisible();
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible();
     }
     \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
     \PHPUnit_Framework_Assert::assertFalse($catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisibleAddToCardButton(), "Button 'Add to Card' is present on Category page.");
     $catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
     \PHPUnit_Framework_Assert::assertFalse($catalogProductView->getViewBlock()->isVisibleAddToCardButton(), "Button 'Add to Card' is present on Product page.");
 }
 /**
  * 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()->getProductItem($product)->isVisible();
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible();
     }
     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);
 }
 /**
  * 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;
 }
 /**
  * Assertion that filtered product list via layered navigation are displayed correctly.
  *
  * @param Category $category
  * @param CmsIndex $cmsIndex
  * @param CatalogCategoryView $catalogCategoryView
  * @param array $layeredNavigation
  * @return void
  */
 public function processAssert(Category $category, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, array $layeredNavigation)
 {
     $this->products = $category->getDataFieldConfig('category_products')['source']->getProducts();
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
     foreach ($layeredNavigation as $filters) {
         foreach ($filters as $filter) {
             $catalogCategoryView->getLayeredNavigationBlock()->applyFilter($filter['title'], $filter['linkPattern']);
             $productNames = $this->getProductNames($filter['products']);
             sort($productNames);
             $pageProductNames = $catalogCategoryView->getListProductBlock()->getProductNames();
             sort($pageProductNames);
             \PHPUnit_Framework_Assert::assertEquals($productNames, $pageProductNames);
         }
         $catalogCategoryView->getLayeredNavigationBlock()->clearAll();
     }
 }
 /**
  * Checking the product in the page of its price.
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param Category $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, Category $category)
 {
     // Open category view page and check visible product
     $categoryName = $category->getName();
     if ($product->hasData('category_ids')) {
         $categoryIds = $product->getCategoryIds();
         $categoryName = is_array($categoryIds) ? reset($categoryIds) : $categoryName;
     }
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible();
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible();
     }
     \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
     //Process price asserts
     $this->assertPrice($product, $catalogCategoryView);
 }
Example #26
0
 /**
  * Prepare category products data for curl.
  *
  * @return void
  */
 protected function prepareCategoryProducts()
 {
     $categoryProducts = [];
     $defaultPosition = 0;
     if ($this->fixture->hasData('category_products')) {
         $products = $this->fixture->getDataFieldConfig('category_products')['source']->getProducts();
         foreach ($products as $product) {
             $categoryProducts[$product->getId()] = $defaultPosition;
         }
     }
     $this->fields['category_products'] = json_encode($categoryProducts);
     unset($this->fields['general']['category_products']);
 }
 /**
  * Assert that the category is no longer available on the top menu bar
  *
  * @param CmsIndex $cmsIndex
  * @param Category $category
  * @param BrowserInterface $browser
  * @param CatalogCategoryView $categoryView
  * @return void
  */
 public function processAssert(CmsIndex $cmsIndex, Category $category, BrowserInterface $browser, CatalogCategoryView $categoryView)
 {
     $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($category->getName(), $categoryView->getTitleBlock()->getTitle(), 'Wrong page is displayed.');
     if (isset($category->getDataFieldConfig('category_products')['source'])) {
         $products = $category->getDataFieldConfig('category_products')['source']->getProducts();
         foreach ($products as $productFixture) {
             \PHPUnit_Framework_Assert::assertTrue($categoryView->getListProductBlock()->isProductVisible($productFixture->getName()), "Products '{$productFixture->getName()}' not find.");
         }
     }
 }
Example #28
0
 /**
  * Verify category Content data:
  * # Description
  * # CMS Block content
  *
  * @param array $categoryData
  * @return array
  */
 protected function verifyContent(array $categoryData)
 {
     $errorMessage = [];
     if (isset($categoryData['description'])) {
         $description = $this->categoryViewPage->getViewBlock()->getDescription();
         if ($categoryData['description'] != $description) {
             $errorMessage[] = 'Wrong category description.' . "\nExpected: " . $categoryData['description'] . "\nActual: " . $description;
         }
     }
     if (isset($categoryData['landing_page']) && isset($categoryData['display_mode']) && in_array($categoryData['display_mode'], $this->visibleCmsBlockMode)) {
         /** @var LandingPage $sourceLandingPage */
         $sourceLandingPage = $this->category->getDataFieldConfig('landing_page')['source'];
         $fixtureContent = $sourceLandingPage->getCmsBlock()->getContent();
         $pageContent = $this->categoryViewPage->getViewBlock()->getContent();
         if ($fixtureContent != $pageContent) {
             $errorMessage[] = 'Wrong category landing page content.' . "\nExpected: " . $fixtureContent . "\nActual: " . $pageContent;
         }
     }
     return $errorMessage;
 }
 /**
  * Prepare data.
  *
  * @param Category $category
  * @return array
  */
 public function __prepare(Category $category)
 {
     $category->persist();
     return ['category' => $category];
 }
 /**
  * Assert that url rewrite category in grid
  *
  * @param Category $category
  * @param UrlRewriteIndex $urlRewriteIndex
  * @return void
  */
 public function processAssert(Category $category, UrlRewriteIndex $urlRewriteIndex)
 {
     $urlRewriteIndex->open();
     $filter = ['target_path' => strtolower($category->getUrlKey())];
     \PHPUnit_Framework_Assert::assertTrue($urlRewriteIndex->getUrlRedirectGrid()->isRowVisible($filter, true, false), 'URL Rewrite with request path "' . $category->getUrlKey() . '" is absent in grid.');
 }