View source
<?php
namespace Drupal\Tests\media_library\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\field_ui\FieldUI;
class WidgetWithoutTypesTest extends MediaLibraryTestBase {
protected static $modules = [
'field_ui',
];
public function testWidgetWithoutMediaTypes() {
$assert_session = $this
->assertSession();
$user = $this
->drupalCreateUser([
'access administration pages',
'access content',
'create basic_page content',
'create media',
'view media',
]);
$this
->drupalLogin($user);
$default_message = 'There are no allowed media types configured for this field. Please contact the site administrator.';
$this
->drupalGet('node/add/basic_page');
$assert_session
->elementTextNotContains('css', '.field--name-field-twin-media', 'There are no allowed media types configured for this field.');
$assert_session
->elementExists('css', '.js-media-library-open-button[name^="field_twin_media"]');
$assert_session
->elementTextContains('css', '.field--name-field-empty-types-media', $default_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_empty_types_media"]');
$assert_session
->elementTextNotContains('css', '.field--name-field-null-types-media', 'There are no allowed media types configured for this field.');
$assert_session
->elementExists('css', '.js-media-library-open-button[name^="field_null_types_media"]');
$entity_type_manager = \Drupal::entityTypeManager();
$media_storage = $entity_type_manager
->getStorage('media');
$media_type_storage = $entity_type_manager
->getStorage('media_type');
$media_storage
->delete($media_storage
->loadMultiple());
$media_type_storage
->delete($media_type_storage
->loadMultiple());
$this
->drupalGet('node/add/basic_page');
$assert_session
->elementTextContains('css', '.field--name-field-twin-media', $default_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_twin_media"]');
$assert_session
->elementTextContains('css', '.field--name-field-empty-types-media', $default_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_empty_types_media"]');
$assert_session
->elementTextContains('css', '.field--name-field-null-types-media', $default_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_null_types_media"]');
$user = $this
->drupalCreateUser([
'access administration pages',
'access content',
'create basic_page content',
'view media',
'administer node fields',
]);
$this
->drupalLogin($user);
$route_bundle_params = FieldUI::getRouteBundleParameter(\Drupal::entityTypeManager()
->getDefinition('node'), 'basic_page');
$field_twin_url = new Url('entity.field_config.node_field_edit_form', [
'field_config' => 'node.basic_page.field_twin_media',
] + $route_bundle_params);
$field_twin_message = 'There are no allowed media types configured for this field. <a href="' . $field_twin_url
->toString() . '">Edit the field settings</a> to select the allowed media types.';
$field_empty_types_url = new Url('entity.field_config.node_field_edit_form', [
'field_config' => 'node.basic_page.field_empty_types_media',
] + $route_bundle_params);
$field_empty_types_message = 'There are no allowed media types configured for this field. <a href="' . $field_empty_types_url
->toString() . '">Edit the field settings</a> to select the allowed media types.';
$field_null_types_url = new Url('entity.field_config.node_field_edit_form', [
'field_config' => 'node.basic_page.field_null_types_media',
] + $route_bundle_params);
$field_null_types_message = 'There are no allowed media types configured for this field. <a href="' . $field_null_types_url
->toString() . '">Edit the field settings</a> to select the allowed media types.';
$this
->drupalGet('node/add/basic_page');
$assert_session
->elementContains('css', '.field--name-field-twin-media', $field_twin_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_twin_media"]');
$assert_session
->elementContains('css', '.field--name-field-empty-types-media', $field_empty_types_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_empty_types_media"]');
$assert_session
->elementContains('css', '.field--name-field-null-types-media', $field_null_types_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_null_types_media"]');
$this
->drupalGet($field_empty_types_url);
$assert_session
->elementContains('css', '.field--name-field-empty-types-media', $field_empty_types_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_empty_types_media"]');
$this
->drupalGet($field_null_types_url);
$assert_session
->elementContains('css', '.field--name-field-null-types-media', $field_null_types_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_null_types_media"]');
\Drupal::service('module_installer')
->uninstall([
'field_ui',
]);
$this
->drupalGet('node/add/basic_page');
$field_ui_uninstalled_message = 'There are no allowed media types configured for this field. Please contact the site administrator.';
$assert_session
->elementNotExists('named', [
'link',
'Edit the field settings',
]);
$assert_session
->elementContains('css', '.field--name-field-twin-media', $field_ui_uninstalled_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_twin_media"]');
$assert_session
->elementContains('css', '.field--name-field-empty-types-media', $field_ui_uninstalled_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_empty_types_media"]');
$assert_session
->elementContains('css', '.field--name-field-null-types-media', $field_ui_uninstalled_message);
$assert_session
->elementNotExists('css', '.js-media-library-open-button[name^="field_null_types_media"]');
}
}