/** * @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; } }
/** * 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 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 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()])); }
/** * 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'; }
/** * 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']); }
/** * Prepare Category fixture with the updated data. * * @param Category $category * @param Category $initialCategory * @return Category */ protected function prepareCategory(Category $category, Category $initialCategory) { $parentCategory = $category->hasData('parent_id') ? $category->getDataFieldConfig('parent_id')['source']->getParentCategory() : $initialCategory->getDataFieldConfig('parent_id')['source']->getParentCategory(); $data = ['data' => array_merge($initialCategory->getData(), $category->getData(), ['parent_id' => ['source' => $parentCategory]])]; return $this->fixtureFactory->createByCode('category', $data); }
/** * 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'; }