6 declare(strict_types=1);
16 use PHPUnit_Framework_MockObject_MockObject as MockObject;
27 private $objectManager;
32 private $categoryUrlPathGenerator;
37 private $categoryUrlRewriteGenerator;
42 private $storeViewService;
52 private $categoryResource;
62 private $updateUrlPathPlugin;
70 $this->categoryUrlPathGenerator = $this->getMockBuilder(CategoryUrlPathGenerator::class)
71 ->disableOriginalConstructor()
72 ->setMethods([
'getUrlPath'])
74 $this->categoryUrlRewriteGenerator = $this->getMockBuilder(CategoryUrlRewriteGenerator::class)
75 ->disableOriginalConstructor()
76 ->setMethods([
'generate'])
78 $this->categoryResource = $this->getMockBuilder(CategoryResource::class)
79 ->disableOriginalConstructor()
80 ->setMethods([
'saveAttribute'])
82 $this->category = $this->getMockBuilder(Category::class)
83 ->disableOriginalConstructor()
89 'isInRootCategoryList',
97 $this->storeViewService = $this->getMockBuilder(StoreViewService::class)
98 ->disableOriginalConstructor()
99 ->setMethods([
'doesEntityHaveOverriddenUrlPathForStore'])
101 $this->urlPersist = $this->getMockBuilder(UrlPersistInterface::class)
102 ->disableOriginalConstructor()
103 ->setMethods([
'replace'])
104 ->getMockForAbstractClass();
106 $this->updateUrlPathPlugin = $this->objectManager->getObject(
109 'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator,
110 'categoryUrlRewriteGenerator' => $this->categoryUrlRewriteGenerator,
111 'urlPersist' => $this->urlPersist,
112 'storeViewService' => $this->storeViewService,
119 $this->category->expects($this->atLeastOnce())->method(
'getParentId')->willReturn(0);
120 $this->category->expects($this->atLeastOnce())->method(
'isObjectNew')->willReturn(
true);
121 $this->category->expects($this->atLeastOnce())->method(
'isInRootCategoryList')->willReturn(
false);
122 $this->category->expects($this->never())->method(
'getStoreIds');
125 $this->categoryResource,
126 $this->updateUrlPathPlugin->afterSave($this->categoryResource, $this->categoryResource, $this->category)
133 $categoryStoreIds = [0,1,2];
134 $generatedUrlPath =
'parent_category/child_category';
136 $this->categoryUrlPathGenerator
137 ->expects($this->once())
138 ->method(
'getUrlPath')
139 ->with($this->category)
140 ->willReturn($generatedUrlPath);
141 $this->category->expects($this->atLeastOnce())->method(
'getParentId')->willReturn($parentId);
142 $this->category->expects($this->atLeastOnce())->method(
'isObjectNew')->willReturn(
true);
143 $this->category->expects($this->atLeastOnce())->method(
'isInRootCategoryList')->willReturn(
false);
144 $this->category->expects($this->atLeastOnce())->method(
'getStoreIds')->willReturn($categoryStoreIds);
145 $this->category->expects($this->once())->method(
'setStoreId')->with($categoryStoreIds[2])->willReturnSelf();
146 $this->category->expects($this->once())->method(
'unsUrlPath')->willReturnSelf();
147 $this->category->expects($this->once())->method(
'setUrlPath')->with($generatedUrlPath)->willReturnSelf();
148 $this->storeViewService->expects($this->exactly(2))->method(
'doesEntityHaveOverriddenUrlPathForStore')
151 [$categoryStoreIds[1], $parentId,
'catalog_category',
false],
152 [$categoryStoreIds[2], $parentId,
'catalog_category',
true],
155 $this->categoryResource
156 ->expects($this->once())
157 ->method(
'saveAttribute')
158 ->with($this->category,
'url_path')
160 $generatedUrlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
161 ->disableOriginalConstructor()
163 $this->categoryUrlRewriteGenerator->expects($this->once())->method(
'generate')->with($this->category)
164 ->willReturn([$generatedUrlRewrite]);
165 $this->urlPersist->expects($this->once())->method(
'replace')->with([$generatedUrlRewrite])->willReturnSelf();
168 $this->categoryResource,
169 $this->updateUrlPathPlugin->afterSave($this->categoryResource, $this->categoryResource, $this->category)
testAroundSaveWithRootCategory()
testAroundSaveWithoutRootCategory()