Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/registration.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-12-14 13:49:05 +0300
committerJoas Schilling <coding@schilljs.com>2020-12-14 13:49:05 +0300
commitfbb0b22155352eb81f0d8b001b3659d7b61351fa (patch)
tree0832d572c3a6de9ea1e098d62edbe06b9d7292c5 /tests
parent378f4e78fc72af3e8906bef18704e4434a06bfd0 (diff)
Fix and add new unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Controller/RegisterControllerTest.php1
-rw-r--r--tests/Unit/Service/RegistrationServiceTest.php38
2 files changed, 36 insertions, 3 deletions
diff --git a/tests/Unit/Controller/RegisterControllerTest.php b/tests/Unit/Controller/RegisterControllerTest.php
index 25ea874..5b9324c 100644
--- a/tests/Unit/Controller/RegisterControllerTest.php
+++ b/tests/Unit/Controller/RegisterControllerTest.php
@@ -457,6 +457,7 @@ class RegisterControllerTest extends TestCase {
'email_is_login' => false,
'username' => $username,
'message' => $message,
+ 'additional_hint' => null,
], $response->getParams());
}
diff --git a/tests/Unit/Service/RegistrationServiceTest.php b/tests/Unit/Service/RegistrationServiceTest.php
index 7994d07..7a819cc 100644
--- a/tests/Unit/Service/RegistrationServiceTest.php
+++ b/tests/Unit/Service/RegistrationServiceTest.php
@@ -67,6 +67,11 @@ class RegistrationServiceTest extends TestCase {
parent::setUp();
$this->mailService = $this->createMock(MailService::class);
$this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
$this->urlGenerator = $this->createMock(IURLGenerator::class);
#$this->userManager = $this->createMock(IUserManager::class);
$this->userManager = \OC::$server->getUserManager();
@@ -233,7 +238,8 @@ class RegistrationServiceTest extends TestCase {
$reg->setEmailConfirmed(true);
$this->expectException(RegistrationException::class);
- $resulting_user = $this->service->createAccount($reg, 'alice1', 'asdf');
+ $this->expectExceptionMessage('The username you have chosen already exists.');
+ $this->service->createAccount($reg, 'alice1', 'asdf');
}
/*
@@ -256,13 +262,39 @@ class RegistrationServiceTest extends TestCase {
$reg->setEmailConfirmed(true);
$this->expectException(RegistrationException::class);
- $resulting_user = $this->service->createAccount($reg);
+ $this->expectExceptionMessage('The username you have chosen already exists.');
+ $this->service->createAccount($reg);
+ }
+
+ /**
+ * @depends testDuplicateUsernameApi
+ */
+ public function testUsernameDoesntMatchPattern() {
+
+
+ $this->config->expects($this->atLeastOnce())
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['registration', 'username_policy_regex', '', '/^[a-z]\.[a-z]+$/'],
+ ]);
+
+ $reg = new Registration();
+ $reg->setEmail("pppp@example.com");
+ $reg->setUsername("alice23");
+ $reg->setDisplayname("Alice");
+ $reg->setPassword("asdf");
+ $reg->setEmailConfirmed(true);
+
+ $this->expectException(RegistrationException::class);
+ $this->expectExceptionMessage('Please provide a valid user name.');
+ $this->service->createAccount($reg);
}
public function settingsCallback1($app, $key, $default) {
$map = [
'registered_user_group' => 'none',
- 'admin_approval_required' => 'no'
+ 'admin_approval_required' => 'no',
+ 'username_policy_regex' => '',
];
return $map[$key];