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,57 @@ public function testGenerateUrlRewritesWithoutSaveHistory()
50
51
];
51
52
52
53
$ this ->assertResults ($ categoryExpectedResult , $ actualResults );
54
+
55
+ $ productIds = [];
56
+ foreach ($ category ->getProductCollection () as $ product ) {
57
+ $ productIds = $ product ->getId ();
58
+ }
59
+ $ this ->assertTrue (isset ($ productIds [0 ]), 'Product for testing does not exist ' );
60
+ $ productForTest = $ productIds [0 ];
61
+ $ productFilter = [
62
+ UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE ,
63
+ UrlRewrite::ENTITY_ID => [$ productForTest ]
64
+ ];
65
+ $ actualResults = $ this ->getActualResults ($ productFilter );
66
+ $ productExpectedResult = [
67
+ [
68
+ 'simple-product-two.html ' ,
69
+ 'catalog/product/view/id/ ' . $ productForTest ,
70
+ 1 ,
71
+ 0
72
+ ],
73
+ [
74
+ 'new-url/category-1-1/category-1-1-1/simple-product-two.html ' ,
75
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/5 ' ,
76
+ 1 ,
77
+ 0
78
+ ],
79
+ [
80
+ 'new-url/simple-product-two.html ' ,
81
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/3 ' ,
82
+ 1 ,
83
+ 0
84
+ ],
85
+ [
86
+ 'new-url/category-1-1/simple-product-two.html ' ,
87
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/4 ' ,
88
+ 1 ,
89
+ 0
90
+ ],
91
+ [
92
+ '/simple-product-two.html ' ,
93
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/2 ' ,
94
+ 1 ,
95
+ 0
96
+ ]
97
+ ];
98
+
99
+ $ this ->assertResults ($ productExpectedResult , $ actualResults );
53
100
}
54
101
55
102
/**
56
103
* @magentoDbIsolation enabled
57
- * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories .php
104
+ * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories_with_products .php
58
105
* @magentoAppIsolation enabled
59
106
*/
60
107
public function testGenerateUrlRewritesWithSaveHistory ()
@@ -86,6 +133,70 @@ public function testGenerateUrlRewritesWithSaveHistory()
86
133
];
87
134
88
135
$ this ->assertResults ($ categoryExpectedResult , $ actualResults );
136
+
137
+ $ productIds = [];
138
+ foreach ($ category ->getProductCollection () as $ product ) {
139
+ $ productIds = $ product ->getId ();
140
+ }
141
+ $ this ->assertTrue (isset ($ productIds [0 ]), 'Product for testing does not exist ' );
142
+ $ productForTest = $ productIds [0 ];
143
+ $ productFilter = [
144
+ UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE ,
145
+ UrlRewrite::ENTITY_ID => [$ productForTest ]
146
+ ];
147
+ $ actualResults = $ this ->getActualResults ($ productFilter );
148
+ $ productExpectedResult = [
149
+ [
150
+ 'simple-product-two.html ' ,
151
+ 'catalog/product/view/id/ ' . $ productForTest ,
152
+ 1 ,
153
+ 0
154
+ ],
155
+ [
156
+ 'new-url/category-1-1/category-1-1-1/simple-product-two.html ' ,
157
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/5 ' ,
158
+ 1 ,
159
+ 0
160
+ ],
161
+ [
162
+ 'category-1/category-1-1/category-1-1-1/simple-product-two.html ' ,
163
+ 'new-url/category-1-1/category-1-1-1/simple-product-two.html ' ,
164
+ 0 ,
165
+ OptionProvider::PERMANENT
166
+ ],
167
+ [
168
+ 'new-url/simple-product-two.html ' ,
169
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/3 ' ,
170
+ 1 ,
171
+ 0
172
+ ],
173
+ [
174
+ 'new-url/category-1-1/simple-product-two.html ' ,
175
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/4 ' ,
176
+ 1 ,
177
+ 0
178
+ ],
179
+ [
180
+ '/simple-product-two.html ' ,
181
+ 'catalog/product/view/id/ ' . $ productForTest . '/category/2 ' ,
182
+ 1 ,
183
+ 0
184
+ ],
185
+ [
186
+ 'category-1/simple-product-two.html ' ,
187
+ 'new-url/simple-product-two.html ' ,
188
+ 0 ,
189
+ OptionProvider::PERMANENT
190
+ ],
191
+ [
192
+ 'category-1/category-1-1/simple-product-two.html ' ,
193
+ 'new-url/category-1-1/simple-product-two.html ' ,
194
+ 0 ,
195
+ OptionProvider::PERMANENT
196
+ ],
197
+ ];
198
+
199
+ $ this ->assertResults ($ productExpectedResult , $ actualResults );
89
200
}
90
201
91
202
/**
@@ -145,6 +256,7 @@ protected function getActualResults(array $filter)
145
256
*/
146
257
protected function assertResults ($ expected , $ actual )
147
258
{
259
+ $ this ->assertEquals (count ($ expected ), count ($ actual ), 'Number of rewrites does not match ' );
148
260
foreach ($ expected as $ row ) {
149
261
$ this ->assertContains (
150
262
$ row ,
0 commit comments