Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / media / tests / src / FunctionalJavascript / MediaReferenceFieldHelpTest.php
1 <?php
2
3 namespace Drupal\Tests\media\FunctionalJavascript;
4
5 use Drupal\Component\Utility\Html;
6
7 /**
8  * Tests related to media reference fields.
9  *
10  * @group media
11  */
12 class MediaReferenceFieldHelpTest extends MediaJavascriptTestBase {
13
14   /**
15    * Test our custom help texts when creating a field.
16    *
17    * @see media_form_field_ui_field_storage_add_form_alter()
18    */
19   public function testFieldCreationHelpText() {
20     $assert_session = $this->assertSession();
21     $page = $this->getSession()->getPage();
22
23     $type = $this->drupalCreateContentType([
24       'type' => 'foo',
25     ]);
26     $this->drupalGet("/admin/structure/types/manage/{$type->id()}/fields/add-field");
27
28     $field_types = [
29       'file',
30       'image',
31       'field_ui:entity_reference:media',
32     ];
33     $description_ids = array_map(function ($item) {
34       return '#edit-description-' . Html::cleanCssIdentifier($item);
35     }, $field_types);
36
37     // Choose a boolean field, none of the description containers should be
38     // visible.
39     $assert_session->optionExists('edit-new-storage-type', 'boolean');
40     $page->selectFieldOption('edit-new-storage-type', 'boolean');
41     foreach ($description_ids as $description_id) {
42       $this->assertFalse($assert_session->elementExists('css', $description_id)->isVisible());
43     }
44     // Select each of the file, image, and media fields and verify their
45     // descriptions are now visible and match the expected text.
46     $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.';
47     foreach ($field_types as $field_name) {
48       $assert_session->optionExists('edit-new-storage-type', $field_name);
49       $page->selectFieldOption('edit-new-storage-type', $field_name);
50       $field_description_element = $assert_session->elementExists('css', '#edit-description-' . Html::cleanCssIdentifier($field_name));
51       $this->assertTrue($field_description_element->isVisible());
52       $this->assertSame($help_text, $field_description_element->getText());
53     }
54   }
55
56 }