diff options
author | Robin Appelman <robin@icewind.nl> | 2019-02-22 17:55:13 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2019-02-22 17:55:13 +0300 |
commit | c47a76b12b62eab53139f3486ffbd85f64b8f3fa (patch) | |
tree | 8c791f48f0a1b9adcbfde8116662a8506f1ee2e0 | |
parent | fbd36c63e9ef9505e6f763d20adbdf0c042bf87c (diff) |
cache wrapper testsacl
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | tests/ACL/ACLCacheWrapperTest.php | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/ACL/ACLCacheWrapperTest.php b/tests/ACL/ACLCacheWrapperTest.php new file mode 100644 index 00000000..b2890378 --- /dev/null +++ b/tests/ACL/ACLCacheWrapperTest.php @@ -0,0 +1,90 @@ +<?php declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\groupfolders\tests\ACL; + + +use OC\Files\Cache\CacheEntry; +use OCA\GroupFolders\ACL\ACLCacheWrapper; +use OCA\GroupFolders\ACL\ACLManager; +use OCP\Constants; +use OCP\Files\Cache\ICache; +use Test\TestCase; + +class ACLCacheWrapperTest extends TestCase { + /** @var ACLManager|\PHPUnit_Framework_MockObject_MockObject */ + private $aclManager; + /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */ + private $source; + /** @var ACLCacheWrapper */ + private $cache; + private $aclPermissions = []; + + protected function setUp() { + parent::setUp(); + + $this->aclManager = $this->createMock(ACLManager::class); + $this->aclManager->method('getACLPermissionsForPath') + ->willReturnCallback(function (string $path) { + return isset($this->aclPermissions[$path]) ? $this->aclPermissions[$path] : Constants::PERMISSION_ALL; + }); + $this->source = $this->createMock(ICache::class); + $this->cache = new ACLCacheWrapper($this->source, $this->aclManager); + } + + public function testHideNonRead() { + $this->source->method('getFolderContentsById') + ->willReturn([ + new CacheEntry([ + 'path' => 'foo/f1', + 'permissions' => Constants::PERMISSION_ALL + ]), + new CacheEntry([ + 'path' => 'foo/f2', + 'permissions' => Constants::PERMISSION_ALL + ]), + new CacheEntry([ + 'path' => 'foo/f3', + 'permissions' => Constants::PERMISSION_ALL + ]), + ]); + $this->aclPermissions['foo/f1'] = Constants::PERMISSION_ALL; + $this->aclPermissions['foo/f2'] = Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE; + $this->aclPermissions['foo/f3'] = Constants::PERMISSION_ALL - Constants::PERMISSION_READ; + + $result = $this->cache->getFolderContentsById(0); + + $expected = [ + new CacheEntry([ + 'path' => 'foo/f1', + 'permissions' => Constants::PERMISSION_ALL, + 'scan_permissions' => Constants::PERMISSION_ALL + ]), + new CacheEntry([ + 'path' => 'foo/f2', + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, + 'scan_permissions' => Constants::PERMISSION_ALL + ]) + ]; + + $this->assertEquals($expected, $result); + } +} |