3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \CatalogUrlRewrite \Test \Unit \Model \Product ;
7
9
10
+ use Magento \Catalog \Api \CategoryRepositoryInterface ;
11
+ use Magento \Catalog \Model \Product ;
12
+ use Magento \CatalogUrlRewrite \Model \ObjectRegistry ;
13
+ use Magento \CatalogUrlRewrite \Model \Product \AnchorUrlRewriteGenerator ;
14
+ use Magento \CatalogUrlRewrite \Model \ProductUrlPathGenerator ;
8
15
use Magento \CatalogUrlRewrite \Model \ProductUrlRewriteGenerator ;
9
16
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
17
+ use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
18
+ use Magento \UrlRewrite \Service \V1 \Data \UrlRewriteFactory ;
19
+ use PHPUnit \Framework \TestCase ;
20
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
10
21
11
- class AnchorUrlRewriteGeneratorTest extends \ PHPUnit \ Framework \ TestCase
22
+ class AnchorUrlRewriteGeneratorTest extends TestCase
12
23
{
13
- /** @var \Magento\CatalogUrlRewrite\Model\Product\ AnchorUrlRewriteGenerator */
24
+ /** @var AnchorUrlRewriteGenerator */
14
25
protected $ anchorUrlRewriteGenerator ;
15
26
16
- /** @var \Magento\CatalogUrlRewrite\Model\ ProductUrlPathGenerator|\PHPUnit_Framework_MockObject_MockObject */
27
+ /** @var ProductUrlPathGenerator|MockObject */
17
28
protected $ productUrlPathGenerator ;
18
29
19
- /** @var \Magento\Catalog\Model\ Product|\PHPUnit_Framework_MockObject_MockObject */
30
+ /** @var Product|MockObject */
20
31
protected $ product ;
21
32
22
- /** @var \Magento\Catalog\Api\ CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
33
+ /** @var CategoryRepositoryInterface|MockObject */
23
34
private $ categoryRepositoryInterface ;
24
35
25
- /** @var \Magento\CatalogUrlRewrite\Model\ ObjectRegistry|\PHPUnit_Framework_MockObject_MockObject */
36
+ /** @var ObjectRegistry|MockObject */
26
37
protected $ categoryRegistry ;
27
38
28
- /** @var \Magento\UrlRewrite\Service\V1\Data\ UrlRewriteFactory|\PHPUnit_Framework_MockObject_MockObject */
39
+ /** @var UrlRewriteFactory|MockObject */
29
40
protected $ urlRewriteFactory ;
30
41
31
- /** @var \Magento\ UrlRewrite\Service\V1\Data\UrlRewrite|\PHPUnit_Framework_MockObject_MockObject */
42
+ /** @var UrlRewrite|MockObject */
32
43
protected $ urlRewrite ;
33
44
45
+ /**
46
+ * @inheritDoc
47
+ */
34
48
protected function setUp ()
35
49
{
36
- $ this ->urlRewriteFactory = $ this ->getMockBuilder (\ Magento \ UrlRewrite \ Service \ V1 \ Data \ UrlRewriteFactory::class)
50
+ $ this ->urlRewriteFactory = $ this ->getMockBuilder (UrlRewriteFactory::class)
37
51
->setMethods (['create ' ])
38
52
->disableOriginalConstructor ()->getMock ();
39
- $ this ->urlRewrite = $ this ->getMockBuilder (\ Magento \ UrlRewrite \ Service \ V1 \ Data \ UrlRewrite::class)
53
+ $ this ->urlRewrite = $ this ->getMockBuilder (UrlRewrite::class)
40
54
->disableOriginalConstructor ()->getMock ();
41
- $ this ->product = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Product::class)
55
+ $ this ->product = $ this ->getMockBuilder (Product::class)
42
56
->disableOriginalConstructor ()->getMock ();
43
57
$ this ->categoryRepositoryInterface = $ this ->getMockBuilder (
44
- \ Magento \ Catalog \ Api \ CategoryRepositoryInterface::class
58
+ CategoryRepositoryInterface::class
45
59
)->disableOriginalConstructor ()->getMock ();
46
- $ this ->categoryRegistry = $ this ->getMockBuilder (\ Magento \ CatalogUrlRewrite \ Model \ ObjectRegistry::class)
60
+ $ this ->categoryRegistry = $ this ->getMockBuilder (ObjectRegistry::class)
47
61
->disableOriginalConstructor ()->getMock ();
48
62
$ this ->productUrlPathGenerator = $ this ->getMockBuilder (
49
- \ Magento \ CatalogUrlRewrite \ Model \ ProductUrlPathGenerator::class
63
+ ProductUrlPathGenerator::class
50
64
)->disableOriginalConstructor ()->getMock ();
51
65
$ this ->anchorUrlRewriteGenerator = (new ObjectManager ($ this ))->getObject (
52
- \ Magento \ CatalogUrlRewrite \ Model \ Product \ AnchorUrlRewriteGenerator::class,
66
+ AnchorUrlRewriteGenerator::class,
53
67
[
54
68
'productUrlPathGenerator ' => $ this ->productUrlPathGenerator ,
55
69
'urlRewriteFactory ' => $ this ->urlRewriteFactory ,
@@ -58,7 +72,12 @@ protected function setUp()
58
72
);
59
73
}
60
74
61
- public function testGenerateEmpty ()
75
+ /**
76
+ * Verify generate if category registry list is empty.
77
+ *
78
+ * @return void
79
+ */
80
+ public function testGenerateEmpty (): void
62
81
{
63
82
$ this ->categoryRegistry ->expects ($ this ->any ())->method ('getList ' )->will ($ this ->returnValue ([]));
64
83
@@ -68,7 +87,12 @@ public function testGenerateEmpty()
68
87
);
69
88
}
70
89
71
- public function testGenerateCategories ()
90
+ /**
91
+ * Verify generate product rewrites for anchor categories.
92
+ *
93
+ * @return void
94
+ */
95
+ public function testGenerateCategories (): void
72
96
{
73
97
$ urlPathWithCategory = 'category1/category2/category3/simple-product.html ' ;
74
98
$ storeId = 10 ;
@@ -102,7 +126,7 @@ public function testGenerateCategories()
102
126
->withConsecutive (
103
127
[$ categoryIds [0 ], $ storeId ],
104
128
[$ categoryIds [1 ], $ storeId ],
105
- [$ categoryIds [2 ], $ storeId ],
129
+ [$ categoryIds [2 ], $ storeId ]
106
130
)
107
131
->will ($ this ->returnValue ($ category ));
108
132
$ this ->categoryRegistry ->expects ($ this ->any ())->method ('getList ' )
0 commit comments