X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fuser%2FPasswordResetTest.php;h=53f02df69c1c33d4e57087d40800aab603aa0bf7;hb=7471e1db1b613d035f981f489f8683a177acff7e;hp=3363bca5249735e43be03cacdf2044064b1fa62c;hpb=eb72adcb4e28eedc1806d845355856bd6f97dadb;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/user/PasswordResetTest.php b/tests/phpunit/includes/user/PasswordResetTest.php index 3363bca524..53f02df69c 100644 --- a/tests/phpunit/includes/user/PasswordResetTest.php +++ b/tests/phpunit/includes/user/PasswordResetTest.php @@ -10,8 +10,7 @@ class PasswordResetTest extends PHPUnit_Framework_TestCase { * @dataProvider provideIsAllowed */ public function testIsAllowed( $passwordResetRoutes, $enableEmail, - $allowsAuthenticationDataChange, $canEditPrivate, $canSeePassword, - $userIsBlocked, $isAllowed + $allowsAuthenticationDataChange, $canEditPrivate, $block, $globalBlock, $isAllowed ) { $config = new HashConfig( [ 'PasswordResetRoutes' => $passwordResetRoutes, @@ -25,13 +24,12 @@ class PasswordResetTest extends PHPUnit_Framework_TestCase { $user = $this->getMockBuilder( User::class )->getMock(); $user->expects( $this->any() )->method( 'getName' )->willReturn( 'Foo' ); - $user->expects( $this->any() )->method( 'isBlocked' )->willReturn( $userIsBlocked ); + $user->expects( $this->any() )->method( 'getBlock' )->willReturn( $block ); + $user->expects( $this->any() )->method( 'getGlobalBlock' )->willReturn( $globalBlock ); $user->expects( $this->any() )->method( 'isAllowed' ) - ->will( $this->returnCallback( function ( $perm ) use ( $canEditPrivate, $canSeePassword ) { + ->will( $this->returnCallback( function ( $perm ) use ( $canEditPrivate ) { if ( $perm === 'editmyprivateinfo' ) { return $canEditPrivate; - } elseif ( $perm === 'passwordreset' ) { - return $canSeePassword; } else { $this->fail( 'Unexpected permission check' ); } @@ -44,67 +42,103 @@ class PasswordResetTest extends PHPUnit_Framework_TestCase { public function provideIsAllowed() { return [ - [ + 'no routes' => [ 'passwordResetRoutes' => [], 'enableEmail' => true, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => true, - 'canSeePassword' => true, - 'userIsBlocked' => false, + 'block' => null, + 'globalBlock' => null, 'isAllowed' => false, ], - [ + 'email disabled' => [ 'passwordResetRoutes' => [ 'username' => true ], 'enableEmail' => false, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => true, - 'canSeePassword' => true, - 'userIsBlocked' => false, + 'block' => null, + 'globalBlock' => null, 'isAllowed' => false, ], - [ + 'auth data change disabled' => [ 'passwordResetRoutes' => [ 'username' => true ], 'enableEmail' => true, 'allowsAuthenticationDataChange' => false, 'canEditPrivate' => true, - 'canSeePassword' => true, - 'userIsBlocked' => false, + 'block' => null, + 'globalBlock' => null, 'isAllowed' => false, ], - [ + 'cannot edit private data' => [ 'passwordResetRoutes' => [ 'username' => true ], 'enableEmail' => true, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => false, - 'canSeePassword' => true, - 'userIsBlocked' => false, + 'block' => null, + 'globalBlock' => null, 'isAllowed' => false, ], - [ + 'blocked with account creation disabled' => [ 'passwordResetRoutes' => [ 'username' => true ], 'enableEmail' => true, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => true, - 'canSeePassword' => true, - 'userIsBlocked' => true, + 'block' => new Block( [ 'createAccount' => true ] ), + 'globalBlock' => null, 'isAllowed' => false, ], - [ + 'blocked w/o account creation disabled' => [ 'passwordResetRoutes' => [ 'username' => true ], 'enableEmail' => true, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => true, - 'canSeePassword' => false, - 'userIsBlocked' => false, + 'block' => new Block( [] ), + 'globalBlock' => null, 'isAllowed' => true, ], - [ + 'using blocked proxy' => [ 'passwordResetRoutes' => [ 'username' => true ], 'enableEmail' => true, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => true, - 'canSeePassword' => true, - 'userIsBlocked' => false, + 'block' => new Block( [ 'systemBlock' => 'proxy' ] ), + 'globalBlock' => null, + 'isAllowed' => false, + ], + 'globally blocked with account creation disabled' => [ + 'passwordResetRoutes' => [ 'username' => true ], + 'enableEmail' => true, + 'allowsAuthenticationDataChange' => true, + 'canEditPrivate' => true, + 'block' => null, + 'globalBlock' => new Block( [ 'systemBlock' => 'global-block', 'createAccount' => true ] ), + 'isAllowed' => false, + ], + 'globally blocked with account creation not disabled' => [ + 'passwordResetRoutes' => [ 'username' => true ], + 'enableEmail' => true, + 'allowsAuthenticationDataChange' => true, + 'canEditPrivate' => true, + 'block' => null, + 'globalBlock' => new Block( [ 'systemBlock' => 'global-block', 'createAccount' => false ] ), + 'isAllowed' => true, + ], + 'blocked via wgSoftBlockRanges' => [ + 'passwordResetRoutes' => [ 'username' => true ], + 'enableEmail' => true, + 'allowsAuthenticationDataChange' => true, + 'canEditPrivate' => true, + 'block' => new Block( [ 'systemBlock' => 'wgSoftBlockRanges', 'anonOnly' => true ] ), + 'globalBlock' => null, + 'isAllowed' => true, + ], + 'all OK' => [ + 'passwordResetRoutes' => [ 'username' => true ], + 'enableEmail' => true, + 'allowsAuthenticationDataChange' => true, + 'canEditPrivate' => true, + 'block' => null, + 'globalBlock' => null, 'isAllowed' => true, ], ];