You are here

public function IndividualUiTest::testIndividualRevisions in CRM Core 8

Same name and namespace in other branches
  1. 8.2 modules/crm_core_contact/src/Tests/IndividualUiTest.php \Drupal\crm_core_contact\Tests\IndividualUiTest::testIndividualRevisions()

Test individual revisions.

File

modules/crm_core_contact/src/Tests/IndividualUiTest.php, line 284

Class

IndividualUiTest
Tests the UI for Individual CRUD operations.

Namespace

Drupal\crm_core_contact\Tests

Code

public function testIndividualRevisions() {
  $user = $this
    ->drupalCreateUser([
    'create crm_core_individual entities',
    'view any crm_core_individual entity',
    'edit any crm_core_individual entity',
    'view all crm_core_individual revisions',
    'revert all crm_core_individual revisions',
  ]);
  $this
    ->drupalLogin($user);
  $individual = [
    'name[0][given]' => 'rev',
    'name[0][family]' => '1',
  ];
  $this
    ->drupalPostForm('crm-core/individual/add/customer', $individual, 'Save Customer');
  $individual_1 = [
    'name[0][family]' => '2',
  ];
  $this
    ->drupalPostForm('crm-core/individual/1/edit', $individual_1, 'Save Customer');
  $individual_2 = [
    'name[0][family]' => '3',
  ];
  $this
    ->drupalPostForm('crm-core/individual/1/edit', $individual_2, 'Save Customer');
  $this
    ->clickLink('Revisions');
  $this
    ->assertLinkByHref('crm-core/individual/1');
  $this
    ->assertLinkByHref('crm-core/individual/1/revisions/1/view');
  $this
    ->assertLinkByHref('crm-core/individual/1/revisions/2/view');
  $this
    ->drupalGet('crm-core/individual/1/revisions/1/view');
  $this
    ->assertText('rev 1');
  $this
    ->drupalGet('crm-core/individual/1/revisions/2/view');
  $this
    ->assertText('rev 2');

  /** @var \Drupal\crm_core_contact\ContactInterface $individual */
  $individual = Individual::create([
    'type' => 'customer',
  ]);
  $individual
    ->save();
  $revision = clone $individual;
  $revision
    ->setNewRevision(TRUE);
  $revision
    ->isDefaultRevision(FALSE);
  $revision
    ->save();
  $this
    ->drupalGet($revision
    ->toUrl('version-history'));

  // Assert we have one revision link and current revision.
  $this
    ->assertLinkByHref('crm-core/individual/' . $individual
    ->id() . '/revisions/5/view');
  $this
    ->assertLinkByHref('crm-core/individual/' . $individual
    ->id());

  // Assert we have revision revert link.
  $this
    ->assertLinkByHref('crm-core/individual/' . $individual
    ->id() . '/revisions/5/revert');
  $this
    ->drupalGet('crm-core/individual/' . $individual
    ->id() . '/revisions/5/revert');
  $this
    ->assertResponse(200);

  // Check view revision route.
  $this
    ->drupalGet('crm-core/individual/' . $individual
    ->id() . '/revisions/5/view');
  $this
    ->assertRaw('Nameless #2');
}