function MediaLibraryAccessTest::testAddFormAccess
Same name in other branches
- 9 core/modules/media_library/tests/src/Kernel/MediaLibraryAccessTest.php \Drupal\Tests\media_library\Kernel\MediaLibraryAccessTest::testAddFormAccess()
- 10 core/modules/media_library/tests/src/Kernel/MediaLibraryAccessTest.php \Drupal\Tests\media_library\Kernel\MediaLibraryAccessTest::testAddFormAccess()
Tests that the media library respects arbitrary access to the add form.
File
-
core/
modules/ media_library/ tests/ src/ Kernel/ MediaLibraryAccessTest.php, line 378
Class
- MediaLibraryAccessTest
- Tests the media library access.
Namespace
Drupal\Tests\media_library\KernelCode
public function testAddFormAccess() : void {
// Access is denied if the media library is trying to create media whose
// type name is 'deny_access'. Also create a second media type that we *can*
// add, so we can be certain that the add form is otherwise visible.
// @see media_library_test_media_create_access()
$media_types = [
$this->createMediaType('image', [
'id' => 'deny_access',
])
->id(),
$this->createMediaType('image')
->id(),
];
$account = $this->createUser([
'create media',
]);
$this->setCurrentUser($account);
/** @var \Drupal\media_library\MediaLibraryUiBuilder $ui_builder */
$ui_builder = $this->container
->get('media_library.ui_builder');
$state = MediaLibraryState::create('test', $media_types, $media_types[0], 1);
$build = $ui_builder->buildUi($state);
$this->assertEmpty($build['content']['form']);
$state = MediaLibraryState::create('test', $media_types, $media_types[1], 1);
$build = $ui_builder->buildUi($state);
$this->assertNotEmpty($build['content']['form']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.