function MediaLibraryImageStyleAccessTest::testMediaLibraryImageStyleAccess

Same name in other branches
  1. 11.x core/modules/media_library/tests/src/Functional/MediaLibraryImageStyleAccessTest.php \Drupal\Tests\media_library\Functional\MediaLibraryImageStyleAccessTest::testMediaLibraryImageStyleAccess()

Tests that users can't delete the 'media_library' image style.

File

core/modules/media_library/tests/src/Functional/MediaLibraryImageStyleAccessTest.php, line 30

Class

MediaLibraryImageStyleAccessTest
Tests access to the Media library image style.

Namespace

Drupal\Tests\media_library\Functional

Code

public function testMediaLibraryImageStyleAccess() : void {
    // Create a user who can manage the image styles.
    $user = $this->createUser([
        'access administration pages',
        'administer image styles',
    ]);
    // The user should be able to delete the 'medium' image style, but not the
    // 'media_library' image style.
    $medium = ImageStyle::load('medium');
    $this->assertTrue($medium->access('delete', $user));
    $mediaLibrary = ImageStyle::load('media_library');
    $this->assertFalse($mediaLibrary->access('delete', $user));
    $this->drupalLogin($user);
    $this->drupalGet($medium->toUrl('delete-form'));
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->drupalGet($mediaLibrary->toUrl('delete-form'));
    $this->assertSession()
        ->statusCodeEquals(403);
}

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