MediaWiki  1.30.2
EmailNotificationSecondaryAuthenticationProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
5 use Psr\Log\LoggerInterface;
6 use Wikimedia\TestingAccessWrapper;
7 
8 class 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' )->getMock();
62  $userWithoutEmail = $this->getMockBuilder( 'User' )->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' )->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' )->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' )->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 }
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
MediaWiki\$action
String $action
Cache what action this request is.
Definition: MediaWiki.php:47
HashConfig
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:550
MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProviderTest\provideGetAuthenticationRequests
provideGetAuthenticationRequests()
Definition: EmailNotificationSecondaryAuthenticationProviderTest.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProviderTest
Definition: EmailNotificationSecondaryAuthenticationProviderTest.php:8
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
MediaWiki\Auth\AuthManager\ACTION_CREATE
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:89
MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProviderTest\testGetAuthenticationRequests
testGetAuthenticationRequests( $action, $expected)
provideGetAuthenticationRequests
Definition: EmailNotificationSecondaryAuthenticationProviderTest.php:33
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
MediaWiki\Auth\AuthManager\ACTION_CHANGE
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:99
MediaWiki\Auth\AuthManager\ACTION_LINK
const ACTION_LINK
Link an existing user to a third-party account.
Definition: AuthManager.php:94
MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProviderTest\testBeginSecondaryAccountCreation
testBeginSecondaryAccountCreation()
Definition: EmailNotificationSecondaryAuthenticationProviderTest.php:58
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:82
MediaWiki\Auth\AuthManager\ACTION_REMOVE
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:101
MediaWiki\$config
Config $config
Definition: MediaWiki.php:42
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:84
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProviderTest\testConstructor
testConstructor()
Definition: EmailNotificationSecondaryAuthenticationProviderTest.php:9
MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProvider
Handles email notification / email address confirmation for account creation.
Definition: EmailNotificationSecondaryAuthenticationProvider.php:13
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProviderTest\testBeginSecondaryAuthentication
testBeginSecondaryAuthentication()
Definition: EmailNotificationSecondaryAuthenticationProviderTest.php:50