HHVM does not support variadic arguments with type hints. This is mostly not a big problem, because we can just drop the type hint, but for some reason PHPUnit adds a type hint of "array" when it creates mocks, so a class with a variadic method can't be mocked (at least in some cases). As such, I left alone all the classes that seem like someone might like to mock them, like Title and User. If anyone wants to mock them in the future, they'll have to switch back to func_get_args(). Some of the changes are definitely safe, like functions and test classes. In most cases, func_get_args() (and/or func_get_arg(), func_num_args() ) were only present because the code was written before we required PHP 5.6, and writing them as variadic functions is strictly superior. In some cases I left them alone, aside from HHVM compatibility: * Forwarding all arguments to another function. It's useful to keep func_get_args() here where we want to keep the list of expected arguments and their meanings in the function signature line for documentation purposes, but don't want to copy-paste a long line of argument names. * Handling deprecated calling conventions. * One or two miscellaneous cases where we're basically using the arguments individually but want to use them as an array as well for some reason. Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
175 lines
4 KiB
PHP
175 lines
4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Auth;
|
|
|
|
/**
|
|
* @group AuthManager
|
|
* @covers \MediaWiki\Auth\UserDataAuthenticationRequest
|
|
*/
|
|
class UserDataAuthenticationRequestTest extends AuthenticationRequestTestCase {
|
|
|
|
protected function getInstance( array $args = [] ) {
|
|
return new UserDataAuthenticationRequest;
|
|
}
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
$this->setMwGlobals( 'wgHiddenPrefs', [] );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providePopulateUser
|
|
* @param string $email Email to set
|
|
* @param string $realname Realname to set
|
|
* @param StatusValue $expect Expected return
|
|
*/
|
|
public function testPopulateUser( $email, $realname, $expect ) {
|
|
$user = new \User();
|
|
$user->setEmail( 'default@example.com' );
|
|
$user->setRealName( 'Fake Name' );
|
|
|
|
$req = new UserDataAuthenticationRequest;
|
|
$req->email = $email;
|
|
$req->realname = $realname;
|
|
$this->assertEquals( $expect, $req->populateUser( $user ) );
|
|
if ( $expect->isOk() ) {
|
|
$this->assertSame( $email ?: 'default@example.com', $user->getEmail() );
|
|
$this->assertSame( $realname ?: 'Fake Name', $user->getRealName() );
|
|
}
|
|
}
|
|
|
|
public static function providePopulateUser() {
|
|
$good = \StatusValue::newGood();
|
|
return [
|
|
[ 'email@example.com', 'Real Name', $good ],
|
|
[ 'email@example.com', '', $good ],
|
|
[ '', 'Real Name', $good ],
|
|
[ '', '', $good ],
|
|
[ 'invalid-email', 'Real Name', \StatusValue::newFatal( 'invalidemailaddress' ) ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideLoadFromSubmission
|
|
*/
|
|
public function testLoadFromSubmission(
|
|
array $args, array $data, $expectState, $hiddenPref = null, $enableEmail = null
|
|
) {
|
|
$this->setMwGlobals( 'wgHiddenPrefs', $hiddenPref );
|
|
$this->setMwGlobals( 'wgEnableEmail', $enableEmail );
|
|
parent::testLoadFromSubmission( $args, $data, $expectState );
|
|
}
|
|
|
|
public function provideLoadFromSubmission() {
|
|
$unhidden = [];
|
|
$hidden = [ 'realname' ];
|
|
|
|
return [
|
|
'Empty request, unhidden, email enabled' => [
|
|
[],
|
|
[],
|
|
false,
|
|
$unhidden,
|
|
true
|
|
],
|
|
'email + realname, unhidden, email enabled' => [
|
|
[],
|
|
$data = [ 'email' => 'Email', 'realname' => 'Name' ],
|
|
$data,
|
|
$unhidden,
|
|
true
|
|
],
|
|
'email empty, unhidden, email enabled' => [
|
|
[],
|
|
$data = [ 'email' => '', 'realname' => 'Name' ],
|
|
$data,
|
|
$unhidden,
|
|
true
|
|
],
|
|
'email omitted, unhidden, email enabled' => [
|
|
[],
|
|
[ 'realname' => 'Name' ],
|
|
false,
|
|
$unhidden,
|
|
true
|
|
],
|
|
'realname empty, unhidden, email enabled' => [
|
|
[],
|
|
$data = [ 'email' => 'Email', 'realname' => '' ],
|
|
$data,
|
|
$unhidden,
|
|
true
|
|
],
|
|
'realname omitted, unhidden, email enabled' => [
|
|
[],
|
|
[ 'email' => 'Email' ],
|
|
false,
|
|
$unhidden,
|
|
true
|
|
],
|
|
'Empty request, hidden, email enabled' => [
|
|
[],
|
|
[],
|
|
false,
|
|
$hidden,
|
|
true
|
|
],
|
|
'email + realname, hidden, email enabled' => [
|
|
[],
|
|
[ 'email' => 'Email', 'realname' => 'Name' ],
|
|
[ 'email' => 'Email' ],
|
|
$hidden,
|
|
true
|
|
],
|
|
'email empty, hidden, email enabled' => [
|
|
[],
|
|
$data = [ 'email' => '', 'realname' => 'Name' ],
|
|
[ 'email' => '' ],
|
|
$hidden,
|
|
true
|
|
],
|
|
'email omitted, hidden, email enabled' => [
|
|
[],
|
|
[ 'realname' => 'Name' ],
|
|
false,
|
|
$hidden,
|
|
true
|
|
],
|
|
'realname empty, hidden, email enabled' => [
|
|
[],
|
|
$data = [ 'email' => 'Email', 'realname' => '' ],
|
|
[ 'email' => 'Email' ],
|
|
$hidden,
|
|
true
|
|
],
|
|
'realname omitted, hidden, email enabled' => [
|
|
[],
|
|
[ 'email' => 'Email' ],
|
|
[ 'email' => 'Email' ],
|
|
$hidden,
|
|
true
|
|
],
|
|
'email + realname, unhidden, email disabled' => [
|
|
[],
|
|
[ 'email' => 'Email', 'realname' => 'Name' ],
|
|
[ 'realname' => 'Name' ],
|
|
$unhidden,
|
|
false
|
|
],
|
|
'email omitted, unhidden, email disabled' => [
|
|
[],
|
|
[ 'realname' => 'Name' ],
|
|
[ 'realname' => 'Name' ],
|
|
$unhidden,
|
|
false
|
|
],
|
|
'email empty, unhidden, email disabled' => [
|
|
[],
|
|
[ 'email' => '', 'realname' => 'Name' ],
|
|
[ 'realname' => 'Name' ],
|
|
$unhidden,
|
|
false
|
|
],
|
|
];
|
|
}
|
|
}
|