@@ -22,6 +22,9 @@ class ProductUrlRewriteGeneratorTest extends \PHPUnit_Framework_TestCase
22
22
/** @var \PHPUnit_Framework_MockObject_MockObject */
23
23
protected $ categoriesUrlRewriteGenerator ;
24
24
25
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
26
+ protected $ anchorUrlRewriteGenerator ;
27
+
25
28
/** @var \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator */
26
29
protected $ productUrlRewriteGenerator ;
27
30
@@ -63,6 +66,9 @@ protected function setUp()
63
66
$ this ->categoriesUrlRewriteGenerator = $ this ->getMockBuilder (
64
67
'Magento\CatalogUrlRewrite\Model\Product\CategoriesUrlRewriteGenerator '
65
68
)->disableOriginalConstructor ()->getMock ();
69
+ $ this ->anchorUrlRewriteGenerator = $ this ->getMockBuilder (
70
+ 'Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator '
71
+ )->disableOriginalConstructor ()->getMock ();
66
72
$ this ->objectRegistryFactory = $ this ->getMockBuilder ('Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory ' )
67
73
->disableOriginalConstructor ()->setMethods (['create ' ])->getMock ();
68
74
$ this ->storeViewService = $ this ->getMockBuilder ('Magento\CatalogUrlRewrite\Service\V1\StoreViewService ' )
@@ -79,6 +85,11 @@ protected function setUp()
79
85
'storeManager ' => $ this ->storeManager ,
80
86
]
81
87
);
88
+
89
+ $ reflection = new \ReflectionClass (get_class ($ this ->productUrlRewriteGenerator ));
90
+ $ reflectionProperty = $ reflection ->getProperty ('anchorUrlRewriteGenerator ' );
91
+ $ reflectionProperty ->setAccessible (true );
92
+ $ reflectionProperty ->setValue ($ this ->productUrlRewriteGenerator , $ this ->anchorUrlRewriteGenerator );
82
93
}
83
94
84
95
/**
@@ -108,9 +119,19 @@ public function testGenerationForGlobalScope()
108
119
->setStoreId (3 );
109
120
$ this ->currentUrlRewritesRegenerator ->expects ($ this ->any ())->method ('generate ' )
110
121
->will ($ this ->returnValue ([$ current ]));
122
+ $ anchorCategories = new \Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ();
123
+ $ anchorCategories ->setTargetPath ('category-4 ' )
124
+ ->setStoreId (4 );
125
+ $ this ->anchorUrlRewriteGenerator ->expects ($ this ->any ())->method ('generate ' )
126
+ ->will ($ this ->returnValue ([$ anchorCategories ]));
111
127
112
128
$ this ->assertEquals (
113
- ['category-1-1 ' => $ canonical , 'category-2-2 ' => $ categories , 'category-3-3 ' => $ current ],
129
+ [
130
+ 'category-1-1 ' => $ canonical ,
131
+ 'category-2-2 ' => $ categories ,
132
+ 'category-3-3 ' => $ current ,
133
+ 'category-4-4 ' => $ anchorCategories
134
+ ],
114
135
$ this ->productUrlRewriteGenerator ->generate ($ this ->product )
115
136
);
116
137
}
@@ -143,6 +164,8 @@ public function testGenerationForSpecificStore()
143
164
->will ($ this ->returnValue ([]));
144
165
$ this ->currentUrlRewritesRegenerator ->expects ($ this ->any ())->method ('generate ' )
145
166
->will ($ this ->returnValue ([]));
167
+ $ this ->anchorUrlRewriteGenerator ->expects ($ this ->any ())->method ('generate ' )
168
+ ->will ($ this ->returnValue ([]));
146
169
147
170
$ this ->assertEquals (['category-1-1 ' => $ canonical ], $ this ->productUrlRewriteGenerator ->generate ($ this ->product ));
148
171
}
@@ -172,6 +195,8 @@ public function testSkipRootCategoryForCategoriesGenerator()
172
195
->will ($ this ->returnValue ([]));
173
196
$ this ->currentUrlRewritesRegenerator ->expects ($ this ->any ())->method ('generate ' )
174
197
->will ($ this ->returnValue ([]));
198
+ $ this ->anchorUrlRewriteGenerator ->expects ($ this ->any ())->method ('generate ' )
199
+ ->will ($ this ->returnValue ([]));
175
200
176
201
$ this ->assertEquals (['category-1-1 ' => $ canonical ], $ this ->productUrlRewriteGenerator ->generate ($ this ->product ));
177
202
}
@@ -201,6 +226,8 @@ public function testSkipGenerationForNotStoreRootCategory()
201
226
->will ($ this ->returnValue ([]));
202
227
$ this ->currentUrlRewritesRegenerator ->expects ($ this ->any ())->method ('generate ' )
203
228
->will ($ this ->returnValue ([]));
229
+ $ this ->anchorUrlRewriteGenerator ->expects ($ this ->any ())->method ('generate ' )
230
+ ->will ($ this ->returnValue ([]));
204
231
205
232
$ this ->assertEquals (['category-1-1 ' => $ canonical ], $ this ->productUrlRewriteGenerator ->generate ($ this ->product ));
206
233
}
0 commit comments