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
eaedf5fcd9
commit
5a497841be
|
@ -166,31 +166,8 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function getDefaultAccountManagerUserData() {
|
||||||
* @dataProvider dataTestSetUserSettings
|
return [
|
||||||
*
|
|
||||||
* @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([
|
|
||||||
IAccountManager::PROPERTY_DISPLAYNAME =>
|
IAccountManager::PROPERTY_DISPLAYNAME =>
|
||||||
[
|
[
|
||||||
'value' => 'Display name',
|
'value' => 'Display name',
|
||||||
|
@ -231,7 +208,34 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'scope' => IAccountManager::VISIBILITY_PRIVATE,
|
'scope' => IAccountManager::VISIBILITY_PRIVATE,
|
||||||
'verified' => IAccountManager::NOT_VERIFIED,
|
'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');
|
$controller->expects($this->once())->method('saveUserSettings');
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue