21 private $canonicalUrlRewriteGenerator;
24 private $currentUrlRewritesRegenerator;
27 private $categoriesUrlRewriteGenerator;
30 private $anchorUrlRewriteGenerator;
33 private $storeViewService;
36 private $objectRegistryFactory;
39 private $storeManager;
42 private $productScopeGenerator;
45 private $mergeDataProvider;
51 private $categoryMock;
55 $this->serializer = $this->createMock(\
Magento\Framework\
Serialize\Serializer\Json::class);
56 $this->serializer->expects($this->any())
60 return json_encode(
$value);
63 $this->serializer->expects($this->any())
64 ->method(
'unserialize')
67 return json_decode(
$value,
true);
71 $this->currentUrlRewritesRegenerator = $this->getMockBuilder(
72 \
Magento\CatalogUrlRewrite\Model\
Product\CurrentUrlRewritesRegenerator::class
73 )->disableOriginalConstructor()->getMock();
74 $this->canonicalUrlRewriteGenerator = $this->getMockBuilder(
75 \
Magento\CatalogUrlRewrite\Model\
Product\CanonicalUrlRewriteGenerator::class
76 )->disableOriginalConstructor()->getMock();
77 $this->categoriesUrlRewriteGenerator = $this->getMockBuilder(
78 \
Magento\CatalogUrlRewrite\Model\
Product\CategoriesUrlRewriteGenerator::class
79 )->disableOriginalConstructor()->getMock();
80 $this->anchorUrlRewriteGenerator = $this->getMockBuilder(
81 \
Magento\CatalogUrlRewrite\Model\
Product\AnchorUrlRewriteGenerator::class
82 )->disableOriginalConstructor()->getMock();
83 $this->objectRegistryFactory = $this->getMockBuilder(
84 \
Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory::class
85 )->disableOriginalConstructor()->setMethods([
'create'])->getMock();
86 $this->storeViewService = $this->getMockBuilder(\
Magento\CatalogUrlRewrite\Service\V1\StoreViewService::class)
87 ->disableOriginalConstructor()->getMock();
88 $this->storeManager = $this->createMock(StoreManagerInterface::class);
89 $storeRootCategoryId = 2;
90 $store = $this->getMockBuilder(\
Magento\
Store\Model\Store::class)->disableOriginalConstructor()->getMock();
91 $store->expects($this->any())->method(
'getRootCategoryId')->will($this->returnValue($storeRootCategoryId));
92 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue(
$store));
93 $mergeDataProviderFactory = $this->createPartialMock(
97 $this->mergeDataProvider = new \Magento\UrlRewrite\Model\MergeDataProvider();
98 $mergeDataProviderFactory->expects($this->once())->method(
'create')->willReturn($this->mergeDataProvider);
100 $this->productScopeGenerator = (
new ObjectManager($this))->getObject(
101 \
Magento\CatalogUrlRewrite\Model\ProductScopeRewriteGenerator::class,
103 'canonicalUrlRewriteGenerator' => $this->canonicalUrlRewriteGenerator,
104 'categoriesUrlRewriteGenerator' => $this->categoriesUrlRewriteGenerator,
105 'currentUrlRewritesRegenerator' => $this->currentUrlRewritesRegenerator,
106 'anchorUrlRewriteGenerator' => $this->anchorUrlRewriteGenerator,
107 'objectRegistryFactory' => $this->objectRegistryFactory,
108 'storeViewService' => $this->storeViewService,
109 'storeManager' => $this->storeManager,
110 'mergeDataProviderFactory' => $mergeDataProviderFactory
113 $this->categoryMock = $this->getMockBuilder(Category::class)->disableOriginalConstructor()->getMock();
119 $product->expects($this->any())->method(
'getStoreId')->will($this->returnValue(
null));
120 $product->expects($this->any())->method(
'getStoreIds')->will($this->returnValue([1]));
121 $this->storeViewService->expects($this->once())->method(
'doesEntityHaveOverriddenUrlKeyForStore')
122 ->will($this->returnValue(
false));
124 $canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
125 $canonical->setRequestPath(
'category-1')
127 $this->canonicalUrlRewriteGenerator->expects($this->any())->method(
'generate')
128 ->will($this->returnValue([$canonical]));
129 $categories = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
132 $this->categoriesUrlRewriteGenerator->expects($this->any())->method(
'generate')
134 $current = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
135 $current->setRequestPath(
'category-3')
137 $this->currentUrlRewritesRegenerator->expects($this->any())->method(
'generate')
138 ->will($this->returnValue([$current]));
139 $this->currentUrlRewritesRegenerator->expects($this->any())->method(
'generateAnchor')
140 ->will($this->returnValue([$current]));
141 $anchorCategories = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
142 $anchorCategories->setRequestPath(
'category-4')
144 $this->anchorUrlRewriteGenerator->expects($this->any())->method(
'generate')
145 ->will($this->returnValue([$anchorCategories]));
149 'category-1_1' => $canonical,
151 'category-3_3' => $current,
152 'category-4_4' => $anchorCategories
154 $this->productScopeGenerator->generateForGlobalScope([$this->categoryMock],
$product, 1)
160 $storeRootCategoryId = 2;
163 $product->expects($this->any())->method(
'getStoreId')->will($this->returnValue(1));
164 $product->expects($this->never())->method(
'getStoreIds');
165 $this->categoryMock->expects($this->any())->method(
'getParentIds')
166 ->will($this->returnValue([
'root-id', $storeRootCategoryId]));
167 $this->categoryMock->expects($this->any())->method(
'getId')->will($this->returnValue($category_id));
169 $canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
170 $canonical->setRequestPath(
'category-1')
172 $this->canonicalUrlRewriteGenerator->expects($this->any())->method(
'generate')
173 ->will($this->returnValue([$canonical]));
174 $this->categoriesUrlRewriteGenerator->expects($this->any())->method(
'generate')
175 ->will($this->returnValue([]));
176 $this->currentUrlRewritesRegenerator->expects($this->any())->method(
'generate')
177 ->will($this->returnValue([]));
178 $this->currentUrlRewritesRegenerator->expects($this->any())->method(
'generateAnchor')
179 ->will($this->returnValue([]));
180 $this->anchorUrlRewriteGenerator->expects($this->any())->method(
'generate')
181 ->will($this->returnValue([]));
184 [
'category-1_1' => $canonical],
185 $this->productScopeGenerator->generateForSpecificStoreView(1, [$this->categoryMock],
$product, 1)
195 $product->expects($this->any())->method(
'getStoreIds')->will($this->returnValue([1, 2]));
196 $this->storeViewService->expects($this->exactly(2))->method(
'doesEntityHaveOverriddenUrlKeyForStore')
197 ->will($this->returnValue(
true));
199 $this->assertEquals([], $this->productScopeGenerator->generateForGlobalScope([],
$product, 1));
207 $objectRegistry = $this->getMockBuilder(\
Magento\CatalogUrlRewrite\Model\ObjectRegistry::class)
208 ->disableOriginalConstructor()->getMock();
209 $this->objectRegistryFactory->expects($this->any())->method(
'create')
210 ->with([
'entities' => $entities])
211 ->will($this->returnValue($objectRegistry));
224 $this->categoryMock->expects(self::any())->method(
'getParentIds')->willReturn($parentIds);
225 $result = $this->productScopeGenerator->isCategoryProperForGenerating(
isCategoryProperForGeneratingDataProvider()
testGenerationForSpecificStore()
testGenerationForGlobalScope()
testSkipGenerationForGlobalScope()
initObjectRegistryFactory($entities)
testIsCategoryProperForGenerating($parentIds, $expectedResult)