Extract default test data to a helper getter

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2021-01-29 20:34:10 +01:00
parent 32fd379b66
commit 91e06bc08a
1 changed files with 46 additions and 42 deletions

View File

@ -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 {