From 598e3ff4fa5e22a25c8beb41295139c6a3d1cfcf Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Sat, 30 Jun 2018 17:10:08 +0800 Subject: [PATCH] Add# first registerController test --- .../controller/RegisterControllerTest.php | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/integration/controller/RegisterControllerTest.php diff --git a/tests/integration/controller/RegisterControllerTest.php b/tests/integration/controller/RegisterControllerTest.php new file mode 100644 index 0000000..042fb95 --- /dev/null +++ b/tests/integration/controller/RegisterControllerTest.php @@ -0,0 +1,144 @@ +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->defaults = $this->createMock(Defaults::class); + $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->defaults, + $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->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->at(0)) + ->method('sendTokenByMail') + ->willReturn(true); + + $this->assertEquals($this->registrationService->validateEmail($email), true); + + $ret = $this->controller->validateEmail($email); + + $expected = new TemplateResponse('registration', 'message', array('msg' => + $this->l10n->t('Verification email successfully sent.') + ), 'guest'); + + + $this->assertEquals($expected, $ret, print_r($ret, true)); + } +}