Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / media / tests / src / Kernel / OEmbedIframeControllerTest.php
diff --git a/web/core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php b/web/core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php
new file mode 100644 (file)
index 0000000..84fe439
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+namespace Drupal\Tests\media\Kernel;
+
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * @coversDefaultClass \Drupal\media\Controller\OEmbedIframeController
+ *
+ * @group media
+ */
+class OEmbedIframeControllerTest extends MediaKernelTestBase {
+
+  /**
+   * Data provider for testBadHashParameter().
+   *
+   * @return array
+   */
+  public function providerBadHashParameter() {
+    return [
+      'no hash' => [
+        '',
+      ],
+      'invalid hash' => [
+        $this->randomString(),
+      ],
+    ];
+  }
+
+  /**
+   * Tests validation of the 'hash' query string parameter.
+   *
+   * @param string $hash
+   *   The 'hash' query string parameter.
+   *
+   * @dataProvider providerBadHashParameter
+   *
+   * @covers ::render
+   */
+  public function testBadHashParameter($hash) {
+    /** @var callable $controller */
+    $controller = $this->container
+      ->get('controller_resolver')
+      ->getControllerFromDefinition('\Drupal\media\Controller\OEmbedIframeController::render');
+
+    $this->assertInternalType('callable', $controller);
+
+    $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException', 'This resource is not available');
+    $request = new Request([
+      'url' => 'https://example.com/path/to/resource',
+      'hash' => $hash,
+    ]);
+    $controller($request);
+  }
+
+}