CasForcedLoginControllerTest.php in CAS 2.x
File
tests/src/Functional/CasForcedLoginControllerTest.php
View source
<?php
namespace Drupal\Tests\cas\Functional;
use Drupal\Component\Utility\UrlHelper;
class CasForcedLoginControllerTest extends CasBrowserTestBase {
protected static $modules = [
'cas',
'page_cache',
'dynamic_page_cache',
];
public function testForcedLoginRoute() {
$admin = $this
->drupalCreateUser([
'administer account settings',
]);
$this
->drupalLogin($admin);
$edit = [
'server[hostname]' => 'fakecasserver.localhost',
'server[path]' => '/auth',
];
$this
->drupalPostForm('/admin/config/people/cas', $edit, 'Save configuration');
$this
->drupalLogout();
$this
->disableRedirects();
$this
->prepareRequest();
$session = $this
->getSession();
$params_to_test = [
[],
[
'returnto' => 'node/1',
],
[
'foo' => 'bar',
'buzz' => 'baz',
],
];
foreach ($params_to_test as $params) {
$path = $this
->buildUrl('cas', [
'query' => $params,
'absolute' => TRUE,
]);
$session
->visit($path);
$this
->assertEquals(302, $session
->getStatusCode());
$expected_redirect_location = 'https://fakecasserver.localhost/auth/login?' . UrlHelper::buildQuery([
'service' => $this
->buildServiceUrlWithParams($params),
]);
$this
->assertEquals($expected_redirect_location, $session
->getResponseHeader('Location'));
}
}
}