diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2021-02-26 15:29:33 +0300 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2021-02-26 15:29:37 +0300 |
commit | 635c54633a0e7b6728d5f11e32c3c71f7bcfa301 (patch) | |
tree | 0fe67b2f78d8076ce6fc5572d8c63b93f3f9c57c /tests | |
parent | 649d9b1f384cb088db508a95eeae21dc949617e4 (diff) |
Check if user exists before creating account
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Command/CreateAccountTest.php | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/Unit/Command/CreateAccountTest.php b/tests/Unit/Command/CreateAccountTest.php index 317b2fa8a..a86fe7f0c 100644 --- a/tests/Unit/Command/CreateAccountTest.php +++ b/tests/Unit/Command/CreateAccountTest.php @@ -23,10 +23,14 @@ namespace OCA\Mail\Tests\Unit\Command; use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Command\CreateAccount; +use OCP\IUserManager; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; class CreateAccountTest extends TestCase { private $service; private $crypto; + private $userManager; private $command; private $args = [ 'user-id', @@ -51,8 +55,9 @@ class CreateAccountTest extends TestCase { ->disableOriginalConstructor() ->getMock(); $this->crypto = $this->getMockBuilder('\OCP\Security\ICrypto')->getMock(); + $this->userManager = $this->createMock(IUserManager::class); - $this->command = new CreateAccount($this->service, $this->crypto); + $this->command = new CreateAccount($this->service, $this->crypto, $this->userManager); } public function testName() { @@ -71,4 +76,40 @@ class CreateAccountTest extends TestCase { $this->assertTrue(in_array($actArg->getName(), $this->args)); } } + + public function testInvalidUserId() { + $userId = 'invalidUser'; + $data = [ + 'user-id' => $userId, + 'name' => '', + 'email' => '', + 'imap-host' => '', + 'imap-port' => 0, + 'imap-ssl-mode' => '', + 'imap-user' => '', + 'imap-password' => '', + 'smtp-host' => '', + 'smtp-port' => 0, + 'smtp-ssl-mode' => '', + 'smtp-user' => '', + 'smtp-password' => '', + ]; + + $input = $this->createMock(InputInterface::class); + $input->method('getArgument') + ->willReturnCallback(function ($arg) use ($data) { + return $data[$arg]; + }); + $output = $this->createMock(OutputInterface::class); + $output->expects($this->once()) + ->method('writeln') + ->with("<error>User $userId does not exist</error>"); + + $this->userManager->expects($this->once()) + ->method('userExists') + ->with($userId) + ->willReturn(false); + + $this->assertEquals(1, $this->command->run($input, $output)); + } } |