class RestExportTest
Same name and namespace in other branches
- 11.x core/modules/rest/tests/src/Kernel/Views/RestExportTest.php \Drupal\Tests\rest\Kernel\Views\RestExportTest
- 10 core/modules/rest/tests/src/Kernel/Views/RestExportTest.php \Drupal\Tests\rest\Kernel\Views\RestExportTest
- 8.9.x core/modules/rest/tests/src/Kernel/Views/RestExportTest.php \Drupal\Tests\rest\Kernel\Views\RestExportTest
Tests the REST export view display plugin.
@coversDefaultClass \Drupal\rest\Plugin\views\display\RestExport
@group rest
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\rest\Kernel\Views\RestExportTest extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of RestExportTest
File
-
core/
modules/ rest/ tests/ src/ Kernel/ Views/ RestExportTest.php, line 17
Namespace
Drupal\Tests\rest\Kernel\ViewsView source
class RestExportTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = [
'test_serializer_display_entity',
];
/**
* {@inheritdoc}
*/
protected static $modules = [
'rest_test_views',
'serialization',
'rest',
'entity_test',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
ViewTestData::createTestViews(static::class, [
'rest_test_views',
]);
$this->installEntitySchema('entity_test');
}
/**
* @covers ::buildResponse
*/
public function testBuildResponse() {
/** @var \Drupal\views\Entity\View $view */
$view = View::load('test_serializer_display_entity');
$display =& $view->getDisplay('rest_export_1');
$display['display_options']['defaults']['style'] = FALSE;
$display['display_options']['style']['type'] = 'serializer';
$display['display_options']['style']['options']['formats'] = [
'json',
'xml',
];
$view->save();
// No custom header should be set yet.
$response = RestExport::buildResponse('test_serializer_display_entity', 'rest_export_1', []);
$this->assertEmpty($response->headers
->get('Custom-Header'));
// Clear render cache.
/** @var \Drupal\Core\Cache\MemoryBackend $render_cache */
$render_cache = $this->container
->get('cache_factory')
->get('render');
$render_cache->deleteAll();
// A custom header should now be added.
// @see rest_test_views_views_post_execute()
$header = $this->randomString();
$this->container
->get('state')
->set('rest_test_views_set_header', $header);
$response = RestExport::buildResponse('test_serializer_display_entity', 'rest_export_1', []);
$this->assertEquals($header, $response->headers
->get('Custom-Header'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.