comparison core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
28 $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY; 28 $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
29 $storage = new FileStorage($optional_install_path); 29 $storage = new FileStorage($optional_install_path);
30 $this->container->get('config.installer')->installOptionalConfig($storage, ''); 30 $this->container->get('config.installer')->installOptionalConfig($storage, '');
31 // Reset all the static caches and list caches. 31 // Reset all the static caches and list caches.
32 $this->container->get('config.factory')->reset(); 32 $this->container->get('config.factory')->reset();
33
34 // This test is going to test the display, so we need the standalone URL.
35 \Drupal::configFactory()
36 ->getEditable('media.settings')
37 ->set('standalone_url', TRUE)
38 ->save(TRUE);
39
40 $this->container->get('router.builder')->rebuild();
33 } 41 }
34 42
35 /** 43 /**
36 * Test basic media display. 44 * Test basic media display.
37 */ 45 */
66 $this->assertSame($media->label(), $name_field->getText()); 74 $this->assertSame($media->label(), $name_field->getText());
67 75
68 // In the standard profile, there are some pre-cooked types. Make sure the 76 // In the standard profile, there are some pre-cooked types. Make sure the
69 // elements configured on their displays are the expected ones. 77 // elements configured on their displays are the expected ones.
70 $this->drupalGet('media/add/image'); 78 $this->drupalGet('media/add/image');
71 $image_media_name = 'Fantastic image asset!'; 79 $image_media_name = 'example_1.jpeg';
72 $page->fillField('name[0][value]', $image_media_name); 80 $page->attachFileToField('files[field_media_image_0]', $this->root . '/core/modules/media/tests/fixtures/' . $image_media_name);
73 $page->attachFileToField('files[field_media_image_0]', $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
74 $result = $assert_session->waitForButton('Remove'); 81 $result = $assert_session->waitForButton('Remove');
75 $this->assertNotEmpty($result); 82 $this->assertNotEmpty($result);
76 $page->fillField('field_media_image[0][alt]', 'Image Alt Text 1'); 83 $page->fillField('field_media_image[0][alt]', 'Image Alt Text 1');
77 $page->pressButton('Save'); 84 $page->pressButton('Save');
78 $image_media_id = $this->container 85 $image_media_id = $this->container
84 $image_media_id = reset($image_media_id); 91 $image_media_id = reset($image_media_id);
85 92
86 // Go to the media entity view. 93 // Go to the media entity view.
87 $this->drupalGet('/media/' . $image_media_id); 94 $this->drupalGet('/media/' . $image_media_id);
88 95
96 // Check if the default media name is generated as expected.
97 $assert_session->elementTextContains('css', 'h1', $image_media_name);
89 // Here we expect to see only the image, nothing else. 98 // Here we expect to see only the image, nothing else.
90 // Assert only one element in the content region. 99 // Assert only one element in the content region.
91 $this->assertSame(1, count($page->findAll('css', '.media--type-image > div'))); 100 $this->assertSame(1, count($page->findAll('css', '.media--type-image > div')));
92 // Assert the image is present inside the media element. 101 // Assert the image is present inside the media element.
93 $media_item = $assert_session->elementExists('css', '.media--type-image > div'); 102 $media_item = $assert_session->elementExists('css', '.media--type-image > div');
99 108
100 $test_filename = $this->randomMachineName() . '.txt'; 109 $test_filename = $this->randomMachineName() . '.txt';
101 $test_filepath = 'public://' . $test_filename; 110 $test_filepath = 'public://' . $test_filename;
102 file_put_contents($test_filepath, $this->randomMachineName()); 111 file_put_contents($test_filepath, $this->randomMachineName());
103 $this->drupalGet("media/add/file"); 112 $this->drupalGet("media/add/file");
104 $page->fillField('name[0][value]', 'File media 1');
105 $page->attachFileToField("files[field_media_file_0]", \Drupal::service('file_system')->realpath($test_filepath)); 113 $page->attachFileToField("files[field_media_file_0]", \Drupal::service('file_system')->realpath($test_filepath));
106 $result = $assert_session->waitForButton('Remove'); 114 $result = $assert_session->waitForButton('Remove');
107 $this->assertNotEmpty($result); 115 $this->assertNotEmpty($result);
108 $page->pressButton('Save'); 116 $page->pressButton('Save');
109 117
110 // Go to the media entity view. 118 // Go to the media entity view.
111 $this->drupalGet($this->assertLinkToCreatedMedia()); 119 $this->drupalGet($this->assertLinkToCreatedMedia());
112 120
121 // Check if the default media name is generated as expected.
122 $assert_session->elementTextContains('css', 'h1', $test_filename);
113 // Here we expect to see only the linked filename. 123 // Here we expect to see only the linked filename.
114 // Assert only one element in the content region. 124 // Assert only one element in the content region.
115 $this->assertSame(1, count($page->findAll('css', 'article.media--type-file > div'))); 125 $this->assertSame(1, count($page->findAll('css', 'article.media--type-file > div')));
116 // Assert the file link is present, and its text matches the filename. 126 // Assert the file link is present, and its text matches the filename.
117 $assert_session->elementExists('css', 'article.media--type-file .field--name-field-media-file a'); 127 $assert_session->elementExists('css', 'article.media--type-file .field--name-field-media-file a');