34 $this->urlRewriteFactory = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewriteFactory::class)
35 ->setMethods([
'create'])
36 ->disableOriginalConstructor()->getMock();
37 $this->urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
38 ->disableOriginalConstructor()->getMock();
39 $this->product = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
40 ->disableOriginalConstructor()->getMock();
41 $this->categoryRegistry = $this->getMockBuilder(\
Magento\CatalogUrlRewrite\Model\ObjectRegistry::class)
42 ->disableOriginalConstructor()->getMock();
43 $this->productUrlPathGenerator = $this->getMockBuilder(
44 \
Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator::class
45 )->disableOriginalConstructor()->getMock();
46 $this->categoriesUrlRewriteGenerator = (
new ObjectManager($this))->getObject(
47 \
Magento\CatalogUrlRewrite\Model\
Product\CategoriesUrlRewriteGenerator::class,
49 'productUrlPathGenerator' => $this->productUrlPathGenerator,
50 'urlRewriteFactory' => $this->urlRewriteFactory
57 $this->categoryRegistry->expects($this->any())->method(
'getList')->will($this->returnValue([]));
61 $this->categoriesUrlRewriteGenerator->generate(1, $this->product, $this->categoryRegistry)
67 $urlPathWithCategory =
'category/simple-product.html';
70 $canonicalUrlPathWithCategory =
'canonical-path-with-category';
71 $categoryId =
'category_id';
73 $this->product->expects($this->any())->method(
'getId')->will($this->returnValue(
$productId));
74 $this->productUrlPathGenerator->expects($this->any())->method(
'getUrlPathWithSuffix')
75 ->will($this->returnValue($urlPathWithCategory));
76 $this->productUrlPathGenerator->expects($this->any())->method(
'getCanonicalUrlPath')
77 ->will($this->returnValue($canonicalUrlPathWithCategory));
79 $category->expects($this->any())->method(
'getId')->will($this->returnValue($categoryId));
80 $this->categoryRegistry->expects($this->any())->method(
'getList')
83 $this->urlRewrite->expects($this->any())->method(
'setStoreId')->with(
$storeId)
84 ->will($this->returnSelf());
85 $this->urlRewrite->expects($this->any())->method(
'setEntityId')->with(
$productId)
86 ->will($this->returnSelf());
87 $this->urlRewrite->expects($this->any())->method(
'setEntityType')
89 $this->urlRewrite->expects($this->any())->method(
'setRequestPath')->with($urlPathWithCategory)
90 ->will($this->returnSelf());
91 $this->urlRewrite->expects($this->any())->method(
'setTargetPath')->with($canonicalUrlPathWithCategory)
92 ->will($this->returnSelf());
93 $this->urlRewrite->expects($this->any())->method(
'setMetadata')
94 ->with([
'category_id' => $categoryId])->will($this->returnSelf());
95 $this->urlRewriteFactory->expects($this->any())->method(
'create')->will($this->returnValue($this->urlRewrite));
101 $this->categoriesUrlRewriteGenerator->generate(
$storeId, $this->product, $this->categoryRegistry)
$categoriesUrlRewriteGenerator