Fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
2d08501be7
commit
2747ad7fd2
|
|
@ -434,6 +434,9 @@ class RegisterControllerTest extends TestCase {
|
|||
$secret = '123456789';
|
||||
$token = 'abcdefghi';
|
||||
$email = 'nextcloud@example.tld';
|
||||
$fullname = 'Full name';
|
||||
$phone = '0123 / 456789';
|
||||
$password = '123456';
|
||||
|
||||
$registration = Registration::fromParams([
|
||||
'email' => 'nextcloud@example.tld',
|
||||
|
|
@ -443,11 +446,17 @@ class RegisterControllerTest extends TestCase {
|
|||
'validateSecretAndToken'
|
||||
]);
|
||||
|
||||
$this->config->method('getAppValue')
|
||||
->willReturnMap([
|
||||
['registration', 'show_fullname', 'no', 'yes'],
|
||||
['registration', 'show_phone', 'no', 'yes'],
|
||||
]);
|
||||
|
||||
$controller->expects($this->once())
|
||||
->method('validateSecretAndToken')
|
||||
->willReturn($registration);
|
||||
|
||||
$response = $controller->showUserForm($secret, $token, $username, $message);
|
||||
$response = $controller->showUserForm($secret, $token, $username, $fullname, $phone, $password, $message);
|
||||
|
||||
self::assertSame(TemplateResponse::RENDER_AS_GUEST, $response->getRenderAs());
|
||||
self::assertSame('form/user', $response->getTemplateName());
|
||||
|
|
@ -455,8 +464,13 @@ class RegisterControllerTest extends TestCase {
|
|||
self::assertSame([
|
||||
'email' => $email,
|
||||
'email_is_login' => false,
|
||||
'username' => $username,
|
||||
'loginname' => $username,
|
||||
'fullname' => $fullname,
|
||||
'show_fullname' => true,
|
||||
'phone' => $phone,
|
||||
'show_phone' => true,
|
||||
'message' => $message,
|
||||
'password' => $password,
|
||||
'additional_hint' => null,
|
||||
], $response->getParams());
|
||||
}
|
||||
|
|
@ -500,7 +514,7 @@ class RegisterControllerTest extends TestCase {
|
|||
->method('validateSecretAndTokenErrorPage')
|
||||
->willReturn($response);
|
||||
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, '', ''));
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, '', '', '', ''));
|
||||
}
|
||||
|
||||
public function testSubmitUserFormCreateAccountException(): void {
|
||||
|
|
@ -508,6 +522,8 @@ class RegisterControllerTest extends TestCase {
|
|||
$token = 'abcdefghi';
|
||||
$username = 'user';
|
||||
$password = 'password';
|
||||
$fullname = 'Full name';
|
||||
$phone = '0123 / 456789';
|
||||
|
||||
$registration = Registration::fromParams([
|
||||
'email' => 'nextcloud@example.tld',
|
||||
|
|
@ -529,10 +545,10 @@ class RegisterControllerTest extends TestCase {
|
|||
|
||||
$this->registrationService->expects($this->once())
|
||||
->method('createAccount')
|
||||
->with($registration, $username, $password)
|
||||
->with($registration, $username, $fullname, $phone, $password)
|
||||
->willThrowException(new RegistrationException('Invalid account data'));
|
||||
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, $username, $password));
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, $username, $fullname, $phone, $password));
|
||||
}
|
||||
|
||||
public function testSubmitUserFormRequiresAdminApproval(): void {
|
||||
|
|
@ -540,6 +556,8 @@ class RegisterControllerTest extends TestCase {
|
|||
$token = 'abcdefghi';
|
||||
$username = 'user';
|
||||
$password = 'password';
|
||||
$fullname = 'Full name';
|
||||
$phone = '0123 / 456789';
|
||||
|
||||
$registration = Registration::fromParams([
|
||||
'email' => 'nextcloud@example.tld',
|
||||
|
|
@ -560,14 +578,14 @@ class RegisterControllerTest extends TestCase {
|
|||
|
||||
$this->registrationService->expects($this->once())
|
||||
->method('createAccount')
|
||||
->with($registration, $username, $password)
|
||||
->with($registration, $username, $fullname, $phone, $password)
|
||||
->willReturn($user);
|
||||
|
||||
$this->registrationService->expects($this->once())
|
||||
->method('deleteRegistration')
|
||||
->with($registration);
|
||||
|
||||
$response = $controller->submitUserForm($secret, $token, $username, $password);
|
||||
$response = $controller->submitUserForm($secret, $token, $username, $fullname, $phone, $password);
|
||||
|
||||
self::assertInstanceOf(StandaloneTemplateResponse::class, $response);
|
||||
self::assertSame(TemplateResponse::RENDER_AS_GUEST, $response->getRenderAs());
|
||||
|
|
@ -579,6 +597,8 @@ class RegisterControllerTest extends TestCase {
|
|||
$token = 'abcdefghi';
|
||||
$username = 'user';
|
||||
$password = 'password';
|
||||
$fullname = 'Full name';
|
||||
$phone = '0123 / 456789';
|
||||
|
||||
$registration = Registration::fromParams([
|
||||
'email' => 'nextcloud@example.tld',
|
||||
|
|
@ -601,7 +621,7 @@ class RegisterControllerTest extends TestCase {
|
|||
|
||||
$this->registrationService->expects($this->once())
|
||||
->method('createAccount')
|
||||
->with($registration, $username, $password)
|
||||
->with($registration, $username, $fullname, $phone, $password)
|
||||
->willReturn($user);
|
||||
|
||||
$this->registrationService->expects($this->once())
|
||||
|
|
@ -612,7 +632,7 @@ class RegisterControllerTest extends TestCase {
|
|||
->method('loginUser')
|
||||
->with($username, $username, $password);
|
||||
|
||||
$response = $controller->submitUserForm($secret, $token, $username, $password);
|
||||
$response = $controller->submitUserForm($secret, $token, $username, $fullname, $phone, $password);
|
||||
|
||||
self::assertInstanceOf(RedirectToDefaultAppResponse::class, $response);
|
||||
}
|
||||
|
|
@ -622,6 +642,8 @@ class RegisterControllerTest extends TestCase {
|
|||
$token = 'abcdefghi';
|
||||
$username = 'user';
|
||||
$password = 'password';
|
||||
$fullname = 'Full name';
|
||||
$phone = '0123 / 456789';
|
||||
|
||||
$registration = Registration::fromParams([
|
||||
'email' => 'nextcloud@example.tld',
|
||||
|
|
@ -644,7 +666,7 @@ class RegisterControllerTest extends TestCase {
|
|||
|
||||
$this->registrationService->expects($this->once())
|
||||
->method('createAccount')
|
||||
->with($registration, $username, $password)
|
||||
->with($registration, $username, $fullname, $phone, $password)
|
||||
->willReturn($user);
|
||||
|
||||
$this->registrationService->expects($this->once())
|
||||
|
|
@ -664,7 +686,7 @@ class RegisterControllerTest extends TestCase {
|
|||
->with($user)
|
||||
->willReturn($response);
|
||||
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, $username, $password));
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, $username, $fullname, $phone, $password));
|
||||
}
|
||||
|
||||
public function testSubmitUserFormSuccessfulLoginFlow1(): void {
|
||||
|
|
@ -672,6 +694,8 @@ class RegisterControllerTest extends TestCase {
|
|||
$token = 'abcdefghi';
|
||||
$username = 'user';
|
||||
$password = 'password';
|
||||
$fullname = 'Full name';
|
||||
$phone = '0123 / 456789';
|
||||
|
||||
$registration = Registration::fromParams([
|
||||
'email' => 'nextcloud@example.tld',
|
||||
|
|
@ -694,7 +718,7 @@ class RegisterControllerTest extends TestCase {
|
|||
|
||||
$this->registrationService->expects($this->once())
|
||||
->method('createAccount')
|
||||
->with($registration, $username, $password)
|
||||
->with($registration, $username, $fullname, $phone, $password)
|
||||
->willReturn($user);
|
||||
|
||||
$this->registrationService->expects($this->once())
|
||||
|
|
@ -715,6 +739,6 @@ class RegisterControllerTest extends TestCase {
|
|||
$this->loginFlowService->method('tryLoginFlowV1')
|
||||
->willReturn($response);
|
||||
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, $username, $password));
|
||||
self::assertSame($response, $controller->submitUserForm($secret, $token, $username, $fullname, $phone, $password));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use OCA\Registration\Db\RegistrationMapper;
|
|||
use OCA\Registration\Service\MailService;
|
||||
use OCA\Registration\Service\RegistrationException;
|
||||
use OCA\Registration\Service\RegistrationService;
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
|
|
@ -42,6 +43,8 @@ class RegistrationServiceTest extends TestCase {
|
|||
private $registrationMapper;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IAccountManager */
|
||||
private $accountManager;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IGroupManager */
|
||||
|
|
@ -75,6 +78,7 @@ class RegistrationServiceTest extends TestCase {
|
|||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
#$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->userManager = \OC::$server->getUserManager();
|
||||
$this->accountManager = $this->createMock(IAccountManager::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->groupManager = \OC::$server->getGroupManager();
|
||||
$this->random = \OC::$server->getSecureRandom();
|
||||
|
|
@ -97,6 +101,7 @@ class RegistrationServiceTest extends TestCase {
|
|||
$this->urlGenerator,
|
||||
$this->registrationMapper,
|
||||
$this->userManager,
|
||||
$this->accountManager,
|
||||
$this->config,
|
||||
$this->groupManager,
|
||||
$this->random,
|
||||
|
|
@ -219,7 +224,7 @@ class RegistrationServiceTest extends TestCase {
|
|||
|
||||
|
||||
$form_input_username = 'alice1';
|
||||
$resulting_user = $this->service->createAccount($reg, $form_input_username, 'asdf');
|
||||
$resulting_user = $this->service->createAccount($reg, $form_input_username, 'Full name', '+49 800 / 1110111', 'asdf');
|
||||
|
||||
$this->assertInstanceOf(IUser::class, $resulting_user);
|
||||
$this->assertEquals($form_input_username, $resulting_user->getUID());
|
||||
|
|
@ -238,8 +243,8 @@ class RegistrationServiceTest extends TestCase {
|
|||
$reg->setEmailConfirmed(true);
|
||||
|
||||
$this->expectException(RegistrationException::class);
|
||||
$this->expectExceptionMessage('The username you have chosen already exists.');
|
||||
$this->service->createAccount($reg, 'alice1', 'asdf');
|
||||
$this->expectExceptionMessage('The login name you have chosen already exists.');
|
||||
$this->service->createAccount($reg, 'alice1', 'Full name', '+49 800 / 1110111', 'asdf');
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -258,12 +263,16 @@ class RegistrationServiceTest extends TestCase {
|
|||
$reg->setEmail("pppp@example.com");
|
||||
$reg->setUsername("alice1");
|
||||
$reg->setDisplayname("Alice");
|
||||
$reg->setPassword("asdf");
|
||||
$reg->setPassword("crypto(asdf)");
|
||||
$reg->setEmailConfirmed(true);
|
||||
|
||||
$this->crypto->method('decrypt')
|
||||
->with('crypto(asdf)')
|
||||
->willReturn('asdf');
|
||||
|
||||
$this->expectException(RegistrationException::class);
|
||||
$this->expectExceptionMessage('The username you have chosen already exists.');
|
||||
$this->service->createAccount($reg);
|
||||
$this->expectExceptionMessage('The login name you have chosen already exists.');
|
||||
$this->service->createAccount($reg, null, 'Full name', '+49 800 / 1110111');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -280,12 +289,16 @@ class RegistrationServiceTest extends TestCase {
|
|||
$reg->setEmail("pppp@example.com");
|
||||
$reg->setUsername("alice23");
|
||||
$reg->setDisplayname("Alice");
|
||||
$reg->setPassword("asdf");
|
||||
$reg->setPassword("crypto(asdf)");
|
||||
$reg->setEmailConfirmed(true);
|
||||
|
||||
$this->crypto->method('decrypt')
|
||||
->with('crypto(asdf)')
|
||||
->willReturn('asdf');
|
||||
|
||||
$this->expectException(RegistrationException::class);
|
||||
$this->expectExceptionMessage('Please provide a valid user name.');
|
||||
$this->service->createAccount($reg);
|
||||
$this->expectExceptionMessage('Please provide a valid login name.');
|
||||
$this->service->createAccount($reg, null, 'Full name', '+49 800 / 1110111');
|
||||
}
|
||||
|
||||
public function settingsCallback1($app, $key, $default) {
|
||||
|
|
@ -293,6 +306,10 @@ class RegistrationServiceTest extends TestCase {
|
|||
'registered_user_group' => 'none',
|
||||
'admin_approval_required' => 'no',
|
||||
'username_policy_regex' => '',
|
||||
'show_fullname' => 'yes',
|
||||
'enforce_fullname' => 'no',
|
||||
'show_phone' => 'yes',
|
||||
'enforce_phone' => 'no',
|
||||
];
|
||||
|
||||
return $map[$key];
|
||||
|
|
|
|||
Loading…
Reference in New Issue