40 private $childCategory;
45 private $parentCategory;
49 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
50 $this->objectManagerHelper =
new ObjectManagerHelper($this);
52 $this->childCategory = $this->getMockBuilder(\
Magento\Catalog\Model\Category::class)
53 ->disableOriginalConstructor()
55 $this->childCategory->method(
'getId')->will($this->returnValue(self::CHILD_CATEGORY_ID));
56 $this->childCategory->method(
'getName')->will($this->returnValue(self::CHILD_CATEGORY_NAME));
57 $this->childCategory->method(
'getPath')->will($this->returnValue(
59 . self::CHILD_CATEGORY_ID
62 $this->parentCategory = $this->getMockBuilder(\
Magento\Catalog\Model\Category::class)
63 ->disableOriginalConstructor()
65 $this->parentCategory->method(
'getId')->will($this->returnValue(self::PARENT_CATEGORY_ID));
66 $this->parentCategory->method(
'getName')->will($this->returnValue(
'Parent'));
67 $this->parentCategory->method(
'getPath')->will($this->returnValue(self::PARENT_CATEGORY_ID));
70 $this->objectManagerHelper->getCollectionMock(
73 self::PARENT_CATEGORY_ID => $this->parentCategory,
74 self::CHILD_CATEGORY_ID => $this->childCategory,
82 ->method(
'getItemById')
83 ->will($this->returnValueMap(
$map));
85 ->method(
'addAttributeToSelect')
91 ->will($this->returnSelf());
93 $categoryColFactory = $this->createPartialMock(
100 $categoryFactory = $this->createPartialMock(\
Magento\Catalog\Model\CategoryFactory::class, [
'create']);
102 $categoryFactory->method(
'create')->will($this->returnValue($this->childCategory));
104 $this->categoryProcessor =
105 new \Magento\CatalogImportExport\Model\Import\Product\CategoryProcessor(
113 $categoriesSeparator =
',';
114 $categoryIds = $this->categoryProcessor->upsertCategories(self::CHILD_CATEGORY_NAME, $categoriesSeparator);
115 $this->assertArrayHasKey(self::CHILD_CATEGORY_ID, array_flip($categoryIds));
123 $exception = new \Magento\Framework\Exception\AlreadyExistsException();
124 $categoriesSeparator =
'/';
125 $categoryName =
'Exception Category';
126 $this->childCategory->method(
'save')->willThrowException($exception);
127 $this->categoryProcessor->upsertCategories($categoryName, $categoriesSeparator);
128 $this->assertNotEmpty($this->categoryProcessor->getFailedCategories());
133 $dummyFailedCategory = [
135 'category' =>
'dummy category',
136 'exception' =>
'dummy exception',
140 $this->
setPropertyValue($this->categoryProcessor,
'failedCategories', $dummyFailedCategory);
141 $this->assertCount(count($dummyFailedCategory), $this->categoryProcessor->getFailedCategories());
143 $this->categoryProcessor->clearFailedCategories();
144 $this->assertEmpty($this->categoryProcessor->getFailedCategories());
154 $categoryId =
'category_id';
155 $this->
setPropertyValue($this->categoryProcessor,
'categoriesCache', $categoriesCache);
157 $actualResult = $this->categoryProcessor->getCategoryById($categoryId);
158 $this->assertEquals($expectedResult, $actualResult);
168 '$categoriesCache' => [
169 'category_id' =>
'category_id value',
171 '$expectedResult' =>
'category_id value',
174 '$categoriesCache' => [],
175 '$expectedResult' =>
null,
189 $reflection = new \ReflectionClass(get_class($object));
190 $reflectionProperty = $reflection->getProperty($property);
191 $reflectionProperty->setAccessible(
true);
192 $reflectionProperty->setValue($object,
$value);
testGetCategoryById($categoriesCache, $expectedResult)
testUpsertCategoriesWithAlreadyExistsException()
testClearFailedCategories()
setPropertyValue(&$object, $property, $value)
const CHILD_CATEGORY_NAME
getCategoryByIdDataProvider()