Skip to content

Commit f2c494f

Browse files
committed
MAGETWO-70651: Saving category create not valid url-rewrites
1 parent c947017 commit f2c494f

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryBasedProductRewriteGeneratorTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\Product;
1010
use Magento\CatalogUrlRewrite\Model\CategoryBasedProductRewriteGenerator;
1111
use Magento\CatalogUrlRewrite\Model\ProductScopeRewriteGenerator;
12+
use Magento\Catalog\Model\ResourceModel\Category\Collection;
1213

1314
/**
1415
* Class CategoryBasedProductRewriteGeneratorTest
@@ -41,6 +42,9 @@ public function testGenerationWithGlobalScope()
4142
$categoryMock = $this->getMockBuilder(Category::class)
4243
->disableOriginalConstructor()
4344
->getMock();
45+
$categoryCollectionMock = $this->getMockBuilder(Collection::class)
46+
->disableOriginalConstructor()
47+
->getMock();
4448
$productMock = $this->getMockBuilder(Product::class)
4549
->disableOriginalConstructor()
4650
->getMock();
@@ -54,13 +58,20 @@ public function testGenerationWithGlobalScope()
5458
$productMock->expects($this->once())
5559
->method('getStoreId')
5660
->willReturn($storeId);
61+
$productMock->expects($this->once())
62+
->method('getCategoryCollection')
63+
->willReturn($categoryCollectionMock);
64+
$categoryCollectionMock->expects($this->atLeastOnce())
65+
->method('addAttributeToSelect')
66+
->willReturnSelf();
67+
5768
$this->productScopeRewriteGeneratorMock->expects($this->once())
5869
->method('isGlobalScope')
5970
->with($storeId)
6071
->willReturn(true);
6172
$this->productScopeRewriteGeneratorMock->expects($this->once())
6273
->method('generateForGlobalScope')
63-
->with([$categoryMock], $productMock, $categoryId)
74+
->with($categoryCollectionMock, $productMock, $categoryId)
6475
->willReturn($urls);
6576

6677
$this->assertEquals($urls, $this->generator->generate($productMock, $categoryMock, $categoryId));
@@ -71,6 +82,9 @@ public function testGenerationWithSpecificStore()
7182
$categoryMock = $this->getMockBuilder(Category::class)
7283
->disableOriginalConstructor()
7384
->getMock();
85+
$categoryCollectionMock = $this->getMockBuilder(Collection::class)
86+
->disableOriginalConstructor()
87+
->getMock();
7488
$productMock = $this->getMockBuilder(Product::class)
7589
->disableOriginalConstructor()
7690
->getMock();
@@ -84,13 +98,20 @@ public function testGenerationWithSpecificStore()
8498
$productMock->expects($this->once())
8599
->method('getStoreId')
86100
->willReturn($storeId);
101+
$productMock->expects($this->once())
102+
->method('getCategoryCollection')
103+
->willReturn($categoryCollectionMock);
104+
$categoryCollectionMock->expects($this->atLeastOnce())
105+
->method('addAttributeToSelect')
106+
->willReturnSelf();
107+
87108
$this->productScopeRewriteGeneratorMock->expects($this->once())
88109
->method('isGlobalScope')
89110
->with($storeId)
90111
->willReturn(false);
91112
$this->productScopeRewriteGeneratorMock->expects($this->once())
92113
->method('generateForSpecificStoreView')
93-
->with($storeId, [$categoryMock], $productMock, $categoryId)
114+
->with($storeId, $categoryCollectionMock, $productMock, $categoryId)
94115
->willReturn($urls);
95116

96117
$this->assertEquals($urls, $this->generator->generate($productMock, $categoryMock, $categoryId));

0 commit comments

Comments
 (0)