public function CasRouteEnhancerTest::testEnhance in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Routing/CasRouteEnhancerTest.php \Drupal\Tests\cas\Unit\Routing\CasRouteEnhancerTest::testEnhance()
Tests the enhance() method.
@covers ::enhance
@dataProvider enhanceDataProvider
File
- tests/
src/ Unit/ Routing/ CasRouteEnhancerTest.php, line 72
Class
- CasRouteEnhancerTest
- CasRouteEnhancer unit tests.
Namespace
Drupal\Tests\cas\Unit\RoutingCode
public function testEnhance($path, $cas_logout_enabled, $is_cas_user) {
$session = $this
->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session')
->disableOriginalConstructor()
->setMethods([
'get',
])
->getMock();
$session
->expects($this
->any())
->method('get')
->with('is_cas_user')
->willReturn($is_cas_user);
$this->request
->expects($this
->any())
->method('getSession')
->willReturn($session);
$this->route
->expects($this
->any())
->method('getPath')
->willReturn($path);
$enhancer = new CasRouteEnhancer($this
->getConfigFactoryStub([
'cas.settings' => [
'logout.cas_logout' => $cas_logout_enabled,
],
]));
$originalDefaults = [
'_route_object' => $this->route,
];
$newDefaults = $enhancer
->enhance($originalDefaults, $this->request);
// The controller should only be changed to our custom logout controller
// if CAS logout is enabled AND the currently logged in user logged in
// via CAS AND we're on the correct path.
if ($path == '/user/logout' && $cas_logout_enabled && $is_cas_user) {
$this
->assertArrayHasKey('_controller', $newDefaults, '$newDefaults array does not contain "_controller" key.');
$this
->assertNotEmpty($newDefaults['_controller']);
$this
->assertEquals($newDefaults['_controller'], '\\Drupal\\cas\\Controller\\LogoutController::logout');
}
else {
$this
->assertEquals($originalDefaults, $newDefaults);
}
}