You are here

public function RevisionBasicUITest::testRevisionView in Entity API 8.0

Same name and namespace in other branches
  1. 8 tests/src/Kernel/RevisionBasicUITest.php \Drupal\Tests\entity\Kernel\RevisionBasicUITest::testRevisionView()

File

tests/src/Kernel/RevisionBasicUITest.php, line 88
Contains \Drupal\Tests\entity\Kernel\RevisionBasicUITest.

Class

RevisionBasicUITest
@group entity

Namespace

Drupal\Tests\entity\Kernel

Code

public function testRevisionView() {
  $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();

  /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
  $http_kernel = \Drupal::service('http_kernel');
  $request = Request::create($revision
    ->url('revision'));
  $response = $http_kernel
    ->handle($request);
  $this
    ->assertEquals(403, $response
    ->getStatusCode());
  $role = Role::create([
    'id' => 'test_role',
  ]);
  $role
    ->grantPermission('view all entity_test_enhanced revisions');
  $role
    ->grantPermission('administer entity_test_enhanced');
  $role
    ->save();
  $user = User::create([
    'name' => 'Test user',
  ]);
  $user
    ->addRole($role
    ->id());
  \Drupal::service('account_switcher')
    ->switchTo($user);
  $request = Request::create($revision
    ->url('revision'));
  $response = $http_kernel
    ->handle($request);
  $this
    ->assertEquals(200, $response
    ->getStatusCode());
  $this
    ->assertNotContains('rev 1', $response
    ->getContent());
  $this
    ->assertContains('rev 2', $response
    ->getContent());
}