Fix priority merging logic and add unit test

This commit is contained in:
Robin McCorkell 2014-05-14 22:34:38 +01:00
parent eae45dca71
commit 0a8a319915
2 changed files with 55 additions and 0 deletions

View file

@ -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 {

View 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']);
}
}