]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix priority merging logic and add unit test
authorRobin McCorkell <rmccorkell@karoshi.org.uk>
Wed, 14 May 2014 21:34:38 +0000 (22:34 +0100)
committerRobin McCorkell <rmccorkell@karoshi.org.uk>
Wed, 21 May 2014 21:18:22 +0000 (22:18 +0100)
apps/files_external/lib/config.php
apps/files_external/tests/mountconfig.php

index 788a136c387ac842e3ba9a5379d337e385991ed2..d47a2b4547b7c429f921e9adde673ada7dd3e3d3 100755 (executable)
@@ -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 {
index 33cbd10d9e9b0b24964f7aa75aa08535cfa86ac5..9b04e200e2b6933b52a0795ab911d5e5926dd4f5 100644 (file)
@@ -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']);
+       }
 }