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 eaedf5fcd9
commit 5a497841be
1 changed files with 46 additions and 42 deletions

View File

@ -166,31 +166,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',
@ -231,7 +208,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 {