10
10
11
11
use Magento \UrlRewrite \Model \OptionProvider ;
12
12
use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
13
+ use Magento \CatalogUrlRewrite \Model \ProductUrlRewriteGenerator ;
13
14
14
15
/**
15
16
* @magentoAppArea adminhtml
@@ -25,7 +26,7 @@ protected function setUp()
25
26
}
26
27
27
28
/**
28
- * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories .php
29
+ * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories_with_products .php
29
30
* @magentoDbIsolation enabled
30
31
* @magentoAppIsolation enabled
31
32
*/
@@ -50,11 +51,56 @@ public function testGenerateUrlRewritesWithoutSaveHistory()
50
51
];
51
52
52
53
$ this ->assertResults ($ categoryExpectedResult , $ actualResults );
54
+
55
+ /** @var \Magento\Catalog\Model\ProductRepository $productRepository */
56
+ $ productRepository = $ this ->objectManager ->create (\Magento \Catalog \Model \ProductRepository::class);
57
+ $ product = $ productRepository ->get ('12345 ' );
58
+ $ productForTest = $ product ->getId ();
59
+
60
+ $ productFilter = [
61
+ UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE ,
62
+ UrlRewrite::ENTITY_ID => [$ productForTest ]
63
+ ];
64
+ $ actualResults = $ this ->getActualResults ($ productFilter );
65
+ $ productExpectedResult = [
66
+ [
67
+ 'simple-product-two.html ' ,
68
+ 'catalog/product/view/id/ ' . $ productForTest ,
69
+ 1 ,
70
+ 0
71
+ ],
72
+ [
73
+ 'new-url/category-1-1/category-1-1-1/simple-product-two.html ' ,
74
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/5 ' ,
75
+ 1 ,
76
+ 0
77
+ ],
78
+ [
79
+ 'new-url/simple-product-two.html ' ,
80
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/3 ' ,
81
+ 1 ,
82
+ 0
83
+ ],
84
+ [
85
+ 'new-url/category-1-1/simple-product-two.html ' ,
86
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/4 ' ,
87
+ 1 ,
88
+ 0
89
+ ],
90
+ [
91
+ '/simple-product-two.html ' ,
92
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/2 ' ,
93
+ 1 ,
94
+ 0
95
+ ]
96
+ ];
97
+
98
+ $ this ->assertResults ($ productExpectedResult , $ actualResults );
53
99
}
54
100
55
101
/**
56
102
* @magentoDbIsolation enabled
57
- * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories .php
103
+ * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories_with_products .php
58
104
* @magentoAppIsolation enabled
59
105
*/
60
106
public function testGenerateUrlRewritesWithSaveHistory ()
@@ -86,6 +132,69 @@ public function testGenerateUrlRewritesWithSaveHistory()
86
132
];
87
133
88
134
$ this ->assertResults ($ categoryExpectedResult , $ actualResults );
135
+
136
+ /** @var \Magento\Catalog\Model\ProductRepository $productRepository */
137
+ $ productRepository = $ this ->objectManager ->create (\Magento \Catalog \Model \ProductRepository::class);
138
+ $ product = $ productRepository ->get ('12345 ' );
139
+ $ productForTest = $ product ->getId ();
140
+
141
+ $ productFilter = [
142
+ UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE ,
143
+ UrlRewrite::ENTITY_ID => [$ productForTest ]
144
+ ];
145
+ $ actualResults = $ this ->getActualResults ($ productFilter );
146
+ $ productExpectedResult = [
147
+ [
148
+ 'simple-product-two.html ' ,
149
+ 'catalog/product/view/id/ ' . $ productForTest ,
150
+ 1 ,
151
+ 0
152
+ ],
153
+ [
154
+ 'new-url/category-1-1/category-1-1-1/simple-product-two.html ' ,
155
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/5 ' ,
156
+ 1 ,
157
+ 0
158
+ ],
159
+ [
160
+ 'category-1/category-1-1/category-1-1-1/simple-product-two.html ' ,
161
+ 'new-url/category-1-1/category-1-1-1/simple-product-two.html ' ,
162
+ 0 ,
163
+ OptionProvider::PERMANENT
164
+ ],
165
+ [
166
+ 'new-url/simple-product-two.html ' ,
167
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/3 ' ,
168
+ 1 ,
169
+ 0
170
+ ],
171
+ [
172
+ 'new-url/category-1-1/simple-product-two.html ' ,
173
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/4 ' ,
174
+ 1 ,
175
+ 0
176
+ ],
177
+ [
178
+ '/simple-product-two.html ' ,
179
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/2 ' ,
180
+ 1 ,
181
+ 0
182
+ ],
183
+ [
184
+ 'category-1/simple-product-two.html ' ,
185
+ 'new-url/simple-product-two.html ' ,
186
+ 0 ,
187
+ OptionProvider::PERMANENT
188
+ ],
189
+ [
190
+ 'category-1/category-1-1/simple-product-two.html ' ,
191
+ 'new-url/category-1-1/simple-product-two.html ' ,
192
+ 0 ,
193
+ OptionProvider::PERMANENT
194
+ ],
195
+ ];
196
+
197
+ $ this ->assertResults ($ productExpectedResult , $ actualResults );
89
198
}
90
199
91
200
/**
@@ -145,6 +254,7 @@ protected function getActualResults(array $filter)
145
254
*/
146
255
protected function assertResults ($ expected , $ actual )
147
256
{
257
+ $ this ->assertEquals (count ($ expected ), count ($ actual ), 'Number of rewrites does not match ' );
148
258
foreach ($ expected as $ row ) {
149
259
$ this ->assertContains (
150
260
$ row ,
0 commit comments