Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / media / tests / modules / media_test_oembed / src / UrlResolver.php
diff --git a/web/core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php b/web/core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php
new file mode 100644 (file)
index 0000000..acfbf8c
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace Drupal\media_test_oembed;
+
+use Drupal\media\OEmbed\UrlResolver as BaseUrlResolver;
+
+/**
+ * Overrides the oEmbed URL resolver service for testing purposes.
+ */
+class UrlResolver extends BaseUrlResolver {
+
+  /**
+   * Sets the endpoint URL for an oEmbed resource URL.
+   *
+   * @param string $url
+   *   The resource URL.
+   * @param string $endpoint_url
+   *   The endpoint URL.
+   */
+  public static function setEndpointUrl($url, $endpoint_url) {
+    $urls = \Drupal::state()->get(static::class, []);
+    $urls[$url] = $endpoint_url;
+    \Drupal::state()->set(static::class, $urls);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getResourceUrl($url, $max_width = NULL, $max_height = NULL) {
+    $urls = \Drupal::state()->get(static::class, []);
+
+    if (isset($urls[$url])) {
+      return $urls[$url];
+    }
+    return parent::getResourceUrl($url, $max_width, $max_height);
+  }
+
+}