You are here

public function ImageFieldTest::testImageField in GraphQL 8.3

Test a simple file field.

File

modules/graphql_core/tests/src/Kernel/Images/ImageFieldTest.php, line 37

Class

ImageFieldTest
Test file attachments.

Namespace

Drupal\Tests\graphql_core\Kernel\Images

Code

public function testImageField() {
  $a = $this
    ->createNode([
    'title' => 'Node A',
    'type' => 'test',
  ]);
  $a->image
    ->generateSampleItems(1);
  $a
    ->save();
  $style = ImageStyle::load('thumbnail');
  $dimensions = [
    'width' => $a->image[0]->width,
    'height' => $a->image[0]->height,
  ];
  $style
    ->transformDimensions($dimensions, $a->image[0]->entity
    ->getFileUri());
  $metadata = $this
    ->defaultCacheMetaData();
  $metadata
    ->addCacheTags([
    'file:1',
    'node:1',
    // TODO: Check metatags. Is the config metatag required?
    'config:image.style.thumbnail',
  ]);
  $this
    ->assertResults($this
    ->getQueryFromFile('image.gql'), [
    'path' => '/node/' . $a
      ->id(),
  ], [
    'route' => [
      'node' => [
        'image' => [
          [
            'alt' => $a->image->alt,
            'title' => $a->image->title,
            'entity' => [
              'url' => $a->image->entity
                ->createFileUrl(FALSE),
            ],
            'width' => $a->image[0]->width,
            'height' => $a->image[0]->height,
            'thumbnailImage' => [
              'url' => $style
                ->buildUrl($a->image->entity->uri->value),
              'width' => $dimensions['width'],
              'height' => $dimensions['height'],
            ],
          ],
        ],
      ],
    ],
  ], $metadata);
}