@@ -70,21 +70,19 @@ public function testCategoriesTree()
7070 }
7171}
7272QUERY ;
73-
7473 // get customer ID token
7574 /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
7675 $ customerTokenService = $ this ->objectManager ->create (
7776 \Magento \Integration \Api \CustomerTokenServiceInterface::class
7877 );
7978 $ customerToken =
$ customerTokenService->
createCustomerAccessToken (
'[email protected] ' ,
'password ' );
80-
8179 $ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
8280 $ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
8381 $ responseDataObject = new DataObject ($ response );
8482 //Some sort of smoke testing
8583 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 ' )
8886 );
8987 self ::assertEquals (
9088 'default-category ' ,
@@ -99,16 +97,52 @@ public function testCategoriesTree()
9997 $ responseDataObject ->getData ('category/children/0/default_sort_by ' )
10098 );
10199 self ::assertCount (
102- 8 ,
100+ 7 ,
103101 $ responseDataObject ->getData ('category/children ' )
104102 );
105103 self ::assertCount (
106104 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
108133 );
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
109139 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 ' )
112146 );
113147 }
114148
@@ -259,17 +293,14 @@ public function testCategoryProducts()
259293 }
260294}
261295QUERY ;
262-
263296 $ response = $ this ->graphQlQuery ($ query );
264297 $ this ->assertArrayHasKey ('products ' , $ response ['category ' ]);
265298 $ this ->assertArrayHasKey ('total_count ' , $ response ['category ' ]['products ' ]);
266299 $ this ->assertGreaterThanOrEqual (1 , $ response ['category ' ]['products ' ]['total_count ' ]);
267300 $ this ->assertEquals (1 , $ response ['category ' ]['products ' ]['page_info ' ]['current_page ' ]);
268301 $ this ->assertEquals (20 , $ response ['category ' ]['products ' ]['page_info ' ]['page_size ' ]);
269-
270302 $ this ->assertArrayHasKey ('sku ' , $ response ['category ' ]['products ' ]['items ' ][0 ]);
271303 $ firstProductSku = $ response ['category ' ]['products ' ]['items ' ][0 ]['sku ' ];
272-
273304 /**
274305 * @var ProductRepositoryInterface $productRepository
275306 */
@@ -279,7 +310,6 @@ public function testCategoryProducts()
279310 $ this ->assertAttributes ($ response ['category ' ]['products ' ]['items ' ][0 ]);
280311 $ this ->assertWebsites ($ firstProduct , $ response ['category ' ]['products ' ]['items ' ][0 ]['websites ' ]);
281312 }
282-
283313 /**
284314 * @magentoApiDataFixture Magento/Catalog/_files/categories.php
285315 */
@@ -291,9 +321,7 @@ public function testAnchorCategory()
291321 /** @var CategoryInterface $category */
292322 $ category = $ categoryCollection ->getFirstItem ();
293323 $ categoryId = $ category ->getId ();
294-
295324 $ this ->assertNotEmpty ($ categoryId , "Preconditions failed: category is not available. " );
296-
297325 $ query = <<<QUERY
298326{
299327 category(id: {$ categoryId }) {
@@ -307,7 +335,6 @@ public function testAnchorCategory()
307335 }
308336}
309337QUERY ;
310-
311338 $ response = $ this ->graphQlQuery ($ query );
312339 $ expectedResponse = [
313340 'category ' => [
@@ -331,7 +358,6 @@ public function testAnchorCategory()
331358 */
332359 private function assertBaseFields ($ product , $ actualResponse )
333360 {
334-
335361 $ assertionMap = [
336362 ['response_field ' => 'attribute_set_id ' , 'expected_value ' => $ product ->getAttributeSetId ()],
337363 ['response_field ' => 'created_at ' , 'expected_value ' => $ product ->getCreatedAt ()],
@@ -365,7 +391,6 @@ private function assertBaseFields($product, $actualResponse)
365391 ['response_field ' => 'type_id ' , 'expected_value ' => $ product ->getTypeId ()],
366392 ['response_field ' => 'updated_at ' , 'expected_value ' => $ product ->getUpdatedAt ()],
367393 ];
368-
369394 $ this ->assertResponseFields ($ actualResponse , $ assertionMap );
370395 }
371396
@@ -385,7 +410,6 @@ private function assertWebsites($product, $actualResponse)
385410 'is_default ' => true ,
386411 ]
387412 ];
388-
389413 $ this ->assertEquals ($ actualResponse , $ assertionMap );
390414 }
391415
@@ -410,7 +434,6 @@ private function assertAttributes($actualResponse)
410434 'special_from_date ' ,
411435 'special_to_date ' ,
412436 ];
413-
414437 foreach ($ eavAttributes as $ eavAttribute ) {
415438 $ this ->assertArrayHasKey ($ eavAttribute , $ actualResponse );
416439 }
0 commit comments