9
9
use Magento \Catalog \Model \Product ;
10
10
use Magento \CatalogUrlRewrite \Model \CategoryBasedProductRewriteGenerator ;
11
11
use Magento \CatalogUrlRewrite \Model \ProductScopeRewriteGenerator ;
12
+ use Magento \Catalog \Model \ResourceModel \Category \Collection ;
12
13
13
14
/**
14
15
* Class CategoryBasedProductRewriteGeneratorTest
@@ -41,6 +42,9 @@ public function testGenerationWithGlobalScope()
41
42
$ categoryMock = $ this ->getMockBuilder (Category::class)
42
43
->disableOriginalConstructor ()
43
44
->getMock ();
45
+ $ categoryCollectionMock = $ this ->getMockBuilder (Collection::class)
46
+ ->disableOriginalConstructor ()
47
+ ->getMock ();
44
48
$ productMock = $ this ->getMockBuilder (Product::class)
45
49
->disableOriginalConstructor ()
46
50
->getMock ();
@@ -54,13 +58,20 @@ public function testGenerationWithGlobalScope()
54
58
$ productMock ->expects ($ this ->once ())
55
59
->method ('getStoreId ' )
56
60
->willReturn ($ storeId );
61
+ $ productMock ->expects ($ this ->once ())
62
+ ->method ('getCategoryCollection ' )
63
+ ->willReturn ($ categoryCollectionMock );
64
+ $ categoryCollectionMock ->expects ($ this ->atLeastOnce ())
65
+ ->method ('addAttributeToSelect ' )
66
+ ->willReturnSelf ();
67
+
57
68
$ this ->productScopeRewriteGeneratorMock ->expects ($ this ->once ())
58
69
->method ('isGlobalScope ' )
59
70
->with ($ storeId )
60
71
->willReturn (true );
61
72
$ this ->productScopeRewriteGeneratorMock ->expects ($ this ->once ())
62
73
->method ('generateForGlobalScope ' )
63
- ->with ([ $ categoryMock ] , $ productMock , $ categoryId )
74
+ ->with ($ categoryCollectionMock , $ productMock , $ categoryId )
64
75
->willReturn ($ urls );
65
76
66
77
$ this ->assertEquals ($ urls , $ this ->generator ->generate ($ productMock , $ categoryMock , $ categoryId ));
@@ -71,6 +82,9 @@ public function testGenerationWithSpecificStore()
71
82
$ categoryMock = $ this ->getMockBuilder (Category::class)
72
83
->disableOriginalConstructor ()
73
84
->getMock ();
85
+ $ categoryCollectionMock = $ this ->getMockBuilder (Collection::class)
86
+ ->disableOriginalConstructor ()
87
+ ->getMock ();
74
88
$ productMock = $ this ->getMockBuilder (Product::class)
75
89
->disableOriginalConstructor ()
76
90
->getMock ();
@@ -84,13 +98,20 @@ public function testGenerationWithSpecificStore()
84
98
$ productMock ->expects ($ this ->once ())
85
99
->method ('getStoreId ' )
86
100
->willReturn ($ storeId );
101
+ $ productMock ->expects ($ this ->once ())
102
+ ->method ('getCategoryCollection ' )
103
+ ->willReturn ($ categoryCollectionMock );
104
+ $ categoryCollectionMock ->expects ($ this ->atLeastOnce ())
105
+ ->method ('addAttributeToSelect ' )
106
+ ->willReturnSelf ();
107
+
87
108
$ this ->productScopeRewriteGeneratorMock ->expects ($ this ->once ())
88
109
->method ('isGlobalScope ' )
89
110
->with ($ storeId )
90
111
->willReturn (false );
91
112
$ this ->productScopeRewriteGeneratorMock ->expects ($ this ->once ())
92
113
->method ('generateForSpecificStoreView ' )
93
- ->with ($ storeId , [ $ categoryMock ] , $ productMock , $ categoryId )
114
+ ->with ($ storeId , $ categoryCollectionMock , $ productMock , $ categoryId )
94
115
->willReturn ($ urls );
95
116
96
117
$ this ->assertEquals ($ urls , $ this ->generator ->generate ($ productMock , $ categoryMock , $ categoryId ));
0 commit comments