Update# add DB to RegistrationServiceTest

This commit is contained in:
Pellaeon Lin 2018-06-24 15:10:18 +08:00
parent 63837e7079
commit c5be32bd17
1 changed files with 30 additions and 3 deletions

View File

@ -23,7 +23,6 @@ use OCP\IUser;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
//use \Test\TestCase;
use ChristophWurst\Nextcloud\Testing\DatabaseTransaction;
use ChristophWurst\Nextcloud\Testing\TestCase;
@ -71,13 +70,12 @@ class RegistrationServiceTest extends TestCase {
$this->mailService = $this->createMock(MailService::class);
$this->l10n = $this->createMock(IL10N::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->registrationMapper = $this->createMock(RegistrationMapper::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 = $this->createMock(ISecureRandom::class);
$this->random = \OC::$server->getSecureRandom();
$this->usersession = $this->createMock(IUserSession::class);
$this->request = $this->createMock(IRequest::class);
$this->logger = $this->createMock(ILogger::class);
@ -85,6 +83,11 @@ class RegistrationServiceTest extends TestCase {
$this->tokenProvider = $this->createMock(IProvider::class);
$this->crypto = $this->createMock(ICrypto::class);
$this->registrationMapper = new RegistrationMapper(
\OC::$server->getDatabaseConnection(),
$this->random
);
$this->service = new RegistrationService(
'registration',
$this->mailService,
@ -105,6 +108,30 @@ class RegistrationServiceTest extends TestCase {
);
}
public function testValidateNewEmail() {
$email = 'aaaa@example.com';
$this->config->expects($this->at(0))
->method('getAppValue')
->with("registration", 'allowed_domains', '')
->willReturn('');
$ret = $this->service->validateEmail($email);
//$this->assertInstanceOf(Registration::class, $ret);
$this->assertTrue($ret);
}
public function testValidatePendingReg() {
$email = 'aaaa@example.com';
$this->service->createRegistration($email, 'alice');
$ret = $this->service->validateEmail($email);
$this->assertInstanceOf(Registration::class, $ret);
$this->assertEquals($email, $ret->getEmail());
}
public function testCreateAccountWebForm() {
$reg = new Registration();
$reg->setEmail("asd@example.com");