function MediaAccessControlHandlerTest::providerAccess

Same name in other branches
  1. 9 core/modules/media/tests/src/Kernel/MediaAccessControlHandlerTest.php \Drupal\Tests\media\Kernel\MediaAccessControlHandlerTest::providerAccess()
  2. 8.9.x core/modules/media/tests/src/Kernel/MediaAccessControlHandlerTest.php \Drupal\Tests\media\Kernel\MediaAccessControlHandlerTest::providerAccess()
  3. 10 core/modules/media/tests/src/Kernel/MediaAccessControlHandlerTest.php \Drupal\Tests\media\Kernel\MediaAccessControlHandlerTest::providerAccess()

Data provider for testAccess().

Return value

array The data sets to test.

File

core/modules/media/tests/src/Kernel/MediaAccessControlHandlerTest.php, line 137

Class

MediaAccessControlHandlerTest
Tests the media access control handler.

Namespace

Drupal\Tests\media\Kernel

Code

public static function providerAccess() {
    $test_data = [];
    // Check published / unpublished media access for a user owning the media
    // item without permissions.
    $test_data['owner, no permissions / published / view'] = [
        [],
        [
            'status' => TRUE,
        ],
        'view',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['owner, no permissions / published / update'] = [
        [],
        [
            'status' => TRUE,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, no permissions / published / delete'] = [
        [],
        [
            'status' => TRUE,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, no permissions / unpublished / view'] = [
        [],
        [],
        'view',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['owner, no permissions / unpublished / update'] = [
        [],
        [],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, no permissions / unpublished / delete'] = [
        [],
        [],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    // Check published / unpublished media access for a user not owning the
    // media item without permissions.
    $test_data['not owner, no permissions / published / view'] = [
        [],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'view',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['not owner, no permissions / published / update'] = [
        [],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, no permissions / published / delete'] = [
        [],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, no permissions / unpublished / view'] = [
        [],
        [
            'uid' => 0,
        ],
        'view',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['not owner, no permissions / unpublished / update'] = [
        [],
        [
            'uid' => 0,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, no permissions / unpublished / delete'] = [
        [],
        [
            'uid' => 0,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    // Check published / unpublished media access for a user owning the media
    // item with only the 'view media' permission.
    $test_data['owner, can view media / published / view'] = [
        [
            'view media',
        ],
        [
            'status' => TRUE,
        ],
        'view',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['owner, can view media / published / update'] = [
        [
            'view media',
        ],
        [
            'status' => TRUE,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, can view media / published / delete'] = [
        [
            'view media',
        ],
        [
            'status' => TRUE,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, can view media / unpublished / view'] = [
        [
            'view media',
        ],
        [],
        'view',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['owner, can view media / unpublished / update'] = [
        [
            'view media',
        ],
        [],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, can view media / unpublished / delete'] = [
        [
            'view media',
        ],
        [],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    // Check published / unpublished media access for a user not owning the
    // media item with only the 'view media' permission.
    $test_data['not owner, can view media / published / view'] = [
        [
            'view media',
        ],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'view',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['not owner, can view media / published / update'] = [
        [
            'view media',
        ],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, can view media / published / delete'] = [
        [
            'view media',
        ],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, can view media / unpublished / view'] = [
        [
            'view media',
        ],
        [
            'uid' => 0,
        ],
        'view',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['not owner, can view media / unpublished / update'] = [
        [
            'view media',
        ],
        [
            'uid' => 0,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, can view media / unpublished / delete'] = [
        [
            'view media',
        ],
        [
            'uid' => 0,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    // Check published / unpublished media access for a user owning the media
    // item with the 'view media' and 'view own unpublished' permission.
    $test_data['owner, can view own unpublished media / published / view'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'status' => TRUE,
        ],
        'view',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['owner, can view own unpublished media / published / update'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'status' => TRUE,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, can view own unpublished media / published / delete'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'status' => TRUE,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, can view own unpublished media / unpublished / view'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [],
        'view',
        AccessResult::allowed(),
        [
            'user.permissions',
            'user',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['owner, can view own unpublished media / unpublished / update'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['owner, can view own unpublished media / unpublished / delete'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    // Check published / unpublished media access for a user not owning the
    // media item with the 'view media' and 'view own unpublished' permission.
    $test_data['not owner, can view own unpublished media / published / view'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'view',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['not owner, can view own unpublished media / published / update'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, can view own unpublished media / published / delete'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'uid' => 0,
            'status' => TRUE,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, can view own unpublished media / unpublished / view'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'uid' => 0,
        ],
        'view',
        AccessResult::neutral(),
        [
            'user.permissions',
            'user',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    $test_data['not owner, can view own unpublished media / unpublished / update'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'uid' => 0,
        ],
        'update',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['not owner, can view own unpublished media / unpublished / delete'] = [
        [
            'view media',
            'view own unpublished media',
        ],
        [
            'uid' => 0,
        ],
        'delete',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    // View all revisions:
    $test_data['view all revisions:none'] = [
        [],
        [],
        'view all revisions',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['admins can view all revisions'] = [
        [
            'administer media',
        ],
        [],
        'view all revisions',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [],
        TRUE,
    ];
    $test_data['view all revisions with view bundle permission'] = [
        [
            'view any test media revisions',
            'view media',
        ],
        [
            'status' => TRUE,
        ],
        'view all revisions',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        TRUE,
    ];
    // Revert revisions:
    $test_data['revert a latest revision with no permissions'] = [
        [],
        [],
        'revert',
        AccessResult::forbidden(),
        [],
        [],
        TRUE,
    ];
    $test_data['revert a historical revision with no permissions'] = [
        [],
        [],
        'revert',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        FALSE,
    ];
    $test_data['revert latest revision with administer media permission'] = [
        [
            'administer media',
        ],
        [],
        'revert',
        AccessResult::forbidden(),
        [],
        [],
        TRUE,
    ];
    $test_data['revert a historical revision with administer media permission'] = [
        [
            'administer media',
        ],
        [],
        'revert',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [],
        FALSE,
    ];
    $test_data['revert a latest revision with revert bundle permission'] = [
        [
            'revert any test media revisions',
        ],
        [],
        'revert',
        AccessResult::forbidden(),
        [],
        [],
        TRUE,
    ];
    $test_data['revert a historical revision with revert bundle permission'] = [
        [
            'revert any test media revisions',
        ],
        [],
        'revert',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        FALSE,
    ];
    // Delete revisions:
    $test_data['delete a latest revision with no permission'] = [
        [],
        [],
        'delete revision',
        AccessResult::forbidden(),
        [],
        [],
        TRUE,
    ];
    $test_data['delete a historical revision with no permission'] = [
        [],
        [],
        'delete revision',
        AccessResult::neutral(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        FALSE,
    ];
    $test_data['delete a latest revision with administer media permission'] = [
        [
            'administer media',
        ],
        [],
        'delete revision',
        AccessResult::forbidden(),
        [],
        [],
        TRUE,
    ];
    $test_data['delete a historical revision with administer media permission'] = [
        [
            'administer media',
        ],
        [],
        'delete revision',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [],
        FALSE,
    ];
    $test_data['delete a latest revision with delete bundle permission'] = [
        [
            'delete any test media revisions',
        ],
        [],
        'delete revision',
        AccessResult::forbidden(),
        [],
        [],
        TRUE,
    ];
    $test_data['delete a historical revision with delete bundle permission'] = [
        [
            'delete any test media revisions',
        ],
        [],
        'delete revision',
        AccessResult::allowed(),
        [
            'user.permissions',
        ],
        [
            'media:1',
        ],
        FALSE,
    ];
    return $test_data;
}

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