Skip to content
Snippets Groups Projects
Commit 8f9e5be6 authored by Christopher C. Wells's avatar Christopher C. Wells Committed by Christopher C. Wells
Browse files

Issue #3227434 by wells: Implement basic tests

parent e309e15d
No related branches found
No related tags found
No related merge requests found
image_styles: []
jsonapi_image_styles.settings:
type: config_object
label: 'JSON:API Image Styles settings'
mapping:
image_styles:
type: sequence
label: 'Image styles'
description: 'Image styles to include in JSON:API responses.'
sequence:
type: string
label: 'Image style'
<?php
namespace Drupal\Tests\jsonapi_image_styles\Functional;
use Drupal\Component\Serialization\Json;
/**
* The test class for the main functionality.
*
* @group jsonapi_image_styles
*/
class JsonApiImageStylesFunctionalTest extends JsonApiImageStylesFunctionalTestBase {
/**
* Tests that only the configured image styles are on the JSON:API response.
*/
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->assertNotEmpty(array_column($styles, 'large'));
$this->assertNotEmpty(array_column($styles, 'thumbnail'));
$this->assertEmpty(array_column($styles, 'wide'));
$this->assertEmpty(array_column($styles, 'medium'));
}
}
<?php
namespace Drupal\Tests\jsonapi_image_styles\Functional;
use Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase;
/**
* Provides helper methods for the module's functional tests.
*
* @internal
*/
abstract class JsonApiImageStylesFunctionalTestBase extends JsonApiFunctionalTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'jsonapi_image_styles',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$config = \Drupal::configFactory()->getEditable('jsonapi_image_styles.settings');
$config->set('image_styles', [
'large' => 'large',
'thumbnail' => 'thumbnail',
]);
$config->save(TRUE);
$this->resetAll();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment