8
8
namespace Magento \GraphQl \Catalog ;
9
9
10
10
use Magento \Catalog \Api \Data \CategoryInterface ;
11
+ use Magento \Catalog \Model \CategoryRepository ;
11
12
use Magento \Catalog \Model \ResourceModel \Category \Collection as CategoryCollection ;
12
13
use Magento \Framework \DataObject ;
13
14
use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
@@ -23,9 +24,15 @@ class CategoryTest extends GraphQlAbstract
23
24
*/
24
25
private $ objectManager ;
25
26
27
+ /**
28
+ * @var CategoryRepository
29
+ */
30
+ private $ categoryRepository ;
31
+
26
32
protected function setUp ()
27
33
{
28
34
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
35
+ $ this ->categoryRepository = $ this ->objectManager ->get (CategoryRepository::class);
29
36
}
30
37
31
38
/**
@@ -103,6 +110,42 @@ public function testCategoriesTree()
103
110
);
104
111
}
105
112
113
+ /**
114
+ * @magentoApiDataFixture Magento/Catalog/_files/categories.php
115
+ */
116
+ public function testCategoriesTreeWithDisabledCategory ()
117
+ {
118
+ $ category = $ this ->categoryRepository ->get (3 );
119
+ $ category ->setIsActive (false );
120
+ $ this ->categoryRepository ->save ($ category );
121
+
122
+ $ rootCategoryId = 2 ;
123
+ $ query = <<<QUERY
124
+ {
125
+ category(id: {$ rootCategoryId }) {
126
+ id
127
+ name
128
+ level
129
+ description
130
+ children {
131
+ id
132
+ name
133
+ productImagePreview: products(pageSize: 1) {
134
+ items {
135
+ id
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ QUERY ;
142
+ $ response = $ this ->graphQlQuery ($ query );
143
+
144
+ $ this ->assertArrayHasKey ('category ' , $ response );
145
+ $ this ->assertArrayHasKey ('children ' , $ response ['category ' ]);
146
+ $ this ->assertSame (6 , count ($ response ['category ' ]['children ' ]));
147
+ }
148
+
106
149
/**
107
150
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
108
151
*/
0 commit comments