5
5
*/
6
6
namespace Magento \CatalogUrlRewrite \Test \Unit \Model ;
7
7
8
- use Magento \Catalog \Model \Category ;
9
8
use Magento \Catalog \Model \Product ;
9
+ use Magento \Catalog \Model \ResourceModel \Category \Collection ;
10
10
use Magento \CatalogUrlRewrite \Model \CategoryProductUrlPathGenerator ;
11
11
use Magento \CatalogUrlRewrite \Model \ProductScopeRewriteGenerator ;
12
- use Magento \Catalog \Model \ResourceModel \Category \Collection ;
12
+ use PHPUnit \Framework \MockObject \MockObject ;
13
+ use PHPUnit \Framework \TestCase ;
13
14
14
15
/**
15
- * Class CategoryProductUrlPathGeneratorTest
16
+ * Class test generate product url path
16
17
*/
17
- class CategoryProductUrlPathGeneratorTest extends \ PHPUnit \ Framework \ TestCase
18
+ class CategoryProductUrlPathGeneratorTest extends TestCase
18
19
{
19
20
/**
20
- * @var ProductScopeRewriteGenerator|\PHPUnit_Framework_MockObject_MockObject
21
+ * @var ProductScopeRewriteGenerator|MockObject
21
22
*/
22
23
private $ productScopeRewriteGeneratorMock ;
23
24
@@ -26,6 +27,9 @@ class CategoryProductUrlPathGeneratorTest extends \PHPUnit\Framework\TestCase
26
27
*/
27
28
private $ generator ;
28
29
30
+ /**
31
+ * @inheritdoc
32
+ */
29
33
public function setUp ()
30
34
{
31
35
$ this ->productScopeRewriteGeneratorMock = $ this ->getMockBuilder (ProductScopeRewriteGenerator::class)
@@ -37,11 +41,16 @@ public function setUp()
37
41
);
38
42
}
39
43
44
+ /**
45
+ * Test to generate product url rewrites based on all product categories on global scope
46
+ */
40
47
public function testGenerationWithGlobalScope ()
41
48
{
49
+ /** @var Collection|MockObject $categoryCollectionMock */
42
50
$ categoryCollectionMock = $ this ->getMockBuilder (Collection::class)
43
51
->disableOriginalConstructor ()
44
52
->getMock ();
53
+ /** @var Product|MockObject $productMock */
45
54
$ productMock = $ this ->getMockBuilder (Product::class)
46
55
->disableOriginalConstructor ()
47
56
->getMock ();
@@ -58,6 +67,10 @@ public function testGenerationWithGlobalScope()
58
67
$ productMock ->expects ($ this ->once ())
59
68
->method ('getCategoryCollection ' )
60
69
->willReturn ($ categoryCollectionMock );
70
+ $ categoryCollectionMock ->expects ($ this ->once ())
71
+ ->method ('setStoreId ' )
72
+ ->with ($ storeId )
73
+ ->willReturnSelf ();
61
74
$ categoryCollectionMock ->expects ($ this ->atLeastOnce ())
62
75
->method ('addAttributeToSelect ' )
63
76
->willReturnSelf ();
@@ -74,11 +87,16 @@ public function testGenerationWithGlobalScope()
74
87
$ this ->assertEquals ($ urls , $ this ->generator ->generate ($ productMock , $ categoryId ));
75
88
}
76
89
90
+ /**
91
+ * Test to generate product url rewrites based on all product categories on specific store
92
+ */
77
93
public function testGenerationWithSpecificStore ()
78
94
{
95
+ /** @var Collection|MockObject $categoryCollectionMock */
79
96
$ categoryCollectionMock = $ this ->getMockBuilder (Collection::class)
80
97
->disableOriginalConstructor ()
81
98
->getMock ();
99
+ /** @var Product|MockObject $productMock */
82
100
$ productMock = $ this ->getMockBuilder (Product::class)
83
101
->disableOriginalConstructor ()
84
102
->getMock ();
@@ -95,6 +113,10 @@ public function testGenerationWithSpecificStore()
95
113
$ productMock ->expects ($ this ->once ())
96
114
->method ('getCategoryCollection ' )
97
115
->willReturn ($ categoryCollectionMock );
116
+ $ categoryCollectionMock ->expects ($ this ->once ())
117
+ ->method ('setStoreId ' )
118
+ ->with ($ storeId )
119
+ ->willReturnSelf ();
98
120
$ categoryCollectionMock ->expects ($ this ->atLeastOnce ())
99
121
->method ('addAttributeToSelect ' )
100
122
->willReturnSelf ();
0 commit comments