You are here

public function EntityLegalMethodsTest::testMessageMethod in Entity Legal 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Tests/EntityLegalMethodsTest.php \Drupal\entity_legal\Tests\EntityLegalMethodsTest::testMessageMethod()
  2. 4.0.x src/Tests/EntityLegalMethodsTest.php \Drupal\entity_legal\Tests\EntityLegalMethodsTest::testMessageMethod()

Drupal message method test.

File

src/Tests/EntityLegalMethodsTest.php, line 15

Class

EntityLegalMethodsTest
Tests methods of encouraging users to accept legal documents.

Namespace

Drupal\entity_legal\Tests

Code

public function testMessageMethod() {
  $document = $this
    ->createDocument(TRUE, TRUE, [
    'existing_users' => [
      'require_method' => 'message',
    ],
  ]);
  $this
    ->createDocumentVersion($document, TRUE);
  $acceptance_message = format_string('Please accept the @title', [
    '@title' => $document
      ->getPublishedVersion()
      ->label(),
  ]);

  /** @var \Drupal\Core\Url $document_url */
  $document_url = $document
    ->toUrl();
  $document_path = $document_url
    ->toString();
  $account = $this
    ->createUserWithAcceptancePermissions($document);
  $this
    ->drupalLogin($account);
  $this
    ->assertText($acceptance_message, 'Document message found');
  $this
    ->assertLinkByHref($document_path, 0, 'Link to document found');
  $this
    ->clickLink($document
    ->getPublishedVersion()
    ->label());
  $this
    ->assertFieldByName('agree', NULL, 'I agree checkbox found');
  $this
    ->drupalPostForm($document_path, [
    'agree' => TRUE,
  ], 'Submit');

  // @todo Assert checkbox is disabled and acceptance date displayed.
  $this
    ->assertNoText($acceptance_message, 'Document message not found');
  $this
    ->createDocumentVersion($document, TRUE);
  $this
    ->drupalGet('');
  $acceptance_message_2 = format_string('Please accept the @title', [
    '@title' => $document
      ->getPublishedVersion()
      ->label(),
  ]);
  $this
    ->assertText($acceptance_message_2, 'Document message found');
  $this
    ->assertLinkByHref($document_path, 0, 'Link to document found');
}