2015-04-18 20:43:20 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Olivier Paroz <owncloud@interfasys.ch>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2015-04-21 15:40:11 +03:00
|
|
|
namespace OCA\Files_Sharing\Tests;
|
2015-04-18 20:43:20 +03:00
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
class ReadOnlyCache extends TestCase {
|
2015-04-18 20:43:20 +03:00
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
/** @var \OC\Files\Storage\Storage */
|
2015-04-18 20:43:20 +03:00
|
|
|
protected $storage;
|
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
/** @var \OC\Files\Storage\StorageFactory */
|
2015-04-18 20:43:20 +03:00
|
|
|
protected $loader;
|
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
/** @var \OC\Files\Mount\MountPoint */
|
2015-04-18 20:43:20 +03:00
|
|
|
protected $readOnlyMount;
|
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
/** @var \OCA\Files_Sharing\ReadOnlyWrapper */
|
2015-04-18 20:43:20 +03:00
|
|
|
protected $readOnlyStorage;
|
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
/** @var \OC\Files\Cache\Cache */
|
2015-04-18 20:43:20 +03:00
|
|
|
protected $readOnlyCache;
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->view->mkdir('readonly');
|
|
|
|
$this->view->file_put_contents('readonly/foo.txt', 'foo');
|
|
|
|
$this->view->file_put_contents('readonly/bar.txt', 'bar');
|
|
|
|
|
|
|
|
list($this->storage) = $this->view->resolvePath('');
|
|
|
|
$this->loader = new \OC\Files\Storage\StorageFactory();
|
|
|
|
$this->readOnlyMount = new \OC\Files\Mount\MountPoint($this->storage,
|
|
|
|
'/readonly', [[]], $this->loader);
|
|
|
|
$this->readOnlyStorage = $this->loader->getInstance($this->readOnlyMount,
|
|
|
|
'\OCA\Files_Sharing\ReadOnlyWrapper', ['storage' => $this->storage]);
|
|
|
|
|
|
|
|
$this->readOnlyCache = $this->readOnlyStorage->getCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetup() {
|
|
|
|
$this->assertTrue($this->view->file_exists('/readonly/foo.txt'));
|
|
|
|
|
|
|
|
$perms = $this->readOnlyStorage->getPermissions('files/readonly/foo.txt');
|
|
|
|
$this->assertEquals(17, $perms);
|
|
|
|
|
|
|
|
$this->assertFalse($this->readOnlyStorage->unlink('files/readonly/foo.txt'));
|
|
|
|
$this->assertTrue($this->readOnlyStorage->file_exists('files/readonly/foo.txt'));
|
|
|
|
|
|
|
|
$this->assertInstanceOf('\OCA\Files_Sharing\ReadOnlyCache', $this->readOnlyCache);
|
|
|
|
}
|
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
public function testGetWhenFileExists() {
|
2015-04-18 20:43:20 +03:00
|
|
|
$result = $this->readOnlyCache->get('files/readonly/foo.txt');
|
|
|
|
$this->assertNotEmpty($result);
|
2015-04-21 15:40:11 +03:00
|
|
|
}
|
2015-04-18 20:43:20 +03:00
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
public function testGetWhenFileDoesNotExist() {
|
2015-04-18 20:43:20 +03:00
|
|
|
$result = $this->readOnlyCache->get('files/readonly/proof does not exist.md');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
public function testGetFolderContentsWhenFolderExists() {
|
2015-04-18 20:43:20 +03:00
|
|
|
$results = $this->readOnlyCache->getFolderContents('files/readonly');
|
|
|
|
$this->assertNotEmpty($results);
|
|
|
|
|
|
|
|
foreach ($results as $result) {
|
|
|
|
$this->assertNotEmpty($result);
|
|
|
|
}
|
2015-04-21 15:40:11 +03:00
|
|
|
}
|
2015-04-18 20:43:20 +03:00
|
|
|
|
2015-04-21 15:40:11 +03:00
|
|
|
public function testGetFolderContentsWhenFolderDoesNotExist() {
|
2015-04-18 20:43:20 +03:00
|
|
|
$results = $this->readOnlyCache->getFolderContents('files/iamaghost');
|
|
|
|
$this->assertEmpty($results);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|