MediaReferenceFieldHelpTest.php in Drupal 9
File
core/modules/media/tests/src/FunctionalJavascript/MediaReferenceFieldHelpTest.php
View source
<?php
namespace Drupal\Tests\media\FunctionalJavascript;
use Drupal\Component\Utility\Html;
class MediaReferenceFieldHelpTest extends MediaJavascriptTestBase {
protected $defaultTheme = 'stark';
public function testFieldCreationHelpText() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$type = $this
->drupalCreateContentType([
'type' => 'foo',
]);
$this
->drupalGet("/admin/structure/types/manage/{$type->id()}/fields/add-field");
$field_types = [
'file',
'image',
'field_ui:entity_reference:media',
];
$description_ids = array_map(function ($item) {
return '#edit-description-' . Html::cleanCssIdentifier($item);
}, $field_types);
$assert_session
->optionExists('edit-new-storage-type', 'boolean');
$page
->selectFieldOption('edit-new-storage-type', 'boolean');
foreach ($description_ids as $description_id) {
$this
->assertFalse($assert_session
->elementExists('css', $description_id)
->isVisible());
}
$help_text = 'Use Media reference fields for most files, images, audio, videos, and remote media. Use File or Image reference fields when creating your own media types, or for legacy files and images created before enabling the Media module.';
foreach ($field_types as $field_name) {
$assert_session
->optionExists('edit-new-storage-type', $field_name);
$page
->selectFieldOption('edit-new-storage-type', $field_name);
$field_description_element = $assert_session
->elementExists('css', '#edit-description-' . Html::cleanCssIdentifier($field_name));
$this
->assertTrue($field_description_element
->isVisible());
$this
->assertSame($help_text, $field_description_element
->getText());
}
}
}