Fix and extend tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
68e41a3aae
commit
68f403cea2
|
@ -28,6 +28,9 @@ namespace OCA\Files_Trashbin\Tests\Command;
|
||||||
|
|
||||||
|
|
||||||
use OCA\Files_Trashbin\Command\CleanUp;
|
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 Test\TestCase;
|
||||||
use OC\User\Manager;
|
use OC\User\Manager;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
@ -183,8 +186,7 @@ class CleanUpTest extends TestCase {
|
||||||
->setMethods(['removeDeletedFiles'])
|
->setMethods(['removeDeletedFiles'])
|
||||||
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection])
|
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection])
|
||||||
->getMock();
|
->getMock();
|
||||||
$backend = $this->getMockBuilder(\OCP\UserInterface::class)
|
$backend = $this->createMock(\OCP\UserInterface::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
$backend->expects($this->once())->method('getUsers')
|
$backend->expects($this->once())->method('getUsers')
|
||||||
->with('', 500, 0)
|
->with('', 500, 0)
|
||||||
->willReturn($backendUsers);
|
->willReturn($backendUsers);
|
||||||
|
@ -193,17 +195,50 @@ class CleanUpTest extends TestCase {
|
||||||
->willReturnCallback(function ($user) use ($backendUsers) {
|
->willReturnCallback(function ($user) use ($backendUsers) {
|
||||||
$this->assertTrue(in_array($user, $backendUsers));
|
$this->assertTrue(in_array($user, $backendUsers));
|
||||||
});
|
});
|
||||||
$inputInterface = $this->getMockBuilder('\Symfony\Component\Console\Input\InputInterface')
|
$inputInterface = $this->createMock(InputInterface::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
$inputInterface->expects($this->once())->method('getArgument')
|
$inputInterface->expects($this->once())->method('getArgument')
|
||||||
->with('user_id')
|
->with('user_id')
|
||||||
->willReturn($userIds);
|
->willReturn($userIds);
|
||||||
$outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')
|
$inputInterface->method('getOption')
|
||||||
->disableOriginalConstructor()->getMock();
|
->with('all-users')
|
||||||
|
->willReturn(true);
|
||||||
|
$outputInterface = $this->createMock(OutputInterface::class);
|
||||||
$this->userManager->expects($this->once())
|
$this->userManager->expects($this->once())
|
||||||
->method('getBackends')
|
->method('getBackends')
|
||||||
->willReturn([$backend]);
|
->willReturn([$backend]);
|
||||||
$this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
|
$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]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue