View source
<?php
namespace Drupal\Tests\legal\Functional;
use Drupal\user\Entity\User;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class LoginTest extends LegalTestBase {
use StringTranslationTrait;
public function testLogin() {
$this
->drupalPostForm('user/login', $this->loginDetails, 'Log in');
$current_url = $this
->getUrl();
$expected_url = substr($current_url, strlen($this->baseUrl), 20);
$this
->assertEquals($expected_url, '/legal_accept?token=');
$this
->assertResponse(200);
$edit = [
'edit-legal-accept' => TRUE,
];
$this
->submitForm($edit, 'Confirm', 'legal-login');
$account = User::load($this->uid);
$this
->drupalUserIsLoggedIn($account);
$current_url = $this
->getUrl();
$expected_url = $this->baseUrl . '/user/' . $this->uid;
$this
->assertEquals($current_url, $expected_url);
}
public function testScrollBox() {
$this
->config('legal.settings')
->set('login_terms_style', 0)
->set('login_container', 0)
->save();
$this
->drupalPostForm('user/login', $this->loginDetails, 'Log in');
$readonly = $this
->assertSession()
->elementExists('css', 'textarea#edit-conditions')
->getAttribute('readonly');
$this
->assertEquals($readonly, 'readonly');
$this
->assertSession()
->elementTextContains('css', 'textarea#edit-conditions', $this->conditionsPlainText);
}
public function testScrollBoxCss() {
$this
->config('legal.settings')
->set('login_terms_style', 1)
->set('login_container', 0)
->save();
$this
->drupalPostForm('user/login', $this->loginDetails, 'Log in');
$this
->assertSession()
->elementExists('css', '#legal-login > div.legal-terms-scroll');
$this
->assertSession()
->elementContains('css', '#legal-login > div.legal-terms-scroll', $this->conditions);
}
public function testHtml() {
$this
->config('legal.settings')
->set('login_terms_style', 2)
->set('login_container', 0)
->save();
$this
->drupalPostForm('user/login', $this->loginDetails, 'Log in');
$this
->assertSession()
->elementContains('css', '#legal-login > div.legal-terms', $this->conditions);
}
public function testPageLink() {
$this
->config('legal.settings')
->set('login_terms_style', 3)
->set('login_container', 0)
->save();
$this
->drupalPostForm('user/login', $this->loginDetails, $this
->t('Log in'));
$this
->assertSession()
->elementExists('css', '#legal-login > div.js-form-item.form-item.js-form-type-checkbox.form-type-checkbox.js-form-item-legal-accept.form-item-legal-accept > label > a');
$this
->click('#legal-login > div.js-form-item.form-item.js-form-type-checkbox.form-type-checkbox.js-form-item-legal-accept.form-item-legal-accept > label > a');
$current_url = $this
->getUrl();
$expected_url = $this->baseUrl . '/legal';
$this
->assertEquals($current_url, $expected_url);
}
}