summaryrefslogtreecommitdiffstats
path: root/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php')
-rw-r--r--core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php b/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php
new file mode 100644
index 0000000..e0e5294
--- /dev/null
+++ b/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\Tests\media\Functional;
+
+use Drupal\media\Entity\Media;
+
+/**
+ * Tests media template suggestions.
+ *
+ * @group media
+ */
+class MediaTemplateSuggestionsTest extends MediaFunctionalTestBase {
+
+ /**
+ * Modules to install.
+ *
+ * @var array
+ */
+ public static $modules = ['media'];
+
+ /**
+ * Tests template suggestions from media_theme_suggestions_media().
+ */
+ public function testMediaThemeHookSuggestions() {
+ $media_type = $this->createMediaType([
+ 'new_revision' => FALSE,
+ 'queue_thumbnail_downloads' => FALSE,
+ ]);
+
+ // Create media item to be rendered.
+ $media = Media::create([
+ 'bundle' => $media_type->id(),
+ 'name' => 'Unnamed',
+ ]);
+ $media->save();
+ $view_mode = 'full';
+
+ // Simulate theming of the media item.
+ $build = \Drupal::entityTypeManager()->getViewBuilder('media')->view($media, $view_mode);
+
+ $variables['elements'] = $build;
+ $suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_media', [$variables]);
+ $this->assertEquals($suggestions, ['media__full', 'media__' . $media_type->id(), 'media__' . $media_type->id() . '__full'], 'Found expected media suggestions.');
+ }
+
+}