function WidgetAccessTest::testRequiredFieldNoAccess

Same name in other branches
  1. 9 core/modules/media_library/tests/src/FunctionalJavascript/WidgetAccessTest.php \Drupal\Tests\media_library\FunctionalJavascript\WidgetAccessTest::testRequiredFieldNoAccess()
  2. 10 core/modules/media_library/tests/src/FunctionalJavascript/WidgetAccessTest.php \Drupal\Tests\media_library\FunctionalJavascript\WidgetAccessTest::testRequiredFieldNoAccess()

Tests the widget with a required field that the user can't access.

File

core/modules/media_library/tests/src/FunctionalJavascript/WidgetAccessTest.php, line 145

Class

WidgetAccessTest
Tests the media library UI access.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

public function testRequiredFieldNoAccess() : void {
    // Make field_single_media_type required.
    $fieldConfig = FieldConfig::loadByName('node', 'basic_page', 'field_single_media_type');
    assert($fieldConfig instanceof FieldConfig);
    $fieldConfig->setRequired(TRUE)
        ->save();
    // Deny access to the field.
    \Drupal::state()->set('media_library_test_entity_field_access_deny_fields', [
        'field_single_media_type',
    ]);
    $user = $this->drupalCreateUser([
        'access administration pages',
        'access content',
        'create basic_page content',
        'create type_one media',
        'view media',
    ]);
    $this->drupalLogin($user);
    $this->drupalGet('node/add/basic_page');
    $this->assertSession()
        ->elementNotExists('css', '.field--name-field-single-media-type');
    $this->submitForm([
        'title[0][value]' => $this->randomMachineName(),
    ], 'Save');
    $this->assertSession()
        ->elementNotExists('css', '.messages--error');
    $this->assertSession()
        ->pageTextNotContains('Single media type field is required.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.