33 $this->urlRewriteFactory = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewriteFactory::class)
34 ->setMethods([
'create'])
35 ->disableOriginalConstructor()->getMock();
36 $this->urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
37 ->disableOriginalConstructor()->getMock();
38 $this->product = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
39 ->disableOriginalConstructor()->getMock();
40 $this->categoryRegistry = $this->getMockBuilder(\
Magento\CatalogUrlRewrite\Model\ObjectRegistry::class)
41 ->disableOriginalConstructor()->getMock();
42 $this->productUrlPathGenerator = $this->getMockBuilder(
43 \
Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator::class
44 )->disableOriginalConstructor()->getMock();
45 $this->canonicalUrlRewriteGenerator = (
new ObjectManager($this))->getObject(
46 \
Magento\CatalogUrlRewrite\Model\
Product\CanonicalUrlRewriteGenerator::class,
48 'productUrlPathGenerator' => $this->productUrlPathGenerator,
49 'urlRewriteFactory' => $this->urlRewriteFactory
56 $requestPath =
'simple-product.html';
59 $targetPath =
'catalog/product/view/id/' .
$productId;
61 $this->product->expects($this->any())->method(
'getId')->will($this->returnValue(
$productId));
62 $this->productUrlPathGenerator->expects($this->any())->method(
'getUrlPathWithSuffix')
63 ->will($this->returnValue($requestPath));
64 $this->productUrlPathGenerator->expects($this->any())->method(
'getCanonicalUrlPath')
65 ->will($this->returnValue($targetPath));
66 $this->categoryRegistry->expects($this->any())->method(
'getList')->will($this->returnValue([]));
68 $this->urlRewrite->expects($this->any())->method(
'setStoreId')->with(
$storeId)
69 ->will($this->returnSelf());
70 $this->urlRewrite->expects($this->any())->method(
'setEntityId')->with(
$productId)
71 ->will($this->returnSelf());
72 $this->urlRewrite->expects($this->any())->method(
'setEntityType')
74 $this->urlRewrite->expects($this->any())->method(
'setRequestPath')->with($requestPath)
75 ->will($this->returnSelf());
76 $this->urlRewrite->expects($this->any())->method(
'setTargetPath')->with($targetPath)
77 ->will($this->returnSelf());
78 $this->urlRewriteFactory->expects($this->any())->method(
'create')->will($this->returnValue($this->urlRewrite));
83 $this->canonicalUrlRewriteGenerator->generate(
$storeId, $this->product)
$canonicalUrlRewriteGenerator