@@ -70,21 +70,19 @@ public function testCategoriesTree()
70
70
}
71
71
}
72
72
QUERY ;
73
-
74
73
// get customer ID token
75
74
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
76
75
$ customerTokenService = $ this ->objectManager ->create (
77
76
\Magento \Integration \Api \CustomerTokenServiceInterface::class
78
77
);
79
78
$ customerToken =
$ customerTokenService->
createCustomerAccessToken (
'[email protected] ' ,
'password ' );
80
-
81
79
$ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
82
80
$ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
83
81
$ responseDataObject = new DataObject ($ response );
84
82
//Some sort of smoke testing
85
83
self ::assertEquals (
86
- 'Ololo ' ,
87
- $ responseDataObject ->getData ('category/children/7 /children/1/description ' )
84
+ 'Its a description of Test Category 1.2 ' ,
85
+ $ responseDataObject ->getData ('category/children/0 /children/1/description ' )
88
86
);
89
87
self ::assertEquals (
90
88
'default-category ' ,
@@ -99,16 +97,52 @@ public function testCategoriesTree()
99
97
$ responseDataObject ->getData ('category/children/0/default_sort_by ' )
100
98
);
101
99
self ::assertCount (
102
- 8 ,
100
+ 7 ,
103
101
$ responseDataObject ->getData ('category/children ' )
104
102
);
105
103
self ::assertCount (
106
104
2 ,
107
- $ responseDataObject ->getData ('category/children/7/children ' )
105
+ $ responseDataObject ->getData ('category/children/0/children ' )
106
+ );
107
+ self ::assertEquals (
108
+ 13 ,
109
+ $ responseDataObject ->getData ('category/children/0/children/1/id ' )
110
+ );
111
+ }
112
+
113
+ /**
114
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
115
+ * @magentoApiDataFixture Magento/Catalog/_files/categories.php
116
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
117
+ */
118
+ public function testGetCategoryById ()
119
+ {
120
+ $ rootCategoryId = 13 ;
121
+ $ query = <<<QUERY
122
+ {
123
+ category(id: {$ rootCategoryId }) {
124
+ id
125
+ name
126
+ }
127
+ }
128
+ QUERY ;
129
+ // get customer ID token
130
+ /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
131
+ $ customerTokenService = $ this ->objectManager ->create (
132
+ \Magento \Integration \Api \CustomerTokenServiceInterface::class
108
133
);
134
+ $ customerToken =
$ customerTokenService->
createCustomerAccessToken (
'[email protected] ' ,
'password ' );
135
+ $ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
136
+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
137
+ $ responseDataObject = new DataObject ($ response );
138
+ //Some sort of smoke testing
109
139
self ::assertEquals (
110
- 5 ,
111
- $ responseDataObject ->getData ('category/children/7/children/1/children/0/id ' )
140
+ 'Category 1.2 ' ,
141
+ $ responseDataObject ->getData ('category/name ' )
142
+ );
143
+ self ::assertEquals (
144
+ 13 ,
145
+ $ responseDataObject ->getData ('category/id ' )
112
146
);
113
147
}
114
148
@@ -259,17 +293,14 @@ public function testCategoryProducts()
259
293
}
260
294
}
261
295
QUERY ;
262
-
263
296
$ response = $ this ->graphQlQuery ($ query );
264
297
$ this ->assertArrayHasKey ('products ' , $ response ['category ' ]);
265
298
$ this ->assertArrayHasKey ('total_count ' , $ response ['category ' ]['products ' ]);
266
299
$ this ->assertGreaterThanOrEqual (1 , $ response ['category ' ]['products ' ]['total_count ' ]);
267
300
$ this ->assertEquals (1 , $ response ['category ' ]['products ' ]['page_info ' ]['current_page ' ]);
268
301
$ this ->assertEquals (20 , $ response ['category ' ]['products ' ]['page_info ' ]['page_size ' ]);
269
-
270
302
$ this ->assertArrayHasKey ('sku ' , $ response ['category ' ]['products ' ]['items ' ][0 ]);
271
303
$ firstProductSku = $ response ['category ' ]['products ' ]['items ' ][0 ]['sku ' ];
272
-
273
304
/**
274
305
* @var ProductRepositoryInterface $productRepository
275
306
*/
@@ -279,7 +310,6 @@ public function testCategoryProducts()
279
310
$ this ->assertAttributes ($ response ['category ' ]['products ' ]['items ' ][0 ]);
280
311
$ this ->assertWebsites ($ firstProduct , $ response ['category ' ]['products ' ]['items ' ][0 ]['websites ' ]);
281
312
}
282
-
283
313
/**
284
314
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
285
315
*/
@@ -291,9 +321,7 @@ public function testAnchorCategory()
291
321
/** @var CategoryInterface $category */
292
322
$ category = $ categoryCollection ->getFirstItem ();
293
323
$ categoryId = $ category ->getId ();
294
-
295
324
$ this ->assertNotEmpty ($ categoryId , "Preconditions failed: category is not available. " );
296
-
297
325
$ query = <<<QUERY
298
326
{
299
327
category(id: {$ categoryId }) {
@@ -307,7 +335,6 @@ public function testAnchorCategory()
307
335
}
308
336
}
309
337
QUERY ;
310
-
311
338
$ response = $ this ->graphQlQuery ($ query );
312
339
$ expectedResponse = [
313
340
'category ' => [
@@ -331,7 +358,6 @@ public function testAnchorCategory()
331
358
*/
332
359
private function assertBaseFields ($ product , $ actualResponse )
333
360
{
334
-
335
361
$ assertionMap = [
336
362
['response_field ' => 'attribute_set_id ' , 'expected_value ' => $ product ->getAttributeSetId ()],
337
363
['response_field ' => 'created_at ' , 'expected_value ' => $ product ->getCreatedAt ()],
@@ -365,7 +391,6 @@ private function assertBaseFields($product, $actualResponse)
365
391
['response_field ' => 'type_id ' , 'expected_value ' => $ product ->getTypeId ()],
366
392
['response_field ' => 'updated_at ' , 'expected_value ' => $ product ->getUpdatedAt ()],
367
393
];
368
-
369
394
$ this ->assertResponseFields ($ actualResponse , $ assertionMap );
370
395
}
371
396
@@ -385,7 +410,6 @@ private function assertWebsites($product, $actualResponse)
385
410
'is_default ' => true ,
386
411
]
387
412
];
388
-
389
413
$ this ->assertEquals ($ actualResponse , $ assertionMap );
390
414
}
391
415
@@ -410,7 +434,6 @@ private function assertAttributes($actualResponse)
410
434
'special_from_date ' ,
411
435
'special_to_date ' ,
412
436
];
413
-
414
437
foreach ($ eavAttributes as $ eavAttribute ) {
415
438
$ this ->assertArrayHasKey ($ eavAttribute , $ actualResponse );
416
439
}
0 commit comments