View source
<?php
namespace Drupal\entity_legal\Tests;
class EntityLegalMethodsTest extends EntityLegalTestBase {
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(),
]);
$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');
$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');
}
public function testPopupMethod() {
$document = $this
->createDocument(TRUE, TRUE, [
'existing_users' => [
'require_method' => 'popup',
],
]);
$this
->createDocumentVersion($document, TRUE);
$account = $this
->createUserWithAcceptancePermissions($document);
$this
->drupalLogin($account);
$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');
$document_url = $document
->toUrl();
$document_path = $document_url
->toString();
$this
->drupalPostForm($document_path, [
'agree' => TRUE,
], 'Submit');
$js_settings = $this
->getDrupalSettings();
$this
->assertFalse(isset($js_settings['entityLegalPopup']), 'Popup javascript settings not found');
$this
->createDocumentVersion($document, TRUE);
$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');
}
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');
$document_url = $document
->toUrl();
$document_path = $document_url
->toString();
$this
->assertLinkByHref($document_path, 0, 'Link to document found');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/people/accounts/form-display');
$this
->assertText('legal_' . $document
->id());
}
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');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/people/accounts/form-display');
$this
->assertText('legal_' . $document
->id());
}
}