MediaLibraryImageStyleAccessTest.php

Same filename in other branches
  1. 11.x core/modules/media_library/tests/src/Functional/MediaLibraryImageStyleAccessTest.php

Namespace

Drupal\Tests\media_library\Functional

File

core/modules/media_library/tests/src/Functional/MediaLibraryImageStyleAccessTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\media_library\Functional;

use Drupal\image\Entity\ImageStyle;
use Drupal\Tests\BrowserTestBase;

/**
 * Tests access to the Media library image style.
 *
 * @group media_library
 */
class MediaLibraryImageStyleAccessTest extends BrowserTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'media_library',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests that users can't delete the 'media_library' image style.
     */
    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);
    }

}

Classes

Title Deprecated Summary
MediaLibraryImageStyleAccessTest Tests access to the Media library image style.

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