3
3
namespace Drupal \Tests \media \FunctionalJavascript ;
4
4
5
5
use Drupal \Component \Utility \Html ;
6
- use Drupal \Core \Url ;
7
6
use Drupal \editor \Entity \Editor ;
8
7
use Drupal \field \Entity \FieldConfig ;
9
8
use Drupal \file \Entity \File ;
@@ -1027,14 +1026,13 @@ public function linkabilityProvider() {
1027
1026
* @dataProvider previewAccessProvider
1028
1027
*/
1029
1028
public function testEmbedPreviewAccess ($ media_embed_enabled , $ can_use_format ) {
1030
- $ format = FilterFormat::create ([
1031
- 'format ' => $ this ->randomMachineName (),
1032
- 'name ' => $ this ->randomString (),
1033
- 'filters ' => [
1034
- 'filter_align ' => ['status ' => TRUE ],
1035
- 'filter_caption ' => ['status ' => TRUE ],
1036
- 'media_embed ' => ['status ' => $ media_embed_enabled ],
1037
- ],
1029
+ // Reconfigure the host entity's text format to suit our needs.
1030
+ /** @var \Drupal\filter\FilterFormatInterface $format */
1031
+ $ format = FilterFormat::load ($ this ->host ->body ->format );
1032
+ $ format ->set ('filters ' , [
1033
+ 'filter_align ' => ['status ' => TRUE ],
1034
+ 'filter_caption ' => ['status ' => TRUE ],
1035
+ 'media_embed ' => ['status ' => $ media_embed_enabled ],
1038
1036
]);
1039
1037
$ format ->save ();
1040
1038
@@ -1045,24 +1043,23 @@ public function testEmbedPreviewAccess($media_embed_enabled, $can_use_format) {
1045
1043
$ permissions [] = $ format ->getPermissionName ();
1046
1044
}
1047
1045
$ this ->drupalLogin ($ this ->drupalCreateUser ($ permissions ));
1048
-
1049
- $ text = '<drupal-media data-caption="baz" data-entity-type="media" data-entity-uuid=" ' . $ this ->media ->uuid () . '"></drupal-media> ' ;
1050
- $ route_parameters = ['filter_format ' => $ format ->id ()];
1051
- $ options = [
1052
- 'query ' => [
1053
- 'text ' => $ text ,
1054
- 'uuid ' => $ this ->media ->uuid (),
1055
- ],
1056
- ];
1057
- $ this ->drupalGet (Url::fromRoute ('media.filter.preview ' , $ route_parameters , $ options ));
1046
+ $ this ->drupalGet ($ this ->host ->toUrl ('edit-form ' ));
1058
1047
1059
1048
$ assert_session = $ this ->assertSession ();
1060
- if ($ media_embed_enabled && $ can_use_format ) {
1061
- $ assert_session ->elementExists ('css ' , 'img ' );
1062
- $ assert_session ->responseContains ('baz ' );
1049
+ if ($ can_use_format ) {
1050
+ $ this ->waitForEditor ();
1051
+ $ this ->assignNameToCkeditorIframe ();
1052
+ $ this ->getSession ()->switchToIFrame ('ckeditor ' );
1053
+ if ($ media_embed_enabled ) {
1054
+ $ this ->assertNotEmpty ($ assert_session ->waitForElementVisible ('css ' , 'article.media ' ));
1055
+ }
1056
+ else {
1057
+ $ assert_session ->assertWaitOnAjaxRequest ();
1058
+ $ assert_session ->elementNotExists ('css ' , 'article.media ' );
1059
+ }
1063
1060
}
1064
1061
else {
1065
- $ assert_session ->responseContains ( ' You are not authorized to access this page . ' );
1062
+ $ assert_session ->pageTextContains ( ' This field has been disabled because you do not have sufficient permissions to edit it . ' );
1066
1063
}
1067
1064
}
1068
1065
0 commit comments