88namespace Magento \Catalog \Block \Adminhtml \Category \Checkboxes ;
99
1010use 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 ;
1115use Magento \Framework \ObjectManagerInterface ;
1216use Magento \Framework \Serialize \SerializerInterface ;
1317use Magento \Framework \View \LayoutInterface ;
@@ -64,30 +68,34 @@ public function testSetGetCategoryIds(): void
6468 */
6569 public function testGetTreeJson (): void
6670 {
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)
6876 ->onlyMethods (['create ' ])
6977 ->disableOriginalConstructor ()
7078 ->getMock ();
7179
72- $ categoryMock = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Category::class)
80+ $ categoryMock = $ this ->getMockBuilder (Category::class)
7381 ->onlyMethods (['getCollection ' ])
7482 ->disableOriginalConstructor ()
7583 ->getMock ();
7684
7785 // create resource connection mock
78- $ resourceConnection = $ this ->getMockBuilder (\ Magento \ Framework \ App \ ResourceConnection::class)
86+ $ resourceConnection = $ this ->getMockBuilder (ResourceConnection::class)
7987 ->onlyMethods (['getTableName ' ])
8088 ->disableOriginalConstructor ()
8189 ->getMock ();
8290
8391 $ resourceConnection ->method ('getTableName ' )
84- ->willReturn (' catalog_category_product_index ' );
92+ ->willReturn ($ categoryTable );
8593
8694 $ categoryFactoryMock ->method ('create ' )
8795 ->willReturn ($ categoryMock );
8896
8997 $ categoryCollection = $ this ->objectManager ->create (
90- \ Magento \ Catalog \ Model \ ResourceModel \ Category \ Collection::class,
98+ Collection::class,
9199 [
92100 'resource ' => $ resourceConnection
93101 ]
@@ -97,7 +105,7 @@ public function testGetTreeJson(): void
97105 ->willReturn ($ categoryCollection );
98106
99107 $ treeObject = $ this ->objectManager ->create (
100- \ Magento \ Catalog \ Block \ Adminhtml \ Category \ Checkboxes \ Tree::class,
108+ Tree::class,
101109 [
102110 'categoryFactory ' => $ categoryFactoryMock
103111 ]
0 commit comments