7
7
8
8
namespace Magento \GraphQl \Catalog ;
9
9
10
+ use Magento \Catalog \Api \Data \CategoryInterface ;
10
11
use Magento \Framework \DataObject ;
11
12
use Magento \TestFramework \TestCase \GraphQlAbstract ;
12
13
use Magento \Catalog \Api \Data \ProductInterface ;
@@ -285,10 +286,22 @@ public function testCategoryProducts()
285
286
*/
286
287
public function testAnchorCategory ()
287
288
{
288
- $ categoryId = 3 ;
289
+ /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */
290
+ $ categoryCollection = $ this ->objectManager ->create (
291
+ \Magento \Catalog \Model \ResourceModel \Category \Collection::class
292
+ );
293
+ $ categoryCollection ->addFieldToFilter ('name ' , 'Category 1 ' );
294
+ $ category = $ categoryCollection ->getFirstItem ();
295
+ /** @var \Magento\Framework\EntityManager\MetadataPool $entityManagerMetadataPool */
296
+ $ entityManagerMetadataPool = $ this ->objectManager ->create (\Magento \Framework \EntityManager \MetadataPool::class);
297
+ $ categoryLinkField = $ entityManagerMetadataPool ->getMetadata (CategoryInterface::class)->getLinkField ();
298
+ $ categoryId = $ category ->getData ($ categoryLinkField );
299
+ $ this ->assertNotEmpty ($ categoryId , "Preconditions failed: category is not available. " );
300
+
289
301
$ query = <<<QUERY
290
302
{
291
303
category(id: {$ categoryId }) {
304
+ name
292
305
products(sort: {sku: ASC}) {
293
306
total_count
294
307
items {
@@ -302,6 +315,7 @@ public function testAnchorCategory()
302
315
$ response = $ this ->graphQlQuery ($ query );
303
316
$ expectedResponse = [
304
317
'category ' => [
318
+ 'name ' => 'Category 1 ' ,
305
319
'products ' => [
306
320
'total_count ' => 3 ,
307
321
'items ' => [
0 commit comments