本文整理匯總了PHP中TestingAccessWrapper::getPrimaryAuthenticationProviders方法的典型用法代碼示例。如果您正苦於以下問題:PHP TestingAccessWrapper::getPrimaryAuthenticationProviders方法的具體用法?PHP TestingAccessWrapper::getPrimaryAuthenticationProviders怎麽用?PHP TestingAccessWrapper::getPrimaryAuthenticationProviders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TestingAccessWrapper
的用法示例。
在下文中一共展示了TestingAccessWrapper::getPrimaryAuthenticationProviders方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testForcePrimaryAuthenticationProviders
public function testForcePrimaryAuthenticationProviders()
{
$mockA = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mockB = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mockB2 = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mockA->expects($this->any())->method('getUniqueId')->will($this->returnValue('A'));
$mockB->expects($this->any())->method('getUniqueId')->will($this->returnValue('B'));
$mockB2->expects($this->any())->method('getUniqueId')->will($this->returnValue('B'));
$this->primaryauthMocks = [$mockA];
$this->logger = new \TestLogger(true);
// Test without first initializing the configured providers
$this->initializeManager();
$this->manager->forcePrimaryAuthenticationProviders([$mockB], 'testing');
$this->assertSame(['B' => $mockB], $this->managerPriv->getPrimaryAuthenticationProviders());
$this->assertSame(null, $this->managerPriv->getAuthenticationProvider('A'));
$this->assertSame($mockB, $this->managerPriv->getAuthenticationProvider('B'));
$this->assertSame([[LogLevel::WARNING, 'Overriding AuthManager primary authn because testing']], $this->logger->getBuffer());
$this->logger->clearBuffer();
// Test with first initializing the configured providers
$this->initializeManager();
$this->assertSame($mockA, $this->managerPriv->getAuthenticationProvider('A'));
$this->assertSame(null, $this->managerPriv->getAuthenticationProvider('B'));
$this->request->getSession()->setSecret('AuthManager::authnState', 'test');
$this->request->getSession()->setSecret('AuthManager::accountCreationState', 'test');
$this->manager->forcePrimaryAuthenticationProviders([$mockB], 'testing');
$this->assertSame(['B' => $mockB], $this->managerPriv->getPrimaryAuthenticationProviders());
$this->assertSame(null, $this->managerPriv->getAuthenticationProvider('A'));
$this->assertSame($mockB, $this->managerPriv->getAuthenticationProvider('B'));
$this->assertNull($this->request->getSession()->getSecret('AuthManager::authnState'));
$this->assertNull($this->request->getSession()->getSecret('AuthManager::accountCreationState'));
$this->assertSame([[LogLevel::WARNING, 'Overriding AuthManager primary authn because testing'], [LogLevel::WARNING, 'PrimaryAuthenticationProviders have already been accessed! I hope nothing breaks.']], $this->logger->getBuffer());
$this->logger->clearBuffer();
// Test duplicate IDs
$this->initializeManager();
try {
$this->manager->forcePrimaryAuthenticationProviders([$mockB, $mockB2], 'testing');
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$class1 = get_class($mockB);
$class2 = get_class($mockB2);
$this->assertSame("Duplicate specifications for id B (classes {$class2} and {$class1})", $ex->getMessage());
}
// Wrong classes
$mock = $this->getMockForAbstractClass(AuthenticationProvider::class);
$mock->expects($this->any())->method('getUniqueId')->will($this->returnValue('X'));
$class = get_class($mock);
try {
$this->manager->forcePrimaryAuthenticationProviders([$mock], 'testing');
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$this->assertSame("Expected instance of MediaWiki\\Auth\\PrimaryAuthenticationProvider, got {$class}", $ex->getMessage());
}
}