mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
add unit test
This commit is contained in:
parent
8ec7e9fac7
commit
786ec82a61
2 changed files with 48 additions and 2 deletions
|
|
@ -57,8 +57,11 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
|||
*/
|
||||
public function getMountsForUser(IUser $user) {
|
||||
$loader = $this->loader;
|
||||
return array_reduce($this->providers, function ($mounts, IMountProvider $provider) use ($user, $loader) {
|
||||
return array_merge($mounts, $provider->getMountsForUser($user, $loader));
|
||||
$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
|
||||
return $provider->getMountsForUser($user, $loader);
|
||||
}, $this->providers);
|
||||
return array_reduce($mounts, function ($mounts, $providerMounts) {
|
||||
return array_merge($mounts, $providerMounts);
|
||||
}, array());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ namespace Test\Files\Utils;
|
|||
use OC\Files\Filesystem;
|
||||
use OC\Files\Mount\MountPoint;
|
||||
use OC\Files\Storage\Temporary;
|
||||
use OCP\Files\Storage\IStorageFactory;
|
||||
use OCP\IUser;
|
||||
|
||||
class TestScanner extends \OC\Files\Utils\Scanner {
|
||||
/**
|
||||
|
|
@ -39,14 +41,22 @@ class TestScanner extends \OC\Files\Utils\Scanner {
|
|||
}
|
||||
|
||||
class Scanner extends \Test\TestCase {
|
||||
/**
|
||||
* @var \OC_User_Dummy
|
||||
*/
|
||||
private $userBackend;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->userBackend = new \OC_User_Dummy();
|
||||
\OC::$server->getUserManager()->registerBackend($this->userBackend);
|
||||
$this->loginAsUser();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
$this->logout();
|
||||
\OC::$server->getUserManager()->removeBackend($this->userBackend);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
|
|
@ -94,6 +104,39 @@ class Scanner extends \Test\TestCase {
|
|||
$this->assertEquals($old, $new);
|
||||
}
|
||||
|
||||
public function testScanSubMount() {
|
||||
$uid = $this->getUniqueID();
|
||||
$this->userBackend->createUser($uid, 'test');
|
||||
|
||||
$mountProvider = $this->getMock('\OCP\Files\Config\IMountProvider');
|
||||
|
||||
$storage = new Temporary(array());
|
||||
$mount = new MountPoint($storage, '/' . $uid . '/files/foo');
|
||||
|
||||
$mountProvider->expects($this->any())
|
||||
->method('getMountsForUser')
|
||||
->will($this->returnCallback(function (IUser $user, IStorageFactory $storageFactory) use ($mount, $uid) {
|
||||
if ($user->getUID() === $uid) {
|
||||
return [$mount];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}));
|
||||
|
||||
\OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
|
||||
$cache = $storage->getCache();
|
||||
|
||||
$storage->mkdir('folder');
|
||||
$storage->file_put_contents('foo.txt', 'qwerty');
|
||||
$storage->file_put_contents('folder/bar.txt', 'qwerty');
|
||||
|
||||
$scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection());
|
||||
|
||||
$this->assertFalse($cache->inCache('folder/bar.txt'));
|
||||
$scanner->scan('/' . $uid . '/files/foo');
|
||||
$this->assertTrue($cache->inCache('folder/bar.txt'));
|
||||
}
|
||||
|
||||
public function testChangePropagator() {
|
||||
/**
|
||||
* @var \OC\Files\Cache\ChangePropagator $propagator
|
||||
|
|
|
|||
Loading…
Reference in a new issue