[Pkg-owncloud-commits] [owncloud] 09/131: add unit test

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 15:58:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag v8.1.1
in repository owncloud.

commit 8a3f54c22592a941ca6a964e8bc8386a2cfed309
Author: Robin Appelman <icewind at owncloud.com>
Date:   Mon Jun 22 14:41:08 2015 +0200

    add unit test
---
 .../files/config/mountprovidercollection.php       |  7 +++-
 tests/lib/files/utils/scanner.php                  | 43 ++++++++++++++++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/lib/private/files/config/mountprovidercollection.php b/lib/private/files/config/mountprovidercollection.php
index a14a6ef..7db0aff 100644
--- a/lib/private/files/config/mountprovidercollection.php
+++ b/lib/private/files/config/mountprovidercollection.php
@@ -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());
 	}
 
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index dfc683c..ca64b1d 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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list