class RevisionRouteProviderTest
Same name in this branch
- 10 core/tests/Drupal/FunctionalTests/Entity/RevisionRouteProviderTest.php \Drupal\FunctionalTests\Entity\RevisionRouteProviderTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Entity/RevisionRouteProviderTest.php \Drupal\KernelTests\Core\Entity\RevisionRouteProviderTest
- 11.x core/tests/Drupal/FunctionalTests/Entity/RevisionRouteProviderTest.php \Drupal\FunctionalTests\Entity\RevisionRouteProviderTest
Tests revision route provider.
@coversDefaultClass \Drupal\Core\Entity\Routing\RevisionHtmlRouteProvider
@group Entity
Hierarchy
- class \Drupal\KernelTests\Core\Entity\RevisionRouteProviderTest
Expanded class hierarchy of RevisionRouteProviderTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ RevisionRouteProviderTest.php, line 17
Namespace
Drupal\KernelTests\Core\EntityView source
class RevisionRouteProviderTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$this->installEntitySchema('user');
$this->setUpCurrentUser([
'uid' => 1,
]);
}
/**
* Tests revision access for revision overview.
*
* Tests routes which do not need a specific revision parameter.
*/
public function testOperationAccessOverview() : void {
$entity = EntityTestRev::create()->setName('first revision');
$entity->save();
$this->assertFalse($entity->toUrl('version-history')
->access());
$entity->setName('view all revisions')
->setNewRevision();
$entity->save();
$this->assertTrue($entity->toUrl('version-history')
->access());
}
/**
* 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'.
*
* @param string $linkTemplate
* The link template to test.
* @param string $entityLabel
* Access is granted via specially named entity label passed to
* EntityTestAccessControlHandler.
*
* @dataProvider providerOperationAccessRevisionRoutes
*/
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());
}
/**
* Data provider for testOperationAccessRevisionRoutes.
*
* @return array
* Data for testing.
*/
public static function providerOperationAccessRevisionRoutes() : array {
$data = [];
$data['view revision'] = [
'revision',
'view revision',
];
$data['revert revision'] = [
'revision-revert-form',
'revert',
];
$data['delete revision'] = [
'revision-delete-form',
'delete revision',
];
return $data;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ExtensionListTestTrait::getModulePath | protected | function | Gets the path for the specified module. |
ExtensionListTestTrait::getThemePath | protected | function | Gets the path for the specified theme. |
RevisionRouteProviderTest::$modules | protected static | property | Modules to install. |
RevisionRouteProviderTest::providerOperationAccessRevisionRoutes | public static | function | Data provider for testOperationAccessRevisionRoutes. |
RevisionRouteProviderTest::setUp | protected | function | |
RevisionRouteProviderTest::testOperationAccessOverview | public | function | Tests revision access for revision overview. |
RevisionRouteProviderTest::testOperationAccessRevisionRoutes | public | function | Tests revision access is granted by entity operations. |
StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.