77
88namespace Magento \CatalogUrlRewrite \Test \Unit \Model ;
99
10+ use Magento \Catalog \Api \ProductRepositoryInterface ;
11+ use Magento \Catalog \Model \Category ;
12+ use Magento \Catalog \Model \Product ;
13+ use Magento \CatalogUrlRewrite \Model \CategoryUrlPathGenerator ;
1014use Magento \CatalogUrlRewrite \Model \ProductUrlPathGenerator ;
15+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1116use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1217use Magento \Store \Model \ScopeInterface ;
18+ use Magento \Store \Model \StoreManagerInterface ;
19+ use PHPUnit \Framework \TestCase ;
20+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
1321
1422/**
15- * Class ProductUrlPathGeneratorTest
23+ * Verify ProductUrlPathGenerator class
1624 */
17- class ProductUrlPathGeneratorTest extends \ PHPUnit \ Framework \ TestCase
25+ class ProductUrlPathGeneratorTest extends TestCase
1826{
19- /** @var \Magento\CatalogUrlRewrite\Model\ ProductUrlPathGenerator */
27+ /** @var ProductUrlPathGenerator */
2028 protected $ productUrlPathGenerator ;
2129
22- /** @var \Magento\Store\Model\ StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
30+ /** @var StoreManagerInterface|MockObject */
2331 protected $ storeManager ;
2432
25- /** @var \Magento\Framework\App\Config\ ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
33+ /** @var ScopeConfigInterface|MockObject */
2634 protected $ scopeConfig ;
2735
28- /** @var \Magento\CatalogUrlRewrite\Model\ CategoryUrlPathGenerator|\PHPUnit_Framework_MockObject_MockObject */
36+ /** @var CategoryUrlPathGenerator|MockObject */
2937 protected $ categoryUrlPathGenerator ;
3038
31- /** @var \Magento\Catalog\Model\ Product|\PHPUnit_Framework_MockObject_MockObject */
39+ /** @var Product|MockObject */
3240 protected $ product ;
3341
34- /** @var \Magento\Catalog\Api\ ProductRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
42+ /** @var ProductRepositoryInterface|MockObject */
3543 protected $ productRepository ;
3644
37- /** @var \Magento\Catalog\Model\ Category|\PHPUnit_Framework_MockObject_MockObject */
45+ /** @var Category|MockObject */
3846 protected $ category ;
3947
4048 /**
4149 * @inheritdoc
4250 */
4351 protected function setUp (): void
4452 {
45- $ this ->category = $ this ->createMock (\ Magento \ Catalog \ Model \ Category::class);
53+ $ this ->category = $ this ->createMock (Category::class);
4654 $ productMethods = [
4755 '__wakeup ' ,
4856 'getData ' ,
@@ -54,17 +62,17 @@ protected function setUp(): void
5462 'setStoreId ' ,
5563 ];
5664
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);
6068 $ this ->categoryUrlPathGenerator = $ this ->createMock (
61- \ Magento \ CatalogUrlRewrite \ Model \ CategoryUrlPathGenerator::class
69+ CategoryUrlPathGenerator::class
6270 );
63- $ this ->productRepository = $ this ->createMock (\ Magento \ Catalog \ Api \ ProductRepositoryInterface::class);
71+ $ this ->productRepository = $ this ->createMock (ProductRepositoryInterface::class);
6472 $ this ->productRepository ->expects ($ this ->any ())->method ('getById ' )->willReturn ($ this ->product );
6573
6674 $ this ->productUrlPathGenerator = (new ObjectManager ($ this ))->getObject (
67- \ Magento \ CatalogUrlRewrite \ Model \ ProductUrlPathGenerator::class,
75+ ProductUrlPathGenerator::class,
6876 [
6977 'storeManager ' => $ this ->storeManager ,
7078 'scopeConfig ' => $ this ->scopeConfig ,
@@ -75,20 +83,24 @@ protected function setUp(): void
7583 }
7684
7785 /**
86+ * Data provider for testGetUrlPath.
87+ *
7888 * @return array
7989 */
8090 public function getUrlPathDataProvider (): array
8191 {
8292 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 ' ],
8595 'path based on product name 1 ' => ['' , 'product-name ' , 1 , 'product-name ' ],
8696 'path based on product name 2 ' => [null , 'product-name ' , 1 , 'product-name ' ],
8797 'path based on product name 3 ' => [false , 'product-name ' , 1 , 'product-name ' ]
8898 ];
8999 }
90100
91101 /**
102+ * Verify get url path.
103+ *
92104 * @dataProvider getUrlPathDataProvider
93105 * @param string|null|bool $urlKey
94106 * @param string|null|bool $productName
@@ -109,6 +121,8 @@ public function testGetUrlPath($urlKey, $productName, $formatterCalled, $result)
109121 }
110122
111123 /**
124+ * Verify get url key.
125+ *
112126 * @param string|bool $productUrlKey
113127 * @param string|bool $expectedUrlKey
114128 * @return void
@@ -122,6 +136,8 @@ public function testGetUrlKey($productUrlKey, $expectedUrlKey): void
122136 }
123137
124138 /**
139+ * Data provider for testGetUrlKey.
140+ *
125141 * @return array
126142 */
127143 public function getUrlKeyDataProvider (): array
@@ -133,6 +149,8 @@ public function getUrlKeyDataProvider(): array
133149 }
134150
135151 /**
152+ * Verify get url path with default utl key.
153+ *
136154 * @param string|null|bool $storedUrlKey
137155 * @param string|null|bool $productName
138156 * @param string $expectedUrlKey
@@ -150,6 +168,8 @@ public function testGetUrlPathDefaultUrlKey($storedUrlKey, $productName, $expect
150168 }
151169
152170 /**
171+ * Data provider for testGetUrlPathDefaultUrlKey.
172+ *
153173 * @return array
154174 */
155175 public function getUrlPathDefaultUrlKeyDataProvider (): array
@@ -161,6 +181,8 @@ public function getUrlPathDefaultUrlKeyDataProvider(): array
161181 }
162182
163183 /**
184+ * Verify get url path with category.
185+ *
164186 * @return void
165187 */
166188 public function testGetUrlPathWithCategory (): void
@@ -177,6 +199,8 @@ public function testGetUrlPathWithCategory(): void
177199 }
178200
179201 /**
202+ * Verify get url path with suffix.
203+ *
180204 * @return void
181205 */
182206 public function testGetUrlPathWithSuffix (): void
@@ -198,6 +222,8 @@ public function testGetUrlPathWithSuffix(): void
198222 }
199223
200224 /**
225+ * Verify get url path with suffix and category and store.
226+ *
201227 * @return void
202228 */
203229 public function testGetUrlPathWithSuffixAndCategoryAndStore (): void
@@ -219,6 +245,8 @@ public function testGetUrlPathWithSuffixAndCategoryAndStore(): void
219245 }
220246
221247 /**
248+ * Verify get canonical url path.
249+ *
222250 * @return void
223251 */
224252 public function testGetCanonicalUrlPath (): void
@@ -232,6 +260,8 @@ public function testGetCanonicalUrlPath(): void
232260 }
233261
234262 /**
263+ * Verify get canonical path with category.
264+ *
235265 * @return void
236266 */
237267 public function testGetCanonicalUrlPathWithCategory (): void
0 commit comments