You are here

public function EntityLegalMethodsTestCase::testPopupMethod in Entity Legal 7.2

Same name and namespace in other branches
  1. 7 tests/entity_legal.methods.test \EntityLegalMethodsTestCase::testPopupMethod()

JQuery UI dialog method test.

File

tests/entity_legal.methods.test, line 70
Test for defined methods in Entity Legal module.

Class

EntityLegalMethodsTestCase
Simpletest class for acceptance methods.

Code

public function testPopupMethod() {
  $document = $this
    ->createDocument(TRUE, TRUE, array(
    'existing_users' => array(
      '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
    ->drupalGetSettings();
  $this
    ->assertTrue(isset($js_settings['entityLegalPopup']), 'Popup javascript settings found');
  $this
    ->assertEqual(entity_legal_document_title($document), $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.
  $document_uri = entity_uri(ENTITY_LEGAL_DOCUMENT_ENTITY_NAME, $document);
  $document_path = $document_uri['path'];
  $this
    ->drupalPost($document_path, array(
    'agree' => TRUE,
  ), 'Submit');

  // Ensure the popup is no longer present.
  $js_settings = $this
    ->drupalGetSettings();
  $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
    ->drupalGetSettings();
  $this
    ->assertTrue(isset($js_settings['entityLegalPopup']), 'Popup javascript settings found');
  $this
    ->assertEqual(entity_legal_document_title($document), $js_settings['entityLegalPopup'][0]['popupTitle'], 'Popup title is correct');
}