Browse Source

Mock l10n in the setup

tags/v8.0.0RC2
Lukas Reschke 9 years ago
parent
commit
944dc127b8
1 changed files with 23 additions and 26 deletions
  1. 23
    26
      tests/core/lostpassword/controller/lostcontrollertest.php

+ 23
- 26
tests/core/lostpassword/controller/lostcontrollertest.php View File

->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') $this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->container['L10N']
->expects($this->any())
->method('t')
->will($this->returnCallback(function($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
$this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults') $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->container['UserManager'] = $this->getMockBuilder('\OCP\IUserManager') $this->container['UserManager'] = $this->getMockBuilder('\OCP\IUserManager')
array(true, $existingUser), array(true, $existingUser),
array(false, $nonExistingUser) array(false, $nonExistingUser)
))); )));
$this->container['L10N']
->expects($this->any())
->method('t')
->will(
$this->returnValueMap(
array(
array('Couldn\'t send reset email. Please make sure your username is correct.', array(),
'Couldn\'t send reset email. Please make sure your username is correct.'),

)
));


// With a non existing user // With a non existing user
$response = $this->lostController->email($nonExistingUser); $response = $this->lostController->email($nonExistingUser);
$expectedResponse = array('status' => 'error', 'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.');
$expectedResponse = [
'status' => 'error',
'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.'
];
$this->assertSame($expectedResponse, $response); $this->assertSame($expectedResponse, $response);


// With no mail address // With no mail address
->with($existingUser, 'settings', 'email') ->with($existingUser, 'settings', 'email')
->will($this->returnValue(null)); ->will($this->returnValue(null));
$response = $this->lostController->email($existingUser); $response = $this->lostController->email($existingUser);
$expectedResponse = array('status' => 'error', 'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.');
$expectedResponse = [
'status' => 'error',
'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.'
];
$this->assertSame($expectedResponse, $response); $this->assertSame($expectedResponse, $response);
} }


} }


public function testSetPasswordUnsuccessful() { public function testSetPasswordUnsuccessful() {
$this->container['L10N']
->expects($this->any())
->method('t')
->will(
$this->returnValueMap(
array(
array('Couldn\'t reset password because the token is invalid', array(),
'Couldn\'t reset password because the token is invalid'),
)
));
$this->container['Config'] $this->container['Config']
->expects($this->once()) ->expects($this->once())
->method('getUserValue') ->method('getUserValue')
// With an invalid token // With an invalid token
$userName = 'InvalidTokenUser'; $userName = 'InvalidTokenUser';
$response = $this->lostController->setPassword('wrongToken', $userName, 'NewPassword', true); $response = $this->lostController->setPassword('wrongToken', $userName, 'NewPassword', true);
$expectedResponse = array('status' => 'error', 'msg' => 'Couldn\'t reset password because the token is invalid');
$expectedResponse = [
'status' => 'error',
'msg' => 'Couldn\'t reset password because the token is invalid'
];
$this->assertSame($expectedResponse, $response); $this->assertSame($expectedResponse, $response);


// With a valid token and no proceed // With a valid token and no proceed
$response = $this->lostController->setPassword('TheOnlyAndOnlyOneTokenToResetThePassword!', $userName, 'NewPassword', false); $response = $this->lostController->setPassword('TheOnlyAndOnlyOneTokenToResetThePassword!', $userName, 'NewPassword', false);
$expectedResponse = array('status' => 'error', 'msg' => '', 'encryption' => true);
$expectedResponse = ['status' => 'error', 'msg' => '', 'encryption' => true];
$this->assertSame($expectedResponse, $response); $this->assertSame($expectedResponse, $response);
} }


->will($this->returnValue(null)); ->will($this->returnValue(null));


$response = $this->lostController->setPassword('', 'ValidTokenUser', 'NewPassword', true); $response = $this->lostController->setPassword('', 'ValidTokenUser', 'NewPassword', true);
$expectedResponse = ['status' => 'error', 'msg' => ''];
$expectedResponse = [
'status' => 'error',
'msg' => 'Couldn\'t reset password because the token is invalid'
];
$this->assertSame($expectedResponse, $response); $this->assertSame($expectedResponse, $response);
} }



Loading…
Cancel
Save