Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Render / RenderArrayNonHtmlSubscriberTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Render;
4
5 use Drupal\Core\Url;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Functional test verifying that render array throws 406 for non-HTML requests.
10  *
11  * @group Render
12  */
13 class RenderArrayNonHtmlSubscriberTest extends BrowserTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['render_array_non_html_subscriber_test'];
21
22   /**
23    * Tests handling of responses by events subscriber.
24    */
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');
28
29     $this->drupalGet($url);
30     $this->assertSession()->statusCodeEquals(200);
31     $this->assertRaw(t('Controller response successfully rendered.'));
32
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', [
36         '_format' => $format,
37       ]);
38
39       $this->drupalGet($url);
40       $this->assertSession()->statusCodeEquals(406);
41       $this->assertNoRaw(t('Controller response successfully rendered.'));
42     }
43
44     // Test that event subscriber does not interfere with raw string responses.
45     $url = Url::fromRoute('render_array_non_html_subscriber_test.raw_string', [
46       '_format' => 'foo',
47     ]);
48
49     $this->drupalGet($url);
50     $this->assertSession()->statusCodeEquals(200);
51     $this->assertRaw(t('Raw controller response.'));
52   }
53
54 }