/**
  * 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 found in category '{$category->getName()}'.");
     }
 }
 /**
  * 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.");
         }
     }
 }
 /**
  * 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.');
 }
 /**
  * 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.');
 }
 /**
  * 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.');
 }
 /**
  * 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;
 }
示例#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);
 }
示例#8
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();
     }
 }
示例#9
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()]));
 }
 /**
  * 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.');
 }
 /**
  * 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';
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * Get category url to open
  *
  * @param Category $category
  * @return string
  */
 protected function getCategoryUrl(Category $category)
 {
     $categoryUrlKey = $category->hasData('url_key') ? strtolower($category->getUrlKey()) : trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-');
     return $_ENV['app_frontend_url'] . $categoryUrlKey . '.html';
 }