class AuthenticationManagerTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php \Drupal\Tests\Core\Authentication\AuthenticationManagerTest
- 8.9.x core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php \Drupal\Tests\Core\Authentication\AuthenticationManagerTest
- 10 core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php \Drupal\Tests\Core\Authentication\AuthenticationManagerTest
@coversDefaultClass \Drupal\Core\Authentication\AuthenticationManager @group Authentication
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Authentication\AuthenticationManagerTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of AuthenticationManagerTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Authentication/ AuthenticationManagerTest.php, line 20
Namespace
Drupal\Tests\Core\AuthenticationView source
class AuthenticationManagerTest extends UnitTestCase {
/**
* @covers ::defaultFilter
* @covers ::applyFilter
*
* @dataProvider providerTestDefaultFilter
*/
public function testDefaultFilter($applies, $has_route, $auth_option, $provider_id, $global) : void {
$auth_provider = $this->createMock('Drupal\\Core\\Authentication\\AuthenticationProviderInterface');
$auth_collector = new AuthenticationCollector();
$auth_collector->addProvider($auth_provider, $provider_id, 0, $global);
$authentication_manager = new AuthenticationManager($auth_collector);
$request = new Request();
if ($has_route) {
$route = new Route('/example');
if ($auth_option) {
$route->setOption('_auth', $auth_option);
}
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, $route);
}
$this->assertSame($applies, $authentication_manager->appliesToRoutedRequest($request, FALSE));
}
/**
* @covers ::applyFilter
*/
public function testApplyFilterWithFilterProvider() : void {
$auth_provider = $this->createMock('Drupal\\Tests\\Core\\Authentication\\TestAuthenticationProviderInterface');
$auth_provider->expects($this->once())
->method('appliesToRoutedRequest')
->willReturn(TRUE);
$authentication_collector = new AuthenticationCollector();
$authentication_collector->addProvider($auth_provider, 'filtered', 0);
$authentication_manager = new AuthenticationManager($authentication_collector);
$request = new Request();
$this->assertTrue($authentication_manager->appliesToRoutedRequest($request, FALSE));
}
/**
* Provides data to self::testDefaultFilter().
*/
public static function providerTestDefaultFilter() {
$data = [];
// No route, cookie is global, should apply.
$data[] = [
TRUE,
FALSE,
[],
'cookie',
TRUE,
];
// No route, cookie is not global, should not apply.
$data[] = [
FALSE,
FALSE,
[],
'cookie',
FALSE,
];
// Route, no _auth, cookie is global, should apply.
$data[] = [
TRUE,
TRUE,
[],
'cookie',
TRUE,
];
// Route, no _auth, cookie is not global, should not apply.
$data[] = [
FALSE,
TRUE,
[],
'cookie',
FALSE,
];
// Route, with _auth and non-matching provider, should not apply.
$data[] = [
FALSE,
TRUE,
[
'basic_auth',
],
'cookie',
TRUE,
];
// Route, with _auth and matching provider should not apply.
$data[] = [
TRUE,
TRUE,
[
'basic_auth',
],
'basic_auth',
TRUE,
];
return $data;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
AuthenticationManagerTest::providerTestDefaultFilter | public static | function | Provides data to self::testDefaultFilter(). | |
AuthenticationManagerTest::testApplyFilterWithFilterProvider | public | function | @covers ::applyFilter | |
AuthenticationManagerTest::testDefaultFilter | public | function | @covers ::defaultFilter @covers ::applyFilter |
|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.