11
11
use Magento \Catalog \Api \CategoryRepositoryInterface ;
12
12
use Magento \Catalog \Api \Data \CategoryInterface ;
13
13
use Magento \Catalog \Api \Data \CategoryInterfaceFactory ;
14
+ use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory as CategoryCollectionFactory ;
14
15
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
15
16
use Magento \Framework \Acl \Builder ;
16
17
use Magento \Framework \ObjectManagerInterface ;
@@ -51,6 +52,9 @@ class CategoryRepositoryTest extends TestCase
51
52
/** @var ObjectManagerInterface */
52
53
private $ objectManager ;
53
54
55
+ /** @var CategoryCollectionFactory */
56
+ private $ categoryCollectionFactory ;
57
+
54
58
/**
55
59
* Sets up common objects.
56
60
*
@@ -64,6 +68,7 @@ protected function setUp()
64
68
$ this ->aclBuilder = $ this ->objectManager ->get (Builder::class);
65
69
$ this ->categoryFactory = $ this ->objectManager ->get (CategoryInterfaceFactory::class);
66
70
$ this ->productCollectionFactory = $ this ->objectManager ->get (CollectionFactory::class);
71
+ $ this ->categoryCollectionFactory = $ this ->objectManager ->create (CategoryCollectionFactory::class);
67
72
}
68
73
69
74
/**
@@ -127,20 +132,23 @@ public function testSaveDesign(): void
127
132
* @magentoAppArea adminhtml
128
133
* @return void
129
134
*/
130
- public function testDeleteCategory (): void
135
+ public function testCheckCategoryBehaviourAfterDelete (): void
131
136
{
132
137
$ productCollection = $ this ->productCollectionFactory ->create ();
133
- $ deletedCategories = [3 , 4 , 5 , 13 ];
134
- $ categoryCollection = $ this ->categoryFactory ->create ()->getCollection ()-> toArray ();
138
+ $ deletedCategories = [' 3 ' , ' 4 ' , ' 5 ' , ' 13 ' ];
139
+ $ categoryCollectionIds = $ this ->categoryCollectionFactory ->create ()->getAllIds ();
135
140
$ this ->repo ->deleteByIdentifier (3 );
136
- $ this ->assertEmpty (
137
- $ productCollection ->addCategoriesFilter (['in ' => $ deletedCategories ])->getItems (),
141
+ $ this ->assertEquals (
142
+ 0 ,
143
+ $ productCollection ->addCategoriesFilter (['in ' => $ deletedCategories ])->getSize (),
138
144
'The category-products relations was not deleted after category delete '
139
145
);
140
- $ newCategoryCollection = $ this ->categoryFactory ->create ()->getCollection ()->toArray ();
146
+ $ newCategoryCollectionIds = $ this ->categoryCollectionFactory ->create ()->getAllIds ();
147
+ $ difference = array_diff ($ categoryCollectionIds , $ newCategoryCollectionIds );
148
+ sort ($ difference );
141
149
$ this ->assertEquals (
142
150
$ deletedCategories ,
143
- array_keys ( array_diff_key ( $ categoryCollection , $ newCategoryCollection )) ,
151
+ $ difference ,
144
152
'Wrong categories was deleted '
145
153
);
146
154
}
0 commit comments