8
8
namespace Magento \Catalog \Block \Adminhtml \Category \Checkboxes ;
9
9
10
10
use Magento \Catalog \Helper \DefaultCategory ;
11
+ use Magento \Catalog \Model \CategoryFactory ;
12
+ use Magento \Catalog \Model \Category ;
13
+ use Magento \Catalog \Model \ResourceModel \Category \Collection ;
14
+ use Magento \Framework \App \ResourceConnection ;
11
15
use Magento \Framework \ObjectManagerInterface ;
12
16
use Magento \Framework \Serialize \SerializerInterface ;
13
17
use Magento \Framework \View \LayoutInterface ;
@@ -64,30 +68,34 @@ public function testSetGetCategoryIds(): void
64
68
*/
65
69
public function testGetTreeJson (): void
66
70
{
67
- $ categoryFactoryMock = $ this ->getMockBuilder (\Magento \Catalog \Model \CategoryFactory::class)
71
+ $ tablePrefix = $ this ->objectManager ->create (ResourceConnection::class)->getTablePrefix ();
72
+ $ categoryTable = 'catalog_category_product_index ' ;
73
+ $ categoryTable = $ tablePrefix ? $ tablePrefix . $ categoryTable : $ categoryTable ;
74
+
75
+ $ categoryFactoryMock = $ this ->getMockBuilder (CategoryFactory::class)
68
76
->onlyMethods (['create ' ])
69
77
->disableOriginalConstructor ()
70
78
->getMock ();
71
79
72
- $ categoryMock = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Category::class)
80
+ $ categoryMock = $ this ->getMockBuilder (Category::class)
73
81
->onlyMethods (['getCollection ' ])
74
82
->disableOriginalConstructor ()
75
83
->getMock ();
76
84
77
85
// create resource connection mock
78
- $ resourceConnection = $ this ->getMockBuilder (\ Magento \ Framework \ App \ ResourceConnection::class)
86
+ $ resourceConnection = $ this ->getMockBuilder (ResourceConnection::class)
79
87
->onlyMethods (['getTableName ' ])
80
88
->disableOriginalConstructor ()
81
89
->getMock ();
82
90
83
91
$ resourceConnection ->method ('getTableName ' )
84
- ->willReturn (' catalog_category_product_index ' );
92
+ ->willReturn ($ categoryTable );
85
93
86
94
$ categoryFactoryMock ->method ('create ' )
87
95
->willReturn ($ categoryMock );
88
96
89
97
$ categoryCollection = $ this ->objectManager ->create (
90
- \ Magento \ Catalog \ Model \ ResourceModel \ Category \ Collection::class,
98
+ Collection::class,
91
99
[
92
100
'resource ' => $ resourceConnection
93
101
]
@@ -97,7 +105,7 @@ public function testGetTreeJson(): void
97
105
->willReturn ($ categoryCollection );
98
106
99
107
$ treeObject = $ this ->objectManager ->create (
100
- \ Magento \ Catalog \ Block \ Adminhtml \ Category \ Checkboxes \ Tree::class,
108
+ Tree::class,
101
109
[
102
110
'categoryFactory ' => $ categoryFactoryMock
103
111
]
0 commit comments