public function MediaRevisionsUiTest::testTabAccess in Media Revisions UI 8
Same name and namespace in other branches
- 2.0.x tests/src/Functional/MediaRevisionsUiTest.php \Drupal\Tests\media_revisions_ui\Functional\MediaRevisionsUiTest::testTabAccess()
Tests access to media revisions tab.
File
- tests/
src/ Functional/ MediaRevisionsUiTest.php, line 73
Class
- MediaRevisionsUiTest
- Tests media revisions UI.
Namespace
Drupal\Tests\media_revisions_ui\FunctionalCode
public function testTabAccess() {
$media = Media::create([
'bundle' => $this->mediaType
->id(),
'name' => 'Test media',
]);
$media
->save();
// Test that access is denied without permissions.
$this
->assertRevisionsListStatusCode($this
->drupalCreateUser([]), $media, 403);
$user = $this
->drupalCreateUser([
'administer media',
'view all media revisions',
]);
// Test that access is denied if a media type does not create revisions
// by default and media has just been created.
$media = Media::create([
'bundle' => $this->mediaType
->id(),
'name' => 'Test media',
]);
$media
->save();
$this
->assertRevisionsListStatusCode($user, $media, 403);
$this
->assertRevisionsTabNotExists($media);
// Test that access is allowed if a media revision is created.
$this
->createMediaRevision($media);
$this
->assertRevisionsListStatusCode($user, $media, 200);
$this
->assertRevisionsTabExists($media);
// Delete revision and check that revisions list is not accessible anymore.
$revisionId = $this
->loadOldestRevisionId($media);
$this->mediaStorage
->deleteRevision($revisionId);
$this
->assertRevisionsListStatusCode($user, $media, 403);
$this
->assertRevisionsTabNotExists($media);
// Test that access is allowed if a media type does create revisions
// by default and media has just been created.
$this->mediaType
->setNewRevision(TRUE);
$this->mediaType
->save();
$media = Media::create([
'bundle' => $this->mediaType
->id(),
'name' => 'Test media',
]);
$media
->save();
$this
->assertRevisionsListStatusCode($user, $media, 200);
$this
->assertRevisionsTabExists($media);
}