7
7
8
8
namespace Magento \CatalogUrlRewrite \Test \Unit \Model ;
9
9
10
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
11
+ use Magento \Catalog \Model \Category ;
12
+ use Magento \Catalog \Model \Product ;
13
+ use Magento \CatalogUrlRewrite \Model \CategoryUrlPathGenerator ;
10
14
use Magento \CatalogUrlRewrite \Model \ProductUrlPathGenerator ;
15
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
11
16
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
17
use Magento \Store \Model \ScopeInterface ;
18
+ use Magento \Store \Model \StoreManagerInterface ;
19
+ use PHPUnit \Framework \TestCase ;
20
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
13
21
14
22
/**
15
- * Class ProductUrlPathGeneratorTest
23
+ * Verify ProductUrlPathGenerator class
16
24
*/
17
- class ProductUrlPathGeneratorTest extends \ PHPUnit \ Framework \ TestCase
25
+ class ProductUrlPathGeneratorTest extends TestCase
18
26
{
19
- /** @var \Magento\CatalogUrlRewrite\Model\ ProductUrlPathGenerator */
27
+ /** @var ProductUrlPathGenerator */
20
28
protected $ productUrlPathGenerator ;
21
29
22
- /** @var \Magento\Store\Model\ StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
30
+ /** @var StoreManagerInterface|MockObject */
23
31
protected $ storeManager ;
24
32
25
- /** @var \Magento\Framework\App\Config\ ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
33
+ /** @var ScopeConfigInterface|MockObject */
26
34
protected $ scopeConfig ;
27
35
28
- /** @var \Magento\CatalogUrlRewrite\Model\ CategoryUrlPathGenerator|\PHPUnit_Framework_MockObject_MockObject */
36
+ /** @var CategoryUrlPathGenerator|MockObject */
29
37
protected $ categoryUrlPathGenerator ;
30
38
31
- /** @var \Magento\Catalog\Model\ Product|\PHPUnit_Framework_MockObject_MockObject */
39
+ /** @var Product|MockObject */
32
40
protected $ product ;
33
41
34
- /** @var \Magento\Catalog\Api\ ProductRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
42
+ /** @var ProductRepositoryInterface|MockObject */
35
43
protected $ productRepository ;
36
44
37
- /** @var \Magento\Catalog\Model\ Category|\PHPUnit_Framework_MockObject_MockObject */
45
+ /** @var Category|MockObject */
38
46
protected $ category ;
39
47
40
48
/**
41
49
* @inheritdoc
42
50
*/
43
51
protected function setUp (): void
44
52
{
45
- $ this ->category = $ this ->createMock (\ Magento \ Catalog \ Model \ Category::class);
53
+ $ this ->category = $ this ->createMock (Category::class);
46
54
$ productMethods = [
47
55
'__wakeup ' ,
48
56
'getData ' ,
@@ -54,17 +62,17 @@ protected function setUp(): void
54
62
'setStoreId ' ,
55
63
];
56
64
57
- $ this ->product = $ this ->createPartialMock (\ Magento \ Catalog \ Model \ Product::class, $ productMethods );
58
- $ this ->storeManager = $ this ->createMock (\ Magento \ Store \ Model \ StoreManagerInterface::class);
59
- $ this ->scopeConfig = $ this ->createMock (\ Magento \ Framework \ App \ Config \ ScopeConfigInterface::class);
65
+ $ this ->product = $ this ->createPartialMock (Product::class, $ productMethods );
66
+ $ this ->storeManager = $ this ->createMock (StoreManagerInterface::class);
67
+ $ this ->scopeConfig = $ this ->createMock (ScopeConfigInterface::class);
60
68
$ this ->categoryUrlPathGenerator = $ this ->createMock (
61
- \ Magento \ CatalogUrlRewrite \ Model \ CategoryUrlPathGenerator::class
69
+ CategoryUrlPathGenerator::class
62
70
);
63
- $ this ->productRepository = $ this ->createMock (\ Magento \ Catalog \ Api \ ProductRepositoryInterface::class);
71
+ $ this ->productRepository = $ this ->createMock (ProductRepositoryInterface::class);
64
72
$ this ->productRepository ->expects ($ this ->any ())->method ('getById ' )->willReturn ($ this ->product );
65
73
66
74
$ this ->productUrlPathGenerator = (new ObjectManager ($ this ))->getObject (
67
- \ Magento \ CatalogUrlRewrite \ Model \ ProductUrlPathGenerator::class,
75
+ ProductUrlPathGenerator::class,
68
76
[
69
77
'storeManager ' => $ this ->storeManager ,
70
78
'scopeConfig ' => $ this ->scopeConfig ,
@@ -75,20 +83,24 @@ protected function setUp(): void
75
83
}
76
84
77
85
/**
86
+ * Data provider for testGetUrlPath.
87
+ *
78
88
* @return array
79
89
*/
80
90
public function getUrlPathDataProvider (): array
81
91
{
82
92
return [
83
- 'path based on url key uppercase ' => ['Url-Key ' , null , 0 , 'url-key ' ],
84
- 'path based on url key ' => ['url-key ' , null , 0 , 'url-key ' ],
93
+ 'path based on url key uppercase ' => ['Url-Key ' , null , 1 , 'url-key ' ],
94
+ 'path based on url key ' => ['url-key ' , null , 1 , 'url-key ' ],
85
95
'path based on product name 1 ' => ['' , 'product-name ' , 1 , 'product-name ' ],
86
96
'path based on product name 2 ' => [null , 'product-name ' , 1 , 'product-name ' ],
87
97
'path based on product name 3 ' => [false , 'product-name ' , 1 , 'product-name ' ]
88
98
];
89
99
}
90
100
91
101
/**
102
+ * Verify get url path.
103
+ *
92
104
* @dataProvider getUrlPathDataProvider
93
105
* @param string|null|bool $urlKey
94
106
* @param string|null|bool $productName
@@ -109,6 +121,8 @@ public function testGetUrlPath($urlKey, $productName, $formatterCalled, $result)
109
121
}
110
122
111
123
/**
124
+ * Verify get url key.
125
+ *
112
126
* @param string|bool $productUrlKey
113
127
* @param string|bool $expectedUrlKey
114
128
* @return void
@@ -122,6 +136,8 @@ public function testGetUrlKey($productUrlKey, $expectedUrlKey): void
122
136
}
123
137
124
138
/**
139
+ * Data provider for testGetUrlKey.
140
+ *
125
141
* @return array
126
142
*/
127
143
public function getUrlKeyDataProvider (): array
@@ -133,6 +149,8 @@ public function getUrlKeyDataProvider(): array
133
149
}
134
150
135
151
/**
152
+ * Verify get url path with default utl key.
153
+ *
136
154
* @param string|null|bool $storedUrlKey
137
155
* @param string|null|bool $productName
138
156
* @param string $expectedUrlKey
@@ -150,6 +168,8 @@ public function testGetUrlPathDefaultUrlKey($storedUrlKey, $productName, $expect
150
168
}
151
169
152
170
/**
171
+ * Data provider for testGetUrlPathDefaultUrlKey.
172
+ *
153
173
* @return array
154
174
*/
155
175
public function getUrlPathDefaultUrlKeyDataProvider (): array
@@ -161,6 +181,8 @@ public function getUrlPathDefaultUrlKeyDataProvider(): array
161
181
}
162
182
163
183
/**
184
+ * Verify get url path with category.
185
+ *
164
186
* @return void
165
187
*/
166
188
public function testGetUrlPathWithCategory (): void
@@ -177,6 +199,8 @@ public function testGetUrlPathWithCategory(): void
177
199
}
178
200
179
201
/**
202
+ * Verify get url path with suffix.
203
+ *
180
204
* @return void
181
205
*/
182
206
public function testGetUrlPathWithSuffix (): void
@@ -198,6 +222,8 @@ public function testGetUrlPathWithSuffix(): void
198
222
}
199
223
200
224
/**
225
+ * Verify get url path with suffix and category and store.
226
+ *
201
227
* @return void
202
228
*/
203
229
public function testGetUrlPathWithSuffixAndCategoryAndStore (): void
@@ -219,6 +245,8 @@ public function testGetUrlPathWithSuffixAndCategoryAndStore(): void
219
245
}
220
246
221
247
/**
248
+ * Verify get canonical url path.
249
+ *
222
250
* @return void
223
251
*/
224
252
public function testGetCanonicalUrlPath (): void
@@ -232,6 +260,8 @@ public function testGetCanonicalUrlPath(): void
232
260
}
233
261
234
262
/**
263
+ * Verify get canonical path with category.
264
+ *
235
265
* @return void
236
266
*/
237
267
public function testGetCanonicalUrlPathWithCategory (): void
0 commit comments