File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
api-functional/testsuite/Magento/GraphQl/Catalog
integration/testsuite/Magento/Catalog/_files Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,38 @@ public function testCategoriesTree()
132
132
);
133
133
}
134
134
135
+ /**
136
+ * @magentoApiDataFixture Magento/Catalog/_files/category_with_parent_anchor.php
137
+ */
138
+ public function testCategoryTree ()
139
+ {
140
+ $ rootCategoryId = 2 ;
141
+ $ query = <<<QUERY
142
+ {
143
+ category(id: {$ rootCategoryId }) {
144
+ children {
145
+ id
146
+ name
147
+ children {
148
+ id
149
+ name
150
+ }
151
+ }
152
+ }
153
+ }
154
+ QUERY ;
155
+ $ response = $ this ->graphQlQuery ($ query );
156
+ $ responseDataObject = new DataObject ($ response );
157
+ self ::assertEquals (
158
+ 'Parent category ' ,
159
+ $ responseDataObject ->getData ('category/children/0/name ' )
160
+ );
161
+ self ::assertEquals (
162
+ 'Child category ' ,
163
+ $ responseDataObject ->getData ('category/children/0/children/0/name ' )
164
+ );
165
+ }
166
+
135
167
/**
136
168
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
137
169
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Original file line number Diff line number Diff line change 27
27
'is_anchor ' => true ,
28
28
];
29
29
$ parentCategory ->setData ($ parentCategoryData );
30
- $ parentCategoryId = $ categoryRepository ->save ($ parentCategory)-> getId ( );
30
+ $ parentCategory = $ categoryRepository ->save ($ parentCategory );
31
31
32
32
$ category = $ categoryFactory ->create ();
33
33
$ category ->isObjectNew (true );
34
34
$ categoryData = [
35
35
'name ' => 'Child category ' ,
36
36
'attribute_set_id ' => $ attributeSetId ,
37
- 'parent_id ' => $ parentCategoryId ,
37
+ 'parent_id ' => $ parentCategory -> getId () ,
38
38
'is_active ' => true ,
39
39
];
40
40
$ category ->setData ($ categoryData );
41
41
$ categoryRepository ->save ($ category );
42
+
43
+ //save parent category to set "children" attribute
44
+ $ categoryRepository ->save ($ parentCategory );
You can’t perform that action at this time.
0 commit comments