class RenderArrayNonHtmlSubscriberTest
Same name in this branch
- main core/modules/system/tests/src/Functional/Render/RenderArrayNonHtmlSubscriberTest.php \Drupal\Tests\system\Functional\Render\RenderArrayNonHtmlSubscriberTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Render/RenderArrayNonHtmlSubscriberTest.php \Drupal\Tests\system\Functional\Render\RenderArrayNonHtmlSubscriberTest
- 10 core/modules/system/tests/src/Functional/Render/RenderArrayNonHtmlSubscriberTest.php \Drupal\Tests\system\Functional\Render\RenderArrayNonHtmlSubscriberTest
- 9 core/modules/system/tests/src/Functional/Render/RenderArrayNonHtmlSubscriberTest.php \Drupal\Tests\system\Functional\Render\RenderArrayNonHtmlSubscriberTest
- 8.9.x core/modules/system/tests/src/Functional/Render/RenderArrayNonHtmlSubscriberTest.php \Drupal\Tests\system\Functional\Render\RenderArrayNonHtmlSubscriberTest
- 11.x core/modules/system/tests/src/Kernel/Render/RenderArrayNonHtmlSubscriberTest.php \Drupal\Tests\system\Kernel\Render\RenderArrayNonHtmlSubscriberTest
Functional test verifying that render array throws 406 for non-HTML requests.
Attributes
#[Group('Render')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Kernel\Render\RenderArrayNonHtmlSubscriberTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of RenderArrayNonHtmlSubscriberTest
File
-
core/
modules/ system/ tests/ src/ Kernel/ Render/ RenderArrayNonHtmlSubscriberTest.php, line 15
Namespace
Drupal\Tests\system\Kernel\RenderView source
class RenderArrayNonHtmlSubscriberTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'render_array_non_html_subscriber_test',
];
/**
* Tests handling of responses by events subscriber.
*/
public function testResponses() : void {
// Test that event subscriber does not interfere with normal requests.
$url = Url::fromRoute('render_array_non_html_subscriber_test.render_array');
$this->drupalGet($url);
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains("Controller response successfully rendered.");
// Test that correct response code is returned for any non-HTML format.
foreach ([
'json',
'xml',
'foo',
] as $format) {
$url = Url::fromRoute('render_array_non_html_subscriber_test.render_array', [
'_format' => $format,
]);
$this->drupalGet($url);
$this->assertSession()
->statusCodeEquals(406);
$this->assertSession()
->pageTextNotContains("Controller response successfully rendered.");
}
// Test that event subscriber does not interfere with raw string responses.
$url = Url::fromRoute('render_array_non_html_subscriber_test.raw_string', [
'_format' => 'foo',
]);
$this->drupalGet($url);
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->responseContains("Raw controller response.");
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.