You are here

public function DiffControllerTest::testController in Diff 8

Tests the Controller.

File

tests/src/Functional/DiffControllerTest.php, line 45

Class

DiffControllerTest
Tests the diff controller.

Namespace

Drupal\Tests\diff\Functional

Code

public function testController() {
  $assert_session = $this
    ->assertSession();
  $entity = EntityTestRev::create([
    'name' => 'test entity 1',
    'type' => 'entity_test_rev',
  ]);
  $entity
    ->save();
  $vid1 = $entity
    ->getRevisionId();
  $entity->name->value = 'test entity 2';
  $entity
    ->setNewRevision(TRUE);
  $entity
    ->save();
  $vi2 = $entity
    ->getRevisionId();
  $url = Url::fromRoute('entity.entity_test_rev.revisions_diff', [
    'entity_test_rev' => $entity
      ->id(),
    'left_revision' => $vid1,
    'right_revision' => $vi2,
  ]);
  $this
    ->drupalGet($url);
  $assert_session
    ->statusCodeEquals(403);
  $account = $this
    ->drupalCreateUser([
    'view test entity',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($url);
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->responseContains('<td class="diff-context diff-deletedline">test entity <span class="diffchange">1</span></td>');
  $assert_session
    ->responseContains('<td class="diff-context diff-addedline">test entity <span class="diffchange">2</span></td>');
}