function RevisionRouteProviderTest::testOperationAccessRevisionRoutes

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/RevisionRouteProviderTest.php \Drupal\KernelTests\Core\Entity\RevisionRouteProviderTest::testOperationAccessRevisionRoutes()

Tests revision access is granted by entity operations.

Ensures entity is sourced from revision parameter, not entity parameter or default revision. E.g 'entity_test_rev_revision' in '/{entity_test_rev}/revision/{entity_test_rev_revision}/view'.

@dataProvider providerOperationAccessRevisionRoutes

Parameters

string $linkTemplate: The link template to test.

string $entityLabel: Access is granted via specially named entity label passed to EntityTestAccessControlHandler.

File

core/tests/Drupal/KernelTests/Core/Entity/RevisionRouteProviderTest.php, line 70

Class

RevisionRouteProviderTest
Tests revision route provider.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testOperationAccessRevisionRoutes(string $linkTemplate, string $entityLabel) : void {
    
    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $entityStorage */
    $entityStorage = \Drupal::entityTypeManager()->getStorage('entity_test_rev');
    $entity = EntityTestRev::create()->setName('first revision');
    $entity->save();
    $noAccessRevisionId = $entity->getRevisionId();
    $entity->setName($entityLabel)
        ->setNewRevision();
    $entity->save();
    $hasAccessRevisionId = $entity->getRevisionId();
    $this->assertNotEquals($noAccessRevisionId, $hasAccessRevisionId);
    // Create an additional default revision to ensure access isn't being pulled
    // from default revision.
    $entity->setName('default')
        ->setNewRevision();
    $entity->isDefaultRevision(TRUE);
    $entity->save();
    // Reload entity so default revision flags are accurate.
    $originalRevision = $entityStorage->loadRevision($noAccessRevisionId);
    $viewableRevision = $entityStorage->loadRevision($hasAccessRevisionId);
    $this->assertFalse($originalRevision->toUrl($linkTemplate)
        ->access());
    $this->assertTrue($viewableRevision->toUrl($linkTemplate)
        ->access());
}

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