CasUserInteractionTest.php in CAS 8
File
tests/src/Functional/CasUserInteractionTest.php
View source
<?php
namespace Drupal\Tests\cas\Functional;
use Drupal\Tests\cas\Traits\CasTestTrait;
class CasUserInteractionTest extends CasBrowserTestBase {
use CasTestTrait {
casLogin as traitCasLogin;
}
public static $modules = [
'block',
'cas',
'cas_mock_server',
'cas_user_interaction_test',
];
protected function setUp() {
parent::setUp();
$account = $this
->createUser([], 'beavis');
$this
->createCasUser('beavis', 'beavis@example.com', 'needtp', [
'firstname' => 'Beavis',
'lastname' => 'El Gran Cornholio',
], $account);
$this
->placeBlock('system_menu_block:account');
}
public function testUserInteraction() {
\Drupal::state()
->set('cas_user_interaction_test.changed', FALSE);
$this
->casLogin();
$this
->assertUserLoggedIn();
$this
->drupalLogout();
\Drupal::state()
->set('cas_user_interaction_test.changed', TRUE);
$this
->casLogin();
$this
->assertUserNotLoggedIn();
$this
->assertSession()
->pageTextContains("I agree with the 'Legal Notice'");
$page = $this
->getSession()
->getPage();
$page
->pressButton('I agree');
$this
->assertSession()
->pageTextContains("I agree with the 'Legal Notice' field is required.");
$this
->assertUserNotLoggedIn();
$page
->checkField("I agree with the 'Legal Notice'");
$page
->pressButton('I agree');
$this
->assertUserLoggedIn();
}
protected function casLogin() {
$this
->traitCasLogin('beavis@example.com', 'needtp');
}
protected function assertUserLoggedIn() {
$this
->assertSession()
->linkExists('My account');
}
protected function assertUserNotLoggedIn() {
$this
->assertSession()
->linkExists('Log in');
}
}