Extract default test data to a helper getter
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
32fd379b66
commit
91e06bc08a
|
@ -172,31 +172,8 @@ class UsersControllerTest extends \Test\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTestSetUserSettings
|
||||
*
|
||||
* @param string $email
|
||||
* @param bool $validEmail
|
||||
* @param $expectedStatus
|
||||
*/
|
||||
public function testSetUserSettings($email, $validEmail, $expectedStatus) {
|
||||
$controller = $this->getController(false, ['saveUserSettings']);
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$this->userSession->method('getUser')->willReturn($user);
|
||||
|
||||
if (!empty($email) && $validEmail) {
|
||||
$this->mailer->expects($this->once())->method('validateMailAddress')
|
||||
->willReturn($validEmail);
|
||||
}
|
||||
|
||||
$saveData = (!empty($email) && $validEmail) || empty($email);
|
||||
|
||||
if ($saveData) {
|
||||
$this->accountManager->expects($this->once())
|
||||
->method('getUser')
|
||||
->with($user)
|
||||
->willReturn([
|
||||
protected function getDefaultAccountManagerUserData() {
|
||||
return [
|
||||
IAccountManager::PROPERTY_DISPLAYNAME =>
|
||||
[
|
||||
'value' => 'Display name',
|
||||
|
@ -237,7 +214,34 @@ class UsersControllerTest extends \Test\TestCase {
|
|||
'scope' => IAccountManager::VISIBILITY_PRIVATE,
|
||||
'verified' => IAccountManager::NOT_VERIFIED,
|
||||
],
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTestSetUserSettings
|
||||
*
|
||||
* @param string $email
|
||||
* @param bool $validEmail
|
||||
* @param $expectedStatus
|
||||
*/
|
||||
public function testSetUserSettings($email, $validEmail, $expectedStatus) {
|
||||
$controller = $this->getController(false, ['saveUserSettings']);
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$this->userSession->method('getUser')->willReturn($user);
|
||||
|
||||
if (!empty($email) && $validEmail) {
|
||||
$this->mailer->expects($this->once())->method('validateMailAddress')
|
||||
->willReturn($validEmail);
|
||||
}
|
||||
|
||||
$saveData = (!empty($email) && $validEmail) || empty($email);
|
||||
|
||||
if ($saveData) {
|
||||
$this->accountManager->expects($this->once())
|
||||
->method('getUser')
|
||||
->with($user)
|
||||
->willReturn($this->getDefaultAccountManagerUserData());
|
||||
|
||||
$controller->expects($this->once())->method('saveUserSettings');
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue