You are here

public function JsonApiImageStylesFunctionalTest::testImageStylesOnJsonApiResponse in JSON:API Image Styles 3.0.x

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/JsonApiImageStylesFunctionalTest.php \Drupal\Tests\jsonapi_image_styles\Functional\JsonApiImageStylesFunctionalTest::testImageStylesOnJsonApiResponse()

Tests that only the configured image styles are on the JSON:API response.

File

tests/src/Functional/JsonApiImageStylesFunctionalTest.php, line 17

Class

JsonApiImageStylesFunctionalTest
The test class for the main functionality.

Namespace

Drupal\Tests\jsonapi_image_styles\Functional

Code

public function testImageStylesOnJsonApiResponse() {
  $this
    ->createDefaultContent(1, 1, TRUE, TRUE, static::IS_NOT_MULTILINGUAL);
  $response = $this
    ->drupalGet('/jsonapi/node/article', [
    'query' => [
      'include' => 'field_image',
    ],
  ]);
  $output = Json::decode($response);
  $this
    ->assertArrayHasKey('image_style_uri', $output['included'][0]['attributes']);

  // Assert only the two configured image styles (large, thumbnail).
  $styles = $output['included'][0]['attributes']['image_style_uri'];
  $this
    ->assertCount(2, $styles);
  $this
    ->assertArrayHasKey('large', $styles);
  $this
    ->assertArrayHasKey('thumbnail', $styles);
  $this
    ->assertArrayNotHasKey('wide', $styles);
  $this
    ->assertArrayNotHasKey('medium', $styles);
}