diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-06-22 14:41:08 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-06-29 14:06:29 +0200 |
commit | 786ec82a619abfc330bb0ff0d8db3398cb1bba01 (patch) | |
tree | cdaf92335b8de8e19adc12ed67a1d9388e89f0e0 /tests | |
parent | 8ec7e9fac7d16d60da09689f6a92dbdfed89c53b (diff) | |
download | nextcloud-server-786ec82a619abfc330bb0ff0d8db3398cb1bba01.tar.gz nextcloud-server-786ec82a619abfc330bb0ff0d8db3398cb1bba01.zip |
add unit test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/utils/scanner.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index dfc683c1bcf..ca64b1db72e 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -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 |