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-07-29 19:06:05 +0300
committerJoas Schilling <coding@schilljs.com>2020-08-18 18:15:14 +0300
commit150e58880e2df492f458745d43edfe88bc8978db (patch)
tree57eb1b040f9e4ab716055e0b40ac2a4010ebce42 /tests
parent906b1f8db2b6254dd4f224eaf692b672251b8886 (diff)
Fix other tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Integration/Controller/RegisterControllerTest.php138
-rw-r--r--tests/Integration/Service/RegistrationServiceTest.php39
-rw-r--r--tests/Unit/Controller/ApiControllerTest.php4
-rw-r--r--tests/Unit/Controller/RegisterControllerTest.php7
4 files changed, 35 insertions, 153 deletions
diff --git a/tests/Integration/Controller/RegisterControllerTest.php b/tests/Integration/Controller/RegisterControllerTest.php
deleted file mode 100644
index b3bb45b..0000000
--- a/tests/Integration/Controller/RegisterControllerTest.php
+++ /dev/null
@@ -1,138 +0,0 @@
-<?php
-
-namespace OCA\Registration\Tests\Integration\Controller;
-
-use OCA\Registration\Controller\RegisterController;
-use OCA\Registration\Db\RegistrationMapper;
-use OCA\Registration\Service\MailService;
-use OCA\Registration\Service\RegistrationService;
-use OCP\IConfig;
-use OCP\IGroupManager;
-use OCP\IL10N;
-use OCP\ILogger;
-use OC\Authentication\Token\IProvider;
-use OCP\IRequest;
-use OCP\Security\ISecureRandom;
-use OCP\Security\ICrypto;
-use OCP\ISession;
-use OCP\IURLGenerator;
-use OCP\IUserManager;
-use OCP\IUserSession;
-
-use \OCP\AppFramework\Http\TemplateResponse;
-
-use ChristophWurst\Nextcloud\Testing\DatabaseTransaction;
-use ChristophWurst\Nextcloud\Testing\TestCase;
-
-/**
- * class RegistrationControllerTest
- *
- * @group DB
- */
-class RegisterControllerTest extends TestCase {
- use DatabaseTransaction;
-
- /** @var MailService */
- private $mailService;
- /** @var IL10N */
- private $l10n;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var RegistrationMapper */
- private $registrationMapper;
- /** @var IUserManager */
- private $userManager;
- /** @var IConfig */
- private $config;
- /** @var IGroupManager */
- private $groupManager;
- /** @var \OCP\Defaults */
- private $defaults;
- /** @var ISecureRandom */
- private $random;
- /** @var IUserSession */
- private $usersession;
- /** @var IRequest */
- private $request;
- /** @var ILogger */
- private $logger;
- /** @var ISession */
- private $session;
- /** @var IProvider */
- private $tokenProvider;
- /** @var ICrypto */
- private $crypto;
-
- public function setUp(): void {
- parent::setUp();
- $this->mailService = $this->createMock(MailService::class);
- $this->l10n = $this->createMock(IL10N::class);
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
- #$this->userManager = $this->createMock(IUserManager::class);
- $this->userManager = \OC::$server->getUserManager();
- $this->config = $this->createMock(IConfig::class);
- $this->groupManager = \OC::$server->getGroupManager();
- $this->random = \OC::$server->getSecureRandom();
- $this->usersession = $this->createMock(IUserSession::class);
- $this->request = $this->createMock(IRequest::class);
- $this->logger = $this->createMock(ILogger::class);
- $this->session = $this->createMock(ISession::class);
- $this->tokenProvider = $this->createMock(IProvider::class);
- $this->crypto = $this->createMock(ICrypto::class);
-
- $this->registrationMapper = new RegistrationMapper(
- \OC::$server->getDatabaseConnection(),
- $this->random
- );
-
- $this->registrationService = new RegistrationService(
- 'registration',
- $this->mailService,
- $this->l10n,
- $this->urlGenerator,
- $this->registrationMapper,
- $this->userManager,
- $this->config,
- $this->groupManager,
- $this->random,
- $this->usersession,
- $this->request,
- $this->logger,
- $this->session,
- $this->tokenProvider,
- $this->crypto
- );
-
- $this->controller = new RegisterController(
- 'registration',
- $this->request,
- $this->l10n,
- $this->urlGenerator,
- $this->config,
- $this->registrationService,
- $this->mailService
- );
- }
-
- public function testValidateEmailNormal() {
- $email = 'aaaa@example.com';
-
- $this->config->expects($this->atLeastOnce())
- ->method('getAppValue')
- ->with("registration", 'allowed_domains', '')
- ->willReturn('');
- $this->mailService->expects($this->once())
- ->method('sendTokenByMail');
-
- $this->assertEquals($this->registrationService->validateEmail($email), true);
-
- $ret = $this->controller->validateEmail($email);
-
- $expected = new TemplateResponse('registration', 'message', ['msg' =>
- $this->l10n->t('Verification email successfully sent.')
- ], 'guest');
-
-
- $this->assertEquals($expected, $ret, print_r($ret, true));
- }
-}
diff --git a/tests/Integration/Service/RegistrationServiceTest.php b/tests/Integration/Service/RegistrationServiceTest.php
index 0ab0aaa..4130ffd 100644
--- a/tests/Integration/Service/RegistrationServiceTest.php
+++ b/tests/Integration/Service/RegistrationServiceTest.php
@@ -61,6 +61,9 @@ class RegistrationServiceTest extends TestCase {
/** @var ICrypto */
private $crypto;
+ /** @var RegistrationService */
+ private $service;
+
public function setUp(): void {
parent::setUp();
$this->mailService = $this->createMock(MailService::class);
@@ -107,13 +110,10 @@ class RegistrationServiceTest extends TestCase {
$this->config->expects($this->once())
->method('getAppValue')
- ->with("registration", 'allowed_domains', '')
+ ->with('registration', 'allowed_domains', '')
->willReturn('');
- $ret = $this->service->validateEmail($email);
-
- //$this->assertInstanceOf(Registration::class, $ret);
- $this->assertTrue($ret);
+ $this->service->validateEmail($email);
}
public function testValidateNewEmailWithinAllowedDomain() {
@@ -121,18 +121,23 @@ class RegistrationServiceTest extends TestCase {
$this->config->expects($this->atLeastOnce())
->method('getAppValue')
- ->with("registration", 'allowed_domains', '')
+ ->with('registration', 'allowed_domains', '')
->willReturn('example.com');
- $ret = $this->service->validateEmail($email);
- $this->assertTrue($ret, print_r($ret, true));
+ $this->service->validateEmail($email);
}
+
/**
* @depends testValidateNewEmailWithinAllowedDomain
*/
public function testValidateNewEmailNotWithinAllowedDomain() {
$email2 = 'bbbb@gmail.com';
+ $this->config->expects($this->atLeastOnce())
+ ->method('getAppValue')
+ ->with('registration', 'allowed_domains', '')
+ ->willReturn('example.com');
+
$this->expectException(RegistrationException::class);
$this->service->validateEmail($email2);
}
@@ -143,18 +148,24 @@ class RegistrationServiceTest extends TestCase {
$this->config->expects($this->atLeastOnce())
->method('getAppValue')
- ->with("registration", 'allowed_domains', '')
+ ->with('registration', 'allowed_domains', '')
->willReturn('example.com;gmail.com');
- $this->assertTrue($this->service->validateEmail($email));
- $this->assertTrue($this->service->validateEmail($email2));
+ $this->service->validateEmail($email);
+ $this->service->validateEmail($email2);
}
+
/**
* @depends testValidateNewEmailWithinMultipleAllowedDomain
*/
public function testValidateNewEmailNotWithinMultipleAllowedDomain() {
$email2 = 'cccc@yahoo.com';
+ $this->config->expects($this->atLeastOnce())
+ ->method('getAppValue')
+ ->with('registration', 'allowed_domains', '')
+ ->willReturn('example.com;gmail.com');
+
$this->expectException(RegistrationException::class);
$this->service->validateEmail($email2);
}
@@ -180,10 +191,8 @@ class RegistrationServiceTest extends TestCase {
$email = 'aaaa@example.com';
$this->service->createRegistration($email, 'alice');
- $ret = $this->service->validateEmail($email);
-
- $this->assertInstanceOf(Registration::class, $ret);
- $this->assertEquals($email, $ret->getEmail());
+ $this->expectException(RegistrationException::class);
+ $this->service->validateEmail($email);
}
public function testCreateAccountWebForm() {
diff --git a/tests/Unit/Controller/ApiControllerTest.php b/tests/Unit/Controller/ApiControllerTest.php
index 2701f42..e37d46a 100644
--- a/tests/Unit/Controller/ApiControllerTest.php
+++ b/tests/Unit/Controller/ApiControllerTest.php
@@ -157,7 +157,11 @@ class ApiControllerTest extends TestCase {
$registration = new Registration();
$registration->setEmailConfirmed(true);
$registration->setClientSecret('mysecret');
+ $registration->setUsername('user');
+ $registration->setPassword('password');
$user = $this->createMock(IUser::class);
+ $user->method('getUID')
+ ->willReturn('user');
$this->registrationService
->method('getRegistrationForSecret')
->with('mysecret')
diff --git a/tests/Unit/Controller/RegisterControllerTest.php b/tests/Unit/Controller/RegisterControllerTest.php
index f9721f2..896f209 100644
--- a/tests/Unit/Controller/RegisterControllerTest.php
+++ b/tests/Unit/Controller/RegisterControllerTest.php
@@ -35,6 +35,7 @@ use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\RedirectToDefaultAppResponse;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -50,6 +51,8 @@ class RegisterControllerTest extends TestCase {
private $l10n;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
+ /** @var IConfig|MockObject */
+ private $config;
/** @var RegistrationService|MockObject */
private $registrationService;
/** @var LoginFlowService|MockObject */
@@ -62,6 +65,7 @@ class RegisterControllerTest extends TestCase {
$this->request = $this->createMock(IRequest::class);
$this->l10n = $this->createMock(IL10N::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->config = $this->createMock(IConfig::class);
$this->registrationService = $this->createMock(RegistrationService::class);
$this->loginFlowService = $this->createMock(LoginFlowService::class);
$this->mailService = $this->createMock(MailService::class);
@@ -84,6 +88,7 @@ class RegisterControllerTest extends TestCase {
$this->request,
$this->l10n,
$this->urlGenerator,
+ $this->config,
$this->registrationService,
$this->loginFlowService,
$this->mailService
@@ -97,6 +102,7 @@ class RegisterControllerTest extends TestCase {
$this->request,
$this->l10n,
$this->urlGenerator,
+ $this->config,
$this->registrationService,
$this->loginFlowService,
$this->mailService,
@@ -446,6 +452,7 @@ class RegisterControllerTest extends TestCase {
self::assertSame([
'email' => $email,
+ 'email_is_login' => false,
'username' => $username,
'message' => $message,
], $response->getParams());