RevisionRouteAccessTest.php in Entity API 8
File
tests/src/Functional/RevisionRouteAccessTest.php
View source
<?php
namespace Drupal\Tests\entity\Functional;
use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
class RevisionRouteAccessTest extends BrowserTestBase {
use BlockCreationTrait;
protected $account;
public static $modules = [
'entity_module_test',
'user',
'entity',
'block',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->placeBlock('local_tasks_block');
$this
->placeBlock('system_breadcrumb_block');
$this->account = $this
->drupalCreateUser([
'administer entity_test_enhanced',
'view all entity_test_enhanced revisions',
]);
$this
->drupalLogin($this->account);
}
public function testRevisionRouteAccess() {
$entity = EnhancedEntity::create([
'name' => 'rev 1',
'type' => 'default',
]);
$entity
->save();
$revision = clone $entity;
$revision->name->value = 'rev 2';
$revision
->setNewRevision(TRUE);
$revision
->isDefaultRevision(FALSE);
$revision
->save();
$this
->drupalGet('/entity_test_enhanced/1/revisions');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('Revisions');
$collection_link = $this
->getSession()
->getPage()
->findLink('Enhanced entities');
$collection_link
->click();
$this
->assertSession()
->addressEquals('/entity_test_enhanced');
$this
->assertSession()
->responseContains('Edit');
$edit_link = $this
->getSession()
->getPage()
->findLink('Edit');
$edit_link
->click();
$this
->assertSession()
->addressEquals('/entity_test_enhanced/1/edit');
$this
->getSession()
->getPage()
->findLink('Revisions')
->click();
$this
->assertSession()
->addressEquals('/entity_test_enhanced/1/revisions');
$this
->drupalGet('/entity_test_enhanced/1/revisions/2/view');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('rev 2');
$revisions_link = $this
->getSession()
->getPage()
->findLink('Revisions');
$revisions_link
->click();
$this
->assertSession()
->addressEquals('/entity_test_enhanced/1/revisions');
$this
->assertSession()
->statusCodeEquals(200);
}
}