function MediaRevisionTest::testRevisions
Same name in other branches
- 9 core/modules/media/tests/src/Functional/MediaRevisionTest.php \Drupal\Tests\media\Functional\MediaRevisionTest::testRevisions()
- 8.9.x core/modules/media/tests/src/Functional/MediaRevisionTest.php \Drupal\Tests\media\Functional\MediaRevisionTest::testRevisions()
- 11.x core/modules/media/tests/src/Functional/MediaRevisionTest.php \Drupal\Tests\media\Functional\MediaRevisionTest::testRevisions()
Checks media revision operations.
File
-
core/
modules/ media/ tests/ src/ Functional/ MediaRevisionTest.php, line 57
Class
- MediaRevisionTest
- Tests the revisions of media entities.
Namespace
Drupal\Tests\media\FunctionalCode
public function testRevisions() : void {
$assert = $this->assertSession();
$media = $this->createMedia('Sample media');
$originalRevisionId = $media->getRevisionId();
// You can access the revision page when there is only 1 revision.
$this->drupalGet($media->toUrl('revision'));
$assert->statusCodeEquals(200);
// Create some revisions.
$revision_count = 3;
for ($i = 0; $i < $revision_count; $i++) {
$media->revision_log = $this->randomMachineName(32);
$media = $this->createMediaRevision($media);
}
// Confirm that the last revision is the default revision.
$this->assertTrue($media->isDefaultRevision(), 'Last revision is the default.');
// Get the original revision for simple checks.
$media = \Drupal::entityTypeManager()->getStorage('media')
->loadRevision($originalRevisionId);
// Test permissions.
$this->drupalLogin($this->nonAdminUser);
/** @var \Drupal\user\RoleInterface $role */
$role = Role::load(RoleInterface::AUTHENTICATED_ID);
// Test 'view all media revisions' permission ('view media' permission is
// needed as well).
user_role_revoke_permissions($role->id(), [
'view all media revisions',
]);
$this->drupalGet($media->toUrl('revision'));
$assert->statusCodeEquals(403);
$this->grantPermissions($role, [
'view any test media revisions',
]);
$this->drupalGet($media->toUrl('revision'));
$assert->statusCodeEquals(200);
user_role_revoke_permissions($role->id(), [
'view any test media revisions',
]);
$this->grantPermissions($role, [
'view all media revisions',
]);
$this->drupalGet($media->toUrl('revision'));
$assert->statusCodeEquals(200);
// Confirm the revision page shows the correct title.
$assert->pageTextContains($media->getName());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.