wiki.techinc.nl/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php
umherirrender 34fe90ac52 Remove empty lines at end of functions
It looks like there is something missing after the last statement
Also remove some other empty lines at begin of functions, ifs or loops
while at these files

Change-Id: Ib00b5cfd31ca4dcd0c32ce33754d3c80bae70641
2016-11-05 11:55:10 +01:00

108 lines
4.4 KiB
PHP

<?php
namespace MediaWiki\Auth;
use Psr\Log\LoggerInterface;
class EmailNotificationSecondaryAuthenticationProviderTest extends \PHPUnit_Framework_TestCase {
public function testConstructor() {
$config = new \HashConfig( [
'EnableEmail' => true,
'EmailAuthentication' => true,
] );
$provider = new EmailNotificationSecondaryAuthenticationProvider();
$provider->setConfig( $config );
$providerPriv = \TestingAccessWrapper::newFromObject( $provider );
$this->assertTrue( $providerPriv->sendConfirmationEmail );
$provider = new EmailNotificationSecondaryAuthenticationProvider( [
'sendConfirmationEmail' => false,
] );
$provider->setConfig( $config );
$providerPriv = \TestingAccessWrapper::newFromObject( $provider );
$this->assertFalse( $providerPriv->sendConfirmationEmail );
}
/**
* @dataProvider provideGetAuthenticationRequests
* @param string $action
* @param AuthenticationRequest[] $expected
*/
public function testGetAuthenticationRequests( $action, $expected ) {
$provider = new EmailNotificationSecondaryAuthenticationProvider( [
'sendConfirmationEmail' => true,
] );
$this->assertSame( $expected, $provider->getAuthenticationRequests( $action, [] ) );
}
public function provideGetAuthenticationRequests() {
return [
[ AuthManager::ACTION_LOGIN, [] ],
[ AuthManager::ACTION_CREATE, [] ],
[ AuthManager::ACTION_LINK, [] ],
[ AuthManager::ACTION_CHANGE, [] ],
[ AuthManager::ACTION_REMOVE, [] ],
];
}
public function testBeginSecondaryAuthentication() {
$provider = new EmailNotificationSecondaryAuthenticationProvider( [
'sendConfirmationEmail' => true,
] );
$this->assertEquals( AuthenticationResponse::newAbstain(),
$provider->beginSecondaryAuthentication( \User::newFromName( 'Foo' ), [] ) );
}
public function testBeginSecondaryAccountCreation() {
$authManager = new AuthManager( new \FauxRequest(), new \HashConfig() );
$creator = $this->getMock( 'User' );
$userWithoutEmail = $this->getMock( 'User' );
$userWithoutEmail->expects( $this->any() )->method( 'getEmail' )->willReturn( '' );
$userWithoutEmail->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf();
$userWithoutEmail->expects( $this->never() )->method( 'sendConfirmationMail' );
$userWithEmailError = $this->getMock( 'User' );
$userWithEmailError->expects( $this->any() )->method( 'getEmail' )->willReturn( 'foo@bar.baz' );
$userWithEmailError->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf();
$userWithEmailError->expects( $this->any() )->method( 'sendConfirmationMail' )
->willReturn( \Status::newFatal( 'fail' ) );
$userExpectsConfirmation = $this->getMock( 'User' );
$userExpectsConfirmation->expects( $this->any() )->method( 'getEmail' )
->willReturn( 'foo@bar.baz' );
$userExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' )
->willReturnSelf();
$userExpectsConfirmation->expects( $this->once() )->method( 'sendConfirmationMail' )
->willReturn( \Status::newGood() );
$userNotExpectsConfirmation = $this->getMock( 'User' );
$userNotExpectsConfirmation->expects( $this->any() )->method( 'getEmail' )
->willReturn( 'foo@bar.baz' );
$userNotExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' )
->willReturnSelf();
$userNotExpectsConfirmation->expects( $this->never() )->method( 'sendConfirmationMail' );
$provider = new EmailNotificationSecondaryAuthenticationProvider( [
'sendConfirmationEmail' => false,
] );
$provider->setManager( $authManager );
$provider->beginSecondaryAccountCreation( $userNotExpectsConfirmation, $creator, [] );
$provider = new EmailNotificationSecondaryAuthenticationProvider( [
'sendConfirmationEmail' => true,
] );
$provider->setManager( $authManager );
$provider->beginSecondaryAccountCreation( $userWithoutEmail, $creator, [] );
$provider->beginSecondaryAccountCreation( $userExpectsConfirmation, $creator, [] );
// test logging of email errors
$logger = $this->getMockForAbstractClass( LoggerInterface::class );
$logger->expects( $this->once() )->method( 'warning' );
$provider->setLogger( $logger );
$provider->beginSecondaryAccountCreation( $userWithEmailError, $creator, [] );
// test disable flag used by other providers
$authManager->setAuthenticationSessionData( 'no-email', true );
$provider->setManager( $authManager );
$provider->beginSecondaryAccountCreation( $userNotExpectsConfirmation, $creator, [] );
}
}