diff options
author | Robin McCorkell <rmccorkell@karoshi.org.uk> | 2014-05-14 20:32:19 +0100 |
---|---|---|
committer | Robin McCorkell <rmccorkell@karoshi.org.uk> | 2014-05-21 22:18:22 +0100 |
commit | eae45dca71a089aa72cc780ecee7a9d7dd9ab3a1 (patch) | |
tree | ea9dcf8e147658a26a5ce9bb5ddcde2e35fcb029 /apps/files_external/tests | |
parent | 2254678a0cb9eb292413f2dca0602d4515077ab5 (diff) | |
download | nextcloud-server-eae45dca71a089aa72cc780ecee7a9d7dd9ab3a1.tar.gz nextcloud-server-eae45dca71a089aa72cc780ecee7a9d7dd9ab3a1.zip |
Add unit tests
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r-- | apps/files_external/tests/mountconfig.php | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php index 14fe1d90b7a..33cbd10d9e9 100644 --- a/apps/files_external/tests/mountconfig.php +++ b/apps/files_external/tests/mountconfig.php @@ -41,16 +41,22 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase { const TEST_USER1 = 'user1'; const TEST_USER2 = 'user2'; const TEST_GROUP1 = 'group1'; + const TEST_GROUP1B = 'group1b'; const TEST_GROUP2 = 'group2'; + const TEST_GROUP2B = 'group2b'; public function setUp() { \OC_User::createUser(self::TEST_USER1, self::TEST_USER1); \OC_User::createUser(self::TEST_USER2, self::TEST_USER2); \OC_Group::createGroup(self::TEST_GROUP1); + \OC_Group::createGroup(self::TEST_GROUP1B); \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1); + \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1B); \OC_Group::createGroup(self::TEST_GROUP2); + \OC_Group::createGroup(self::TEST_GROUP2B); \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2); + \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2B); \OC_User::setUserId(self::TEST_USER1); $this->userHome = \OC_User::getHome(self::TEST_USER1); @@ -81,7 +87,9 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase { \OC_User::deleteUser(self::TEST_USER2); \OC_User::deleteUser(self::TEST_USER1); \OC_Group::deleteGroup(self::TEST_GROUP1); + \OC_Group::deleteGroup(self::TEST_GROUP1B); \OC_Group::deleteGroup(self::TEST_GROUP2); + \OC_Group::deleteGroup(self::TEST_GROUP2B); @unlink($this->dataDir . '/mount.json'); @@ -635,4 +643,113 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase { $this->assertEquals('ext', $config[1]['mountpoint']); $this->assertEquals($options2, $config[1]['options']); } + + public function priorityDataProvider() { + return array( + + // test 1 - group vs group + array( + array( + array( + 'isPersonal' => false, + 'mountType' => OC_Mount_Config::MOUNT_TYPE_GROUP, + 'applicable' => self::TEST_GROUP1, + 'priority' => 50 + ), + array( + 'isPersonal' => false, + 'mountType' => OC_Mount_Config::MOUNT_TYPE_GROUP, + 'applicable' => self::TEST_GROUP1B, + 'priority' => 60 + ) + ), + 1 + ), + // test 2 - user vs personal + array( + array( + array( + 'isPersonal' => false, + 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER, + 'applicable' => self::TEST_USER1, + 'priority' => 2000 + ), + array( + 'isPersonal' => true, + 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER, + 'applicable' => self::TEST_USER1, + 'priority' => null + ) + ), + 1 + ), + // test 3 - all vs group vs user + array( + array( + array( + 'isPersonal' => false, + 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER, + 'applicable' => 'all', + 'priority' => 70 + ), + array( + 'isPersonal' => false, + 'mountType' => OC_Mount_Config::MOUNT_TYPE_GROUP, + 'applicable' => self::TEST_GROUP1, + 'priority' => 60 + ), + array( + 'isPersonal' => false, + 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER, + 'applicable' => self::TEST_USER1, + 'priority' => 50 + ) + ), + 2 + ) + + ); + } + + /** + * Ensure priorities are being respected + * Test user is self::TEST_USER1 + * + * @dataProvider priorityDataProvider + * @param array[] $mounts array of associative array of mount parameters: + * bool $isPersonal + * string $mountType + * string $applicable + * int|null $priority null for personal + * @param int $expected index of expected visible mount + */ + public function testPriority($mounts, $expected) { + $mountConfig = array( + 'host' => 'somehost', + 'user' => 'someuser', + 'password' => 'somepassword', + 'root' => 'someroot' + ); + + // Add mount points + foreach($mounts as $i => $mount) { + $this->assertTrue( + OC_Mount_Config::addMountPoint( + '/ext', + '\OC\Files\Storage\SMB', + $mountConfig + array('id' => $i), + $mount['mountType'], + $mount['applicable'], + $mount['isPersonal'], + $mount['priority'] + ) + ); + } + + // Get mount points for user + $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1); + + $this->assertEquals(1, count($mountPoints)); + $this->assertEquals($expected, $mountPoints['/'.self::TEST_USER1.'/files/ext']['options']['id']); + } } |