diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-06-29 20:48:09 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-06-29 20:48:09 +0200 |
commit | 68f403cea205e41c02b9d072cf7398dca768c615 (patch) | |
tree | 44492bae9ad95d2d567636a6d64c4a41bcf31dde /apps/files_trashbin | |
parent | 68e41a3aae803e46be433b372deab16e9b155279 (diff) | |
download | nextcloud-server-68f403cea205e41c02b9d072cf7398dca768c615.tar.gz nextcloud-server-68f403cea205e41c02b9d072cf7398dca768c615.zip |
Fix and extend tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r-- | apps/files_trashbin/tests/Command/CleanUpTest.php | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/apps/files_trashbin/tests/Command/CleanUpTest.php b/apps/files_trashbin/tests/Command/CleanUpTest.php index 36b1ff10727..1ea3fc19c05 100644 --- a/apps/files_trashbin/tests/Command/CleanUpTest.php +++ b/apps/files_trashbin/tests/Command/CleanUpTest.php @@ -28,6 +28,9 @@ namespace OCA\Files_Trashbin\Tests\Command; use OCA\Files_Trashbin\Command\CleanUp; +use Symfony\Component\Console\Exception\InvalidOptionException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; use OC\User\Manager; use OCP\Files\IRootFolder; @@ -183,8 +186,7 @@ class CleanUpTest extends TestCase { ->setMethods(['removeDeletedFiles']) ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection]) ->getMock(); - $backend = $this->getMockBuilder(\OCP\UserInterface::class) - ->disableOriginalConstructor()->getMock(); + $backend = $this->createMock(\OCP\UserInterface::class); $backend->expects($this->once())->method('getUsers') ->with('', 500, 0) ->willReturn($backendUsers); @@ -193,17 +195,50 @@ class CleanUpTest extends TestCase { ->willReturnCallback(function ($user) use ($backendUsers) { $this->assertTrue(in_array($user, $backendUsers)); }); - $inputInterface = $this->getMockBuilder('\Symfony\Component\Console\Input\InputInterface') - ->disableOriginalConstructor()->getMock(); + $inputInterface = $this->createMock(InputInterface::class); $inputInterface->expects($this->once())->method('getArgument') ->with('user_id') ->willReturn($userIds); - $outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface') - ->disableOriginalConstructor()->getMock(); + $inputInterface->method('getOption') + ->with('all-users') + ->willReturn(true); + $outputInterface = $this->createMock(OutputInterface::class); $this->userManager->expects($this->once()) ->method('getBackends') ->willReturn([$backend]); $this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]); } + public function testExecuteNoUsersAndNoAllUsers() { + $inputInterface = $this->createMock(InputInterface::class); + $inputInterface->expects($this->once())->method('getArgument') + ->with('user_id') + ->willReturn([]); + $inputInterface->method('getOption') + ->with('all-users') + ->willReturn(false); + $outputInterface = $this->createMock(OutputInterface::class); + + $this->expectException(InvalidOptionException::class); + $this->expectExceptionMessage('Either specify a user_id or --all-users'); + + $this->invokePrivate($this->cleanup, 'execute', [$inputInterface, $outputInterface]); + } + + public function testExecuteUsersAndAllUsers() { + $inputInterface = $this->createMock(InputInterface::class); + $inputInterface->expects($this->once())->method('getArgument') + ->with('user_id') + ->willReturn(['user1', 'user2']); + $inputInterface->method('getOption') + ->with('all-users') + ->willReturn(true); + $outputInterface = $this->createMock(OutputInterface::class); + + $this->expectException(InvalidOptionException::class); + $this->expectExceptionMessage('Either specify a user_id or --all-users'); + + $this->invokePrivate($this->cleanup, 'execute', [$inputInterface, $outputInterface]); + } + } |