From 0a8a3199158a7a52c071054df4b4d740c90db5ac Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 14 May 2014 22:34:38 +0100 Subject: [PATCH] Fix priority merging logic and add unit test --- apps/files_external/lib/config.php | 7 ++++ apps/files_external/tests/mountconfig.php | 48 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 788a136c387..d47a2b4547b 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -769,6 +769,13 @@ class OC_Mount_Config { $mountPath = key($mountPoint[$applicable]); if (isset($data[$mountType])) { if (isset($data[$mountType][$applicable])) { + // Merge priorities + if (isset($data[$mountType][$applicable][$mountPath]) + && isset($data[$mountType][$applicable][$mountPath]['priority']) + && !isset($mountPoint[$applicable][$mountPath]['priority'])) { + $mountPoint[$applicable][$mountPath]['priority'] + = $data[$mountType][$applicable][$mountPath]['priority']; + } $data[$mountType][$applicable] = array_merge($data[$mountType][$applicable], $mountPoint[$applicable]); } else { diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php index 33cbd10d9e9..9b04e200e2b 100644 --- a/apps/files_external/tests/mountconfig.php +++ b/apps/files_external/tests/mountconfig.php @@ -752,4 +752,52 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase { $this->assertEquals(1, count($mountPoints)); $this->assertEquals($expected, $mountPoints['/'.self::TEST_USER1.'/files/ext']['options']['id']); } + + /** + * Test for persistence of priority when changing mount options + */ + public function testPriorityPersistence() { + $class = '\OC\Files\Storage\SMB'; + $priority = 123; + $mountConfig = array( + 'host' => 'somehost', + 'user' => 'someuser', + 'password' => 'somepassword', + 'root' => 'someroot' + ); + + $this->assertTrue( + OC_Mount_Config::addMountPoint( + '/ext', + $class, + $mountConfig, + OC_Mount_Config::MOUNT_TYPE_USER, + self::TEST_USER1, + false, + $priority + ) + ); + + // Check for correct priority + $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1); + $this->assertEquals($priority, + $mountPoints['/'.self::TEST_USER1.'/files/ext']['priority']); + + // Simulate changed mount options (without priority set) + $this->assertTrue( + OC_Mount_Config::addMountPoint( + '/ext', + $class, + $mountConfig, + OC_Mount_Config::MOUNT_TYPE_USER, + self::TEST_USER1, + false + ) + ); + + // Check for correct priority + $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1); + $this->assertEquals($priority, + $mountPoints['/'.self::TEST_USER1.'/files/ext']['priority']); + } } -- 2.39.5