nextcloud/tests/lib/files/storage/storagefactory.php

46 lines
1.5 KiB
PHP
Raw Normal View History

2015-03-05 19:10:32 +03:00
<?php
/**
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace Test\Files\Storage;
use OC\Files\Mount\MountPoint;
use OCP\Files\Mount\IMountPoint;
2015-03-05 19:31:35 +03:00
use OCP\Files\Storage as IStorage;
2015-03-05 19:10:32 +03:00
use Test\TestCase;
use OC\Files\Storage\Wrapper\Wrapper;
class DummyWrapper extends Wrapper {
}
class StorageFactory extends TestCase {
public function testSimpleWrapper() {
$instance = new \OC\Files\Storage\StorageFactory();
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance);
2015-03-05 19:31:35 +03:00
$instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
2015-03-05 19:10:32 +03:00
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $storage);
$this->assertEquals('/foo/', $mount->getMountPoint());
$this->assertEquals('/foo/', $mountPoint);
return new DummyWrapper(['storage' => $storage]);
});
$wrapped = $mount->getStorage();
$this->assertInstanceOf('\Test\Files\Storage\DummyWrapper', $wrapped);
}
public function testRemoveWrapper() {
$instance = new \OC\Files\Storage\StorageFactory();
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance);
2015-03-05 19:31:35 +03:00
$instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage) {
2015-03-05 19:10:32 +03:00
return new DummyWrapper(['storage' => $storage]);
});
$instance->removeStorageWrapper('dummy');
$wrapped = $mount->getStorage();
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $wrapped);
}
}