public function ThunderTestTrait::getMediaByName in Thunder 6.2.x
Same name and namespace in other branches
- 6.1.x tests/src/Traits/ThunderTestTrait.php \Drupal\Tests\thunder\Traits\ThunderTestTrait::getMediaByName()
Get a media item from the database based on its name.
Parameters
string|\Drupal\Component\Render\MarkupInterface $name: A media name, usually generated by $this->randomMachineName().
bool $reset: (optional) Whether to reset the entity cache.
Return value
\Drupal\media\MediaInterface|bool A media entity matching $name.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
3 calls to ThunderTestTrait::getMediaByName()
- ArticleCreationTest::testCreateArticle in tests/
src/ FunctionalJavascript/ ArticleCreationTest.php - Test Creation of Article.
- FileRemoveButtonTest::testRemoveButtonGone in modules/
thunder_media/ tests/ src/ Functional/ FileRemoveButtonTest.php - Test for transliteration of file name.
- MediaGalleryModifyTest::testAddRemove in tests/
src/ FunctionalJavascript/ MediaGalleryModifyTest.php - Test add/remove Images in Gallery.
File
- tests/
src/ Traits/ ThunderTestTrait.php, line 240
Class
- ThunderTestTrait
- Use this trait to reuse an existing database.
Namespace
Drupal\Tests\thunder\TraitsCode
public function getMediaByName($name, $reset = FALSE) {
if ($reset) {
\Drupal::entityTypeManager()
->getStorage('media')
->resetCache();
}
// Cast MarkupInterface objects to string.
$name = (string) $name;
$medias = \Drupal::entityTypeManager()
->getStorage('media')
->loadByProperties([
'name' => $name,
]);
return reset($medias);
}