diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2017-09-14 13:59:09 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2017-09-15 11:32:45 +0200 |
commit | 6e69881512ad072508f13983ad9c145b48855ce7 (patch) | |
tree | 7f79d8f68dbc209d0aa458b4bad47fe34777df30 /apps/files_trashbin/tests | |
parent | 113fd47f3005d9f05a6dc3d42b73bbb7a6339d00 (diff) | |
download | nextcloud-server-6e69881512ad072508f13983ad9c145b48855ce7.tar.gz nextcloud-server-6e69881512ad072508f13983ad9c145b48855ce7.zip |
allow apps to control the trash bin
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/files_trashbin/tests')
-rw-r--r-- | apps/files_trashbin/tests/StorageTest.php | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 52d5f056148..2e3ddf2e6bf 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -31,7 +31,13 @@ namespace OCA\Files_Trashbin\Tests; use OC\Files\Storage\Temporary; use OC\Files\Filesystem; +use OCA\Files_Trashbin\Events\MoveToTrashEvent; +use OCA\Files_Trashbin\Storage; +use OCP\Files\Cache\ICache; +use OCP\Files\IRootFolder; +use OCP\Files\Node; use OCP\ILogger; +use Symfony\Component\EventDispatcher\EventDispatcher; /** * Class Storage @@ -522,19 +528,40 @@ class StorageTest extends \Test\TestCase { /** * @dataProvider dataTestShouldMoveToTrash */ - public function testShouldMoveToTrash($mountPoint, $path, $userExists, $expected) { + public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisablesTrash, $expected) { + $fileID = 1; + $cache = $this->getMock(ICache::class); + $cache->expects($this->any())->method('getId')->willReturn($fileID); $tmpStorage = $this->getMockBuilder('\OC\Files\Storage\Temporary') - ->disableOriginalConstructor()->getMock(); + ->disableOriginalConstructor()->getMock($cache); + $tmpStorage->expects($this->any())->method('getCache')->willReturn($cache); $userManager = $this->getMockBuilder('OCP\IUserManager') ->disableOriginalConstructor()->getMock(); $userManager->expects($this->any()) ->method('userExists')->willReturn($userExists); $logger = $this->getMockBuilder(ILogger::class)->getMock(); - $storage = new \OCA\Files_Trashbin\Storage( - ['mountPoint' => $mountPoint, 'storage' => $tmpStorage], - $userManager, - $logger - ); + $eventDispatcher = $this->getMockBuilder(EventDispatcher::class) + ->disableOriginalConstructor()->getMock(); + $rootFolder = $this->getMock(IRootFolder::class); + $node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(MoveToTrashEvent::class)->disableOriginalConstructor()->getMock(); + $event->expects($this->any())->method('shouldMoveToTrashBin')->willReturn(!$appDisablesTrash); + + $rootFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]); + + $storage = $this->getMockBuilder(Storage::class) + ->setConstructorArgs( + [ + ['mountPoint' => $mountPoint, 'storage' => $tmpStorage], + $userManager, + $logger, + $eventDispatcher, + $rootFolder + ] + )->setMethods(['createMoveToTrashEvent'])->getMock(); + + $storage->expects($this->any())->method('createMoveToTrashEvent')->with($node) + ->willReturn($event); $this->assertSame($expected, $this->invokePrivate($storage, 'shouldMoveToTrash', [$path]) @@ -544,10 +571,13 @@ class StorageTest extends \Test\TestCase { public function dataTestShouldMoveToTrash() { return [ - ['/schiesbn/', '/files/test.txt', true, true], - ['/schiesbn/', '/files/test.txt', false, false], - ['/schiesbn/', '/test.txt', true, false], - ['/schiesbn/', '/test.txt', false, false], + ['/schiesbn/', '/files/test.txt', true, false, true], + ['/schiesbn/', '/files/test.txt', false, false, false], + ['/schiesbn/', '/test.txt', true, false, false], + ['/schiesbn/', '/test.txt', false, false, false], + // other apps disables the trashbin + ['/schiesbn/', '/files/test.txt', true, true, false], + ['/schiesbn/', '/files/test.txt', false, true, false], ]; } |