class EntityLegalMethodsTest in Entity Legal 3.0.x
Same name and namespace in other branches
- 8.2 src/Tests/EntityLegalMethodsTest.php \Drupal\entity_legal\Tests\EntityLegalMethodsTest
- 4.0.x src/Tests/EntityLegalMethodsTest.php \Drupal\entity_legal\Tests\EntityLegalMethodsTest
Tests methods of encouraging users to accept legal documents.
@group entity_legal
Hierarchy
- class \Drupal\entity_legal\Tests\EntityLegalTestBase extends \Drupal\simpletest\WebTestBase uses EntityLegalTestTrait
- class \Drupal\entity_legal\Tests\EntityLegalMethodsTest
Expanded class hierarchy of EntityLegalMethodsTest
File
- src/
Tests/ EntityLegalMethodsTest.php, line 10
Namespace
Drupal\entity_legal\TestsView source
class EntityLegalMethodsTest extends EntityLegalTestBase {
/**
* Drupal message method test.
*/
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');
}
/**
* JQuery UI dialog method test.
*/
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');
}
/**
* User signup form with link method test.
*/
public function testSignupFormLinkMethod() {
$document = $this
->createDocument(TRUE, TRUE, [
'new_users' => [
'require_method' => 'form_link',
],
]);
$this
->createDocumentVersion($document, TRUE);
$this
->drupalGet('user/register');
$this
->assertFieldByName('legal_' . $document
->id(), NULL, 'Agree checkbox found');
/** @var \Drupal\Core\Url $document_url */
$document_url = $document
->toUrl();
$document_path = $document_url
->toString();
$this
->assertLinkByHref($document_path, 0, 'Link to document found');
// Ensure the field extra field is available for re-ordering.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/people/accounts/form-display');
$this
->assertText('legal_' . $document
->id());
}
/**
* User signup form with inline method test.
*/
public function testProfileFormInlineMethod() {
$document = $this
->createDocument(TRUE, TRUE, [
'new_users' => [
'require_method' => 'form_inline',
],
]);
$this
->createDocumentVersion($document, TRUE);
$this
->drupalGet('user/register');
$this
->assertFieldByName('legal_' . $document
->id(), NULL, 'Agree checkbox found');
$this
->assertRaw('<div class="clearfix text-formatted field field--name-entity-legal-document-text', 'Document markup found on register page');
// Ensure the field extra field is available for re-ordering.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/people/accounts/form-display');
$this
->assertText('legal_' . $document
->id());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityLegalMethodsTest:: |
public | function | Drupal message method test. | |
EntityLegalMethodsTest:: |
public | function | JQuery UI dialog method test. | |
EntityLegalMethodsTest:: |
public | function | User signup form with inline method test. | |
EntityLegalMethodsTest:: |
public | function | User signup form with link method test. | |
EntityLegalTestBase:: |
protected | property | The administrative user to use for tests. | |
EntityLegalTestBase:: |
public static | property | Modules to enable. | |
EntityLegalTestBase:: |
public | function | Get an entity bypassing static and db cache. | |
EntityLegalTestBase:: |
protected | function | Ensures generated names are lower case. | |
EntityLegalTestBase:: |
protected | function | ||
EntityLegalTestTrait:: |
protected | function | Creates a random legal document entity. | |
EntityLegalTestTrait:: |
protected | function | Creates a document version. | |
EntityLegalTestTrait:: |
protected | function | Creates an account that is able to view and re-accept a given document. |