diff options
Diffstat (limited to 'tests/Core/Controller')
-rw-r--r-- | tests/Core/Controller/AutoCompleteControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Core/Controller/ClientFlowLoginControllerTest.php | 30 | ||||
-rw-r--r-- | tests/Core/Controller/LoginControllerTest.php | 100 | ||||
-rw-r--r-- | tests/Core/Controller/LostControllerTest.php | 34 | ||||
-rw-r--r-- | tests/Core/Controller/TwoFactorChallengeControllerTest.php | 14 | ||||
-rw-r--r-- | tests/Core/Controller/WipeControllerTest.php | 2 |
6 files changed, 114 insertions, 68 deletions
diff --git a/tests/Core/Controller/AutoCompleteControllerTest.php b/tests/Core/Controller/AutoCompleteControllerTest.php index 23bd03be7af..23fd0ac8399 100644 --- a/tests/Core/Controller/AutoCompleteControllerTest.php +++ b/tests/Core/Controller/AutoCompleteControllerTest.php @@ -42,7 +42,7 @@ class AutoCompleteControllerTest extends TestCase { ); } - public function searchDataProvider() { + public static function searchDataProvider(): array { return [ [ #0 – regular search // searchResults diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index 591a3027e96..b10055ef542 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -118,10 +118,6 @@ class ClientFlowLoginControllerTest extends TestCase { public function testShowAuthPickerPageWithOcsHeader(): void { $this->request ->method('getHeader') - ->withConsecutive( - ['USER_AGENT'], - ['OCS-APIREQUEST'] - ) ->willReturnMap([ ['USER_AGENT', 'Mac OS X Sync Client'], ['OCS-APIREQUEST', 'true'], @@ -181,10 +177,6 @@ class ClientFlowLoginControllerTest extends TestCase { public function testShowAuthPickerPageWithOauth(): void { $this->request ->method('getHeader') - ->withConsecutive( - ['USER_AGENT'], - ['OCS-APIREQUEST'] - ) ->willReturnMap([ ['USER_AGENT', 'Mac OS X Sync Client'], ['OCS-APIREQUEST', 'false'], @@ -404,20 +396,20 @@ class ClientFlowLoginControllerTest extends TestCase { public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $redirectUrl): void { $this->session ->method('get') - ->withConsecutive( - ['client.flow.state.token'], - ['oauth.state'] - ) ->willReturnMap([ ['client.flow.state.token', 'MyStateToken'], ['oauth.state', 'MyOauthState'], ]); + $calls = [ + 'client.flow.state.token', + 'oauth.state', + ]; $this->session ->method('remove') - ->withConsecutive( - ['client.flow.state.token'], - ['oauth.state'] - ); + ->willReturnCallback(function ($key) use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, $key); + }); $this->session ->expects($this->once()) ->method('getId') @@ -439,10 +431,6 @@ class ClientFlowLoginControllerTest extends TestCase { ->willReturn('MyPassword'); $this->random ->method('generate') - ->withConsecutive( - [72], - [128] - ) ->willReturnMap([ [72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyGeneratedToken'], [128, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyAccessCode'], @@ -561,7 +549,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } - public function dataGeneratePasswordWithHttpsProxy() { + public static function dataGeneratePasswordWithHttpsProxy(): array { return [ [ [ diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index a6438a35af0..d049203c302 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -255,9 +255,9 @@ class LoginControllerTest extends TestCase { ], ] ); - $this->initialState->expects($this->exactly(13)) - ->method('provideInitialState') - ->withConsecutive([ + + $calls = [ + [ 'loginMessages', [ 'MessageArray1', @@ -265,17 +265,26 @@ class LoginControllerTest extends TestCase { 'This community release of Nextcloud is unsupported and push notifications are limited.', ], ], + [ + 'loginErrors', [ - 'loginErrors', - [ - 'ErrorArray1', - 'ErrorArray2', - ], + 'ErrorArray1', + 'ErrorArray2', ], - [ - 'loginUsername', - '', - ]); + ], + [ + 'loginUsername', + '', + ] + ]; + $this->initialState->expects($this->exactly(13)) + ->method('provideInitialState') + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + if (!empty($expected)) { + $this->assertEquals($expected, func_get_args()); + } + }); $expectedResponse = new TemplateResponse( 'core', @@ -294,15 +303,25 @@ class LoginControllerTest extends TestCase { ->expects($this->once()) ->method('isLoggedIn') ->willReturn(false); - $this->initialState->expects($this->exactly(14)) - ->method('provideInitialState') - ->withConsecutive([], [], [], [ + $calls = [ + [], [], [], + [ 'loginAutocomplete', false - ], [ + ], + [ 'loginRedirectUrl', 'login/flow' - ]); + ], + ]; + $this->initialState->expects($this->exactly(14)) + ->method('provideInitialState') + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + if (!empty($expected)) { + $this->assertEquals($expected, func_get_args()); + } + }); $expectedResponse = new TemplateResponse( 'core', @@ -319,7 +338,7 @@ class LoginControllerTest extends TestCase { /** * @return array */ - public function passwordResetDataProvider(): array { + public static function passwordResetDataProvider(): array { return [ [ true, @@ -363,15 +382,26 @@ class LoginControllerTest extends TestCase { ->method('get') ->with('LdapUser') ->willReturn($user); - $this->initialState->expects($this->exactly(13)) - ->method('provideInitialState') - ->withConsecutive([], [], [ + $calls = [ + [], [], + [ 'loginUsername', 'LdapUser' - ], [], [], [], [ + ], + [], [], [], + [ 'loginCanResetPassword', $expectedResult - ]); + ], + ]; + $this->initialState->expects($this->exactly(13)) + ->method('provideInitialState') + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + if (!empty($expected)) { + $this->assertEquals($expected, func_get_args()); + } + }); $expectedResponse = new TemplateResponse( 'core', @@ -411,18 +441,30 @@ class LoginControllerTest extends TestCase { ->method('get') ->with('0') ->willReturn($user); - $this->initialState->expects($this->exactly(13)) - ->method('provideInitialState') - ->withConsecutive([], [], [], [ + $calls = [ + [], [], [], + [ 'loginAutocomplete', true - ], [], [ + ], + [], + [ 'loginResetPasswordLink', false - ], [ + ], + [ 'loginCanResetPassword', false - ]); + ], + ]; + $this->initialState->expects($this->exactly(13)) + ->method('provideInitialState') + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + if (!empty($expected)) { + $this->assertEquals($expected, func_get_args()); + } + }); $expectedResponse = new TemplateResponse( 'core', diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index 2a99c9f9d16..ffe3eb3920d 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -172,13 +172,18 @@ class LostControllerTest extends TestCase { ->method('linkToRouteAbsolute') ->with('core.lost.setPassword', ['userId' => 'ValidTokenUser', 'token' => 'MySecretToken']) ->willReturn('https://example.tld/index.php/lostpassword/set/sometoken/someuser'); + + $calls = [ + ['resetPasswordUser', 'ValidTokenUser'], + ['resetPasswordTarget', 'https://example.tld/index.php/lostpassword/set/sometoken/someuser'], + ]; $this->initialState ->expects($this->exactly(2)) ->method('provideInitialState') - ->withConsecutive( - ['resetPasswordUser', 'ValidTokenUser'], - ['resetPasswordTarget', 'https://example.tld/index.php/lostpassword/set/sometoken/someuser'] - ); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); $response = $this->lostController->resetform('MySecretToken', 'ValidTokenUser'); $expectedResponse = new TemplateResponse('core', @@ -448,12 +453,19 @@ class LostControllerTest extends TestCase { $this->userManager->method('get') ->with('ValidTokenUser') ->willReturn($this->existingUser); - $beforePasswordResetEvent = new BeforePasswordResetEvent($this->existingUser, 'NewPassword'); - $passwordResetEvent = new PasswordResetEvent($this->existingUser, 'NewPassword'); + + $calls = [ + [new BeforePasswordResetEvent($this->existingUser, 'NewPassword')], + [new PasswordResetEvent($this->existingUser, 'NewPassword')], + ]; $this->eventDispatcher ->expects($this->exactly(2)) ->method('dispatchTyped') - ->withConsecutive([$beforePasswordResetEvent], [$passwordResetEvent]); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); + $this->config->expects($this->once()) ->method('deleteUserValue') ->with('ValidTokenUser', 'core', 'lostpassword'); @@ -666,15 +678,15 @@ class LostControllerTest extends TestCase { /** * @return array */ - public function dataTwoUserswithSameEmailOneDisabled(): array { + public static function dataTwoUsersWithSameEmailOneDisabled(): array { return [ - ['user1' => true, 'user2' => false], - ['user1' => false, 'user2' => true] + ['userEnabled1' => true, 'userEnabled2' => false], + ['userEnabled1' => false, 'userEnabled2' => true] ]; } /** - * @dataProvider dataTwoUserswithSameEmailOneDisabled + * @dataProvider dataTwoUsersWithSameEmailOneDisabled * @param bool $userEnabled1 * @param bool $userEnabled2 */ diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php index 7498abb9a9e..97900191199 100644 --- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php +++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php @@ -68,7 +68,7 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->urlGenerator, $this->logger, ]) - ->setMethods(['getLogoutUrl']) + ->onlyMethods(['getLogoutUrl']) ->getMock(); $this->controller->expects($this->any()) ->method('getLogoutUrl') @@ -302,12 +302,16 @@ class TwoFactorChallengeControllerTest extends TestCase { ->method('verifyChallenge') ->with('myprovider', $user, 'token') ->will($this->throwException($exception)); + $calls = [ + ['two_factor_auth_error_message', '2FA failed'], + ['two_factor_auth_error', true], + ]; $this->session->expects($this->exactly(2)) ->method('set') - ->withConsecutive( - ['two_factor_auth_error_message', '2FA failed'], - ['two_factor_auth_error', true] - ); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('core.TwoFactorChallenge.showChallenge', [ diff --git a/tests/Core/Controller/WipeControllerTest.php b/tests/Core/Controller/WipeControllerTest.php index 2cd315db5bf..fa5f98988e7 100644 --- a/tests/Core/Controller/WipeControllerTest.php +++ b/tests/Core/Controller/WipeControllerTest.php @@ -33,7 +33,7 @@ class WipeControllerTest extends TestCase { $this->remoteWipe); } - public function dataTest() { + public static function dataTest(): array { return [ // valid token, could perform operation, valid result [ true, true, true], |