class MediaTemplateSuggestionsTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php \Drupal\Tests\media\Functional\MediaTemplateSuggestionsTest
- 9 core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php \Drupal\Tests\media\Functional\MediaTemplateSuggestionsTest
Tests media template suggestions.
@group media
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\media\Functional\MediaFunctionalTestBase uses MediaFunctionalTestTrait, MediaTypeCreationTrait
- class \Drupal\Tests\media\Functional\MediaTemplateSuggestionsTest
- class \Drupal\Tests\media\Functional\MediaFunctionalTestBase uses MediaFunctionalTestTrait, MediaTypeCreationTrait
Expanded class hierarchy of MediaTemplateSuggestionsTest
File
- core/
modules/ media/ tests/ src/ Functional/ MediaTemplateSuggestionsTest.php, line 12
Namespace
Drupal\Tests\media\FunctionalView source
class MediaTemplateSuggestionsTest extends MediaFunctionalTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'media',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests template suggestions from media_theme_suggestions_media().
*/
public function testMediaThemeHookSuggestions() {
$media_type = $this
->createMediaType('test', [
'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
->assertSame($suggestions, [
'media__full',
'media__' . $media_type
->id(),
'media__' . $media_type
->id() . '__full',
'media__source_' . $media_type
->getSource()
->getPluginId(),
], 'Found expected media suggestions.');
}
}