MediaWiki REL1_31
EmailNotificationSecondaryAuthenticationProviderTest.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Auth;
4
5use Psr\Log\LoggerInterface;
6use Wikimedia\TestingAccessWrapper;
7
8class EmailNotificationSecondaryAuthenticationProviderTest extends \PHPUnit\Framework\TestCase {
9 public function testConstructor() {
10 $config = new \HashConfig( [
11 'EnableEmail' => true,
12 'EmailAuthentication' => true,
13 ] );
14
16 $provider->setConfig( $config );
17 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
18 $this->assertTrue( $providerPriv->sendConfirmationEmail );
19
21 'sendConfirmationEmail' => false,
22 ] );
23 $provider->setConfig( $config );
24 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
25 $this->assertFalse( $providerPriv->sendConfirmationEmail );
26 }
27
33 public function testGetAuthenticationRequests( $action, $expected ) {
35 'sendConfirmationEmail' => true,
36 ] );
37 $this->assertSame( $expected, $provider->getAuthenticationRequests( $action, [] ) );
38 }
39
41 return [
47 ];
48 }
49
52 'sendConfirmationEmail' => true,
53 ] );
54 $this->assertEquals( AuthenticationResponse::newAbstain(),
55 $provider->beginSecondaryAuthentication( \User::newFromName( 'Foo' ), [] ) );
56 }
57
59 $authManager = new AuthManager( new \FauxRequest(), new \HashConfig() );
60
61 $creator = $this->getMockBuilder( \User::class )->getMock();
62 $userWithoutEmail = $this->getMockBuilder( \User::class )->getMock();
63 $userWithoutEmail->expects( $this->any() )->method( 'getEmail' )->willReturn( '' );
64 $userWithoutEmail->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf();
65 $userWithoutEmail->expects( $this->never() )->method( 'sendConfirmationMail' );
66 $userWithEmailError = $this->getMockBuilder( \User::class )->getMock();
67 $userWithEmailError->expects( $this->any() )->method( 'getEmail' )->willReturn( 'foo@bar.baz' );
68 $userWithEmailError->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf();
69 $userWithEmailError->expects( $this->any() )->method( 'sendConfirmationMail' )
70 ->willReturn( \Status::newFatal( 'fail' ) );
71 $userExpectsConfirmation = $this->getMockBuilder( \User::class )->getMock();
72 $userExpectsConfirmation->expects( $this->any() )->method( 'getEmail' )
73 ->willReturn( 'foo@bar.baz' );
74 $userExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' )
75 ->willReturnSelf();
76 $userExpectsConfirmation->expects( $this->once() )->method( 'sendConfirmationMail' )
77 ->willReturn( \Status::newGood() );
78 $userNotExpectsConfirmation = $this->getMockBuilder( \User::class )->getMock();
79 $userNotExpectsConfirmation->expects( $this->any() )->method( 'getEmail' )
80 ->willReturn( 'foo@bar.baz' );
81 $userNotExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' )
82 ->willReturnSelf();
83 $userNotExpectsConfirmation->expects( $this->never() )->method( 'sendConfirmationMail' );
84
86 'sendConfirmationEmail' => false,
87 ] );
88 $provider->setManager( $authManager );
89 $provider->beginSecondaryAccountCreation( $userNotExpectsConfirmation, $creator, [] );
90
92 'sendConfirmationEmail' => true,
93 ] );
94 $provider->setManager( $authManager );
95 $provider->beginSecondaryAccountCreation( $userWithoutEmail, $creator, [] );
96 $provider->beginSecondaryAccountCreation( $userExpectsConfirmation, $creator, [] );
97
98 // test logging of email errors
99 $logger = $this->getMockForAbstractClass( LoggerInterface::class );
100 $logger->expects( $this->once() )->method( 'warning' );
101 $provider->setLogger( $logger );
102 $provider->beginSecondaryAccountCreation( $userWithEmailError, $creator, [] );
103
104 // test disable flag used by other providers
105 $authManager->setAuthenticationSessionData( 'no-email', true );
106 $provider->setManager( $authManager );
107 $provider->beginSecondaryAccountCreation( $userNotExpectsConfirmation, $creator, [] );
108 }
109}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
WebRequest clone which takes values from a provided array.
A Config instance which stores all settings as a member variable.
This serves as the entry point to the authentication system.
const ACTION_CHANGE
Change a user's credentials.
const ACTION_REMOVE
Remove a user's credentials.
const ACTION_LINK
Link an existing user to a third-party account.
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
const ACTION_CREATE
Create a new user.
Handles email notification / email address confirmation for account creation.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:591