/** * Creates a new child category for $parentCategory * * @param \Magento\Catalog\Model\Category $parentCategory * @return \Magento\Catalog\Model\Category */ protected function createCategory($parentCategory) { /** @var \Magento\Catalog\Model\Category $category */ $category = $this->objectManager->create('Magento\\Catalog\\Model\\Category'); $category->setStoreId(self::DEFAULT_STORE_ID)->setParentId($parentCategory->getId())->setName(self::NAMES_PREFIX . $this->titlesGenerator->generateCategoryTitle())->setAttributeSetId($category->getDefaultAttributeSetId())->setLevel($parentCategory->getLevel() + 1)->setPath($parentCategory->getPath())->setIsActive(1)->save(); return $category; }
/** * Checks that category title generator produces correct words count */ public function testGenerateCategoryTitle() { $wordsInCategory = 3; $categoryName = $this->namesGenerator->generateCategoryTitle(); $this->assertCount($wordsInCategory, explode(' ', $categoryName), "Category name should contain {$wordsInCategory} words. Current {$categoryName}"); }