Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Render / RenderArrayNonHtmlSubscriberTest.php
diff --git a/web/core/modules/system/tests/src/Functional/Render/RenderArrayNonHtmlSubscriberTest.php b/web/core/modules/system/tests/src/Functional/Render/RenderArrayNonHtmlSubscriberTest.php
new file mode 100644 (file)
index 0000000..08380de
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+namespace Drupal\Tests\system\Functional\Render;
+
+use Drupal\Core\Url;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Functional test verifying that render array throws 406 for non-HTML requests.
+ *
+ * @group Render
+ */
+class RenderArrayNonHtmlSubscriberTest extends BrowserTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['render_array_non_html_subscriber_test'];
+
+  /**
+   * Tests handling of responses by events subscriber.
+   */
+  public function testResponses() {
+    // 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->assertRaw(t('Controller response successfully rendered.'));
+
+    // Test that correct response code is returned for any non-HTML format.
+    foreach (['json', 'hal+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->assertNoRaw(t('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->assertRaw(t('Raw controller response.'));
+  }
+
+}