You are here

public function EntityLegalMethodsTest::testPopupMethod 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::testPopupMethod()
  2. 4.0.x src/Tests/EntityLegalMethodsTest.php \Drupal\entity_legal\Tests\EntityLegalMethodsTest::testPopupMethod()

JQuery UI dialog method test.

File

src/Tests/EntityLegalMethodsTest.php, line 58

Class

EntityLegalMethodsTest
Tests methods of encouraging users to accept legal documents.

Namespace

Drupal\entity_legal\Tests

Code

public function testPopupMethod() {
  $document = $this
    ->createDocument(TRUE, TRUE, [
    'existing_users' => [
      'require_method' => 'popup',
    ],
  ]);
  $this
    ->createDocumentVersion($document, TRUE);
  $account = $this
    ->createUserWithAcceptancePermissions($document);
  $this
    ->drupalLogin($account);

  // Check for the presence of the legal document in the js settings array.
  $js_settings = $this
    ->getDrupalSettings();
  $this
    ->assertTrue(isset($js_settings['entityLegalPopup']), 'Popup javascript settings found');
  $this
    ->assertEqual($document
    ->getPublishedVersion()
    ->label(), $js_settings['entityLegalPopup'][0]['popupTitle'], 'Popup title is correct');

  // Visit the document to agree as SimpleTest cannot properly submit using
  // the unprocessed markup from within the JS array.

  /** @var \Drupal\Core\Url $document_url */
  $document_url = $document
    ->toUrl();
  $document_path = $document_url
    ->toString();
  $this
    ->drupalPostForm($document_path, [
    'agree' => TRUE,
  ], 'Submit');

  // Ensure the popup is no longer present.
  $js_settings = $this
    ->getDrupalSettings();
  $this
    ->assertFalse(isset($js_settings['entityLegalPopup']), 'Popup javascript settings not found');

  // Create a new version.
  $this
    ->createDocumentVersion($document, TRUE);

  // Visit the home page and ensure that the user must re-accept.
  $this
    ->drupalGet('');
  $js_settings = $this
    ->getDrupalSettings();
  $this
    ->assertTrue(isset($js_settings['entityLegalPopup']), 'Popup javascript settings found');
  $this
    ->assertEqual($document
    ->getPublishedVersion()
    ->label(), $js_settings['entityLegalPopup'][0]['popupTitle'], 'Popup title is correct');
}