/**
  * Assert that the category cannot be accessed from the navigation bar in the frontend
  *
  * @param CmsIndex $cmsIndex
  * @param CatalogCategory $category
  * @param Browser $browser
  * @return void
  */
 public function processAssert(CmsIndex $cmsIndex, CatalogCategory $category, Browser $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.');
 }
 /**
  * Delete category
  *
  * @param CatalogCategory $category
  * @return void
  */
 public function test(CatalogCategory $category)
 {
     $category->persist();
     $this->catalogCategoryIndex->open();
     $this->catalogCategoryIndex->getTreeCategories()->selectCategory($category);
     $this->catalogCategoryEdit->getFormPageActions()->delete();
 }
 /**
  * Inject page end prepare default category
  *
  * @param CatalogCategory $initialCategory
  * @param CatalogCategoryIndex $catalogCategoryIndex
  * @param CatalogCategoryEdit $catalogCategoryEdit
  * @return array
  */
 public function __inject(CatalogCategory $initialCategory, CatalogCategoryIndex $catalogCategoryIndex, CatalogCategoryEdit $catalogCategoryEdit)
 {
     $this->catalogCategoryIndex = $catalogCategoryIndex;
     $this->catalogCategoryEdit = $catalogCategoryEdit;
     $initialCategory->persist();
     return ['initialCategory' => $initialCategory];
 }
 /**
  * Assert that displayed category data on category page equals to passed from fixture
  *
  * @param CatalogCategory $category
  * @param CatalogCategory $initialCategory
  * @param FixtureFactory $fixtureFactory
  * @param CatalogCategoryView $categoryView
  * @param Browser $browser
  * @return void
  */
 public function processAssert(CatalogCategory $category, CatalogCategory $initialCategory, FixtureFactory $fixtureFactory, CatalogCategoryView $categoryView, Browser $browser)
 {
     $product = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'default', 'data' => ['category_ids' => ['category' => $initialCategory]]]);
     $categoryData = array_merge($initialCategory->getData(), $category->getData());
     $product->persist();
     $url = $_ENV['app_frontend_url'] . strtolower($category->getUrlKey()) . '.html';
     $browser->open($url);
     \PHPUnit_Framework_Assert::assertEquals($url, $browser->getUrl(), 'Wrong page URL.' . "\nExpected: " . $url . "\nActual: " . $browser->getUrl());
     if (isset($categoryData['name'])) {
         $title = $categoryView->getTitleBlock()->getTitle();
         \PHPUnit_Framework_Assert::assertEquals($categoryData['name'], $title, 'Wrong page title.' . "\nExpected: " . $categoryData['name'] . "\nActual: " . $title);
     }
     if (isset($categoryData['description'])) {
         $description = $categoryView->getViewBlock()->getDescription();
         \PHPUnit_Framework_Assert::assertEquals($categoryData['description'], $description, 'Wrong category description.' . "\nExpected: " . $categoryData['description'] . "\nActual: " . $description);
     }
     if (isset($categoryData['default_sort_by'])) {
         $sortBy = strtolower($categoryData['default_sort_by']);
         $sortType = $categoryView->getTopToolbar()->getSelectSortType();
         \PHPUnit_Framework_Assert::assertEquals($sortBy, $sortType, 'Wrong sorting type.' . "\nExpected: " . $sortBy . "\nActual: " . $sortType);
     }
     if (isset($categoryData['available_sort_by'])) {
         $availableSortType = array_filter($categoryData['available_sort_by'], function (&$value) {
             return $value !== '-' && ucfirst($value);
         });
         if ($availableSortType) {
             $availableSortType = array_values($availableSortType);
             $availableSortTypeOnPage = $categoryView->getTopToolbar()->getSortType();
             \PHPUnit_Framework_Assert::assertEquals($availableSortType, $availableSortTypeOnPage, 'Wrong available sorting type.' . "\nExpected: " . implode(PHP_EOL, $availableSortType) . "\nActual: " . implode(PHP_EOL, $availableSortTypeOnPage));
         }
     }
 }
 /**
  * Assert configurable product, corresponds to the category page
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param CatalogProductConfigurable $configurable
  * @param CatalogCategory $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, CatalogProductConfigurable $configurable, CatalogCategory $category)
 {
     //Open category view page
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
     //process asserts
     $this->assertPrice($configurable, $catalogCategoryView);
 }
 /**
  * Assert that displayed assigned products on category page equals passed from fixture
  *
  * @param CatalogCategory $category
  * @param CatalogCategoryView $categoryView
  * @param Browser $browser
  * @return void
  */
 public function processAssert(CatalogCategory $category, CatalogCategoryView $categoryView, Browser $browser)
 {
     $browser->open($_ENV['app_frontend_url'] . strtolower($category->getUrlKey()) . '.html');
     $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.");
     }
 }
 /**
  * Assert that sitemap.xml file contains correct content according to dataset:
  *  - product url
  *  - category url
  *  - CMS page url
  *
  * @param CatalogProductSimple $product
  * @param CatalogCategory $catalog
  * @param CmsPage $cmsPage
  * @param Sitemap $sitemap
  * @param SitemapIndex $sitemapIndex
  * @return void
  */
 public function processAssert(CatalogProductSimple $product, CatalogCategory $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));
 }
 /**
  * Prepare dataSets and pages
  *
  * @param UrlrewriteIndex $urlRewriteIndex
  * @param UrlrewriteEdit $urlRewriteEdit
  * @param FixtureFactory $fixtureFactory
  * @param CatalogCategory $category
  * @return array
  */
 public function __inject(UrlrewriteIndex $urlRewriteIndex, UrlrewriteEdit $urlRewriteEdit, FixtureFactory $fixtureFactory, CatalogCategory $category)
 {
     $this->urlRewriteIndex = $urlRewriteIndex;
     $this->urlRewriteEdit = $urlRewriteEdit;
     $category->persist();
     $categoryRedirect = $fixtureFactory->createByCode('urlRewrite', ['dataSet' => 'default', 'data' => ['id_path' => ['category/' . $category->getId()]]]);
     $categoryRedirect->persist();
     return ['categoryRedirect' => $categoryRedirect, 'category' => $category];
 }
 /**
  * Assert that product is not visible in the assigned category
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param CatalogCategory|null $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $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.');
 }
 /**
  * Update Sitemap Entity
  *
  * @param Sitemap $sitemap
  * @param CatalogProductSimple $product
  * @param CatalogCategory $catalog
  * @param CmsPage $cmsPage
  * @return void
  */
 public function testUpdateSitemap(Sitemap $sitemap, CatalogProductSimple $product, CatalogCategory $catalog, CmsPage $cmsPage)
 {
     // Preconditions
     $sitemap->persist();
     $product->persist();
     $catalog->persist();
     $cmsPage->persist();
     $filter = ['sitemap_filename' => $sitemap->getSitemapFilename(), 'sitemap_path' => $sitemap->getSitemapPath(), 'sitemap_id' => $sitemap->getSitemapId()];
     // Steps
     $this->sitemapIndex->open()->getSitemapGrid()->search($filter);
     $this->sitemapIndex->getSitemapGrid()->generate();
 }
 /**
  * Checking the product in the page of its price
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param CatalogCategory $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $category)
 {
     // Open category view page and check visible product
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     while (!$isProductVisible && $catalogCategoryView->getToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
     //Process price asserts
     $this->assertPrice($product, $catalogCategoryView);
 }
Exemple #12
0
 /**
  * @constructor
  * @param FixtureFactory $fixtureFactory
  * @param array $params
  * @param array|int $data
  */
 public function __construct(FixtureFactory $fixtureFactory, array $params, $data = [])
 {
     $this->params = $params;
     if ($data['dataSet']) {
         $this->parentCategory = $fixtureFactory->createByCode('catalogCategory', ['dataSet' => $data['dataSet']]);
         if (!$this->parentCategory->hasData('id')) {
             $this->parentCategory->persist();
         }
         $this->data = $this->parentCategory->getId();
     } else {
         $this->data = $data;
     }
 }
 /**
  * Assert that product is visible in the assigned category
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param CatalogCategory|null $category
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $category = null)
 {
     $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName();
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     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;
 }
 /**
  * Assert that product is visible in the assigned category
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param CatalogCategory $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $category)
 {
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     while (!$isProductVisible && $catalogCategoryView->getToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     $isInStock = $product->getQuantityAndStockStatus();
     if ($product->getVisibility() === 'Search' || isset($isInStock['is_in_stock']) && $isInStock['is_in_stock'] === '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);
 }
Exemple #16
0
 /**
  * Select category
  *
  * @param FixtureInterface $fixture
  * @return void|null
  */
 protected function fillCategory(FixtureInterface $fixture)
 {
     // TODO should be removed after suggest widget implementation as typified element
     $categoryName = null;
     if (!empty($this->category)) {
         $categoryName = $this->category->getName();
     }
     if (empty($categoryName) && !$fixture instanceof InjectableFixture) {
         $categoryName = $fixture->getCategoryName();
     }
     if (empty($categoryName)) {
         return;
     }
     $category = $this->_rootElement->find(str_replace('%categoryName%', $categoryName, $this->categoryName), Locator::SELECTOR_XPATH);
     if (!$category->isVisible()) {
         $this->fillCategoryField($categoryName, 'category_ids-suggest', '//*[@id="attribute-category_ids-container"]');
     }
 }
 /**
  * Assert that the category is no longer available on the top menu bar
  *
  * @param CmsIndex $cmsIndex
  * @param CatalogCategory $category
  * @param Browser $browser
  * @param CatalogCategoryView $categoryView
  * @return void
  */
 public function processAssert(CmsIndex $cmsIndex, CatalogCategory $category, Browser $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.");
         }
     }
 }
 /**
  * Assert that not displayed category in frontend main menu
  *
  * @param Browser $browser
  * @param CatalogCategoryView $categoryView
  * @param CatalogCategory $category
  * @return void
  */
 public function processAssert(Browser $browser, CatalogCategoryView $categoryView, CatalogCategory $category)
 {
     $browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html');
     \PHPUnit_Framework_Assert::assertEquals(self::NOT_FOUND_MESSAGE, $categoryView->getTitleBlock()->getTitle(), 'Wrong page is displayed.');
 }
 /**
  * Generate Sitemap Entity
  *
  * @param Sitemap $sitemap
  * @param CatalogProductSimple $product
  * @param CatalogCategory $catalog
  * @param CmsPage $cmsPage
  * @return void
  */
 public function testGenerateSitemap(Sitemap $sitemap, CatalogProductSimple $product, CatalogCategory $catalog, CmsPage $cmsPage)
 {
     // Preconditions
     $product->persist();
     $catalog->persist();
     $cmsPage->persist();
     // Steps
     $this->sitemapIndex->open();
     $this->sitemapIndex->getGridPageActions()->addNew();
     $this->sitemapNew->getSitemapForm()->fill($sitemap);
     $this->sitemapNew->getSitemapPageActions()->saveAndGenerate();
 }
 /**
  * Assert check URL rewrite category redirect
  *
  * @param UrlRewrite $urlRewrite
  * @param CatalogCategory $category
  * @param Browser $browser
  * @return void
  */
 public function processAssert(UrlRewrite $urlRewrite, CatalogCategory $category, Browser $browser)
 {
     $browser->open($_ENV['app_frontend_url'] . $urlRewrite->getRequestPath());
     $url = $urlRewrite->getOptions() == 'No' ? $urlRewrite->getRequestPath() : $category->getUrlKey() . '.html';
     \PHPUnit_Framework_Assert::assertEquals($browser->getUrl(), $_ENV['app_frontend_url'] . $url, 'URL rewrite category redirect false.' . "\nExpected: " . $_ENV['app_frontend_url'] . $url . "\nActual: " . $browser->getUrl());
 }
 /**
  * Verifying that category present in Frontend with products
  *
  * @param CatalogCategory $category
  * @param array $products
  */
 protected function assertProductsOnCategory(CatalogCategory $category, array $products)
 {
     //Open created category on frontend
     $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex();
     $categoryPage = Factory::getPageFactory()->getCatalogCategoryView();
     $frontendHomePage->open();
     $navigationMenu = $frontendHomePage->getTopmenu();
     $navigationMenu->selectCategoryByName($category->getName());
     $this->assertEquals($category->getName(), $frontendHomePage->getTitleBlock()->getTitle());
     $productListBlock = $categoryPage->getListProductBlock();
     /** @var Product $product */
     foreach ($products as $product) {
         $this->assertTrue($productListBlock->isProductVisible($product->getName()), 'Product is absent on category page.');
     }
 }
Exemple #22
0
 /**
  * Prepare category path
  *
  * @param CatalogCategory $category
  * @return array
  */
 protected function prepareFullCategoryPath(CatalogCategory $category)
 {
     $path = [];
     $parentCategory = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
     if ($parentCategory != null) {
         $path = $this->prepareFullCategoryPath($parentCategory);
     }
     return array_filter(array_merge($path, [$category->getPath(), $category->getName()]));
 }
 /**
  * Persist category
  *
  * @param CatalogCategory $category
  * @return array
  */
 public function __prepare(CatalogCategory $category)
 {
     $category->persist();
     return ['category' => $category];
 }
 /**
  * Test check create category rewrites
  *
  * @param UrlRewrite $urlRewrite
  * @param CatalogCategory $category
  * @return void
  */
 public function testCreateCategoryRewrite(UrlRewrite $urlRewrite, CatalogCategory $category)
 {
     //Steps
     $this->urlRewriteIndex->open();
     $this->urlRewriteIndex->getPageActionsBlock()->addNew();
     $this->urlRewriteEdit->getTreeBlock()->selectCategory($category->getName());
     $this->urlRewriteEdit->getFormBlock()->fill($urlRewrite);
     $this->urlRewriteEdit->getPageMainActions()->save();
 }