3 namespace Drupal\Tests\system\Functional\Render;
6 use Drupal\Tests\BrowserTestBase;
9 * Functional test verifying that render array throws 406 for non-HTML requests.
13 class RenderArrayNonHtmlSubscriberTest extends BrowserTestBase {
20 public static $modules = ['render_array_non_html_subscriber_test'];
23 * Tests handling of responses by events subscriber.
25 public function testResponses() {
26 // Test that event subscriber does not interfere with normal requests.
27 $url = Url::fromRoute('render_array_non_html_subscriber_test.render_array');
29 $this->drupalGet($url);
30 $this->assertSession()->statusCodeEquals(200);
31 $this->assertRaw(t('Controller response successfully rendered.'));
33 // Test that correct response code is returned for any non-HTML format.
34 foreach (['json', 'hal+json', 'xml', 'foo'] as $format) {
35 $url = Url::fromRoute('render_array_non_html_subscriber_test.render_array', [
39 $this->drupalGet($url);
40 $this->assertSession()->statusCodeEquals(406);
41 $this->assertNoRaw(t('Controller response successfully rendered.'));
44 // Test that event subscriber does not interfere with raw string responses.
45 $url = Url::fromRoute('render_array_non_html_subscriber_test.raw_string', [
49 $this->drupalGet($url);
50 $this->assertSession()->statusCodeEquals(200);
51 $this->assertRaw(t('Raw controller response.'));