Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
eae45dca
Commit
eae45dca
authored
11 years ago
by
Robin McCorkell
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests
parent
2254678a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_external/lib/config.php
+13
-8
13 additions, 8 deletions
apps/files_external/lib/config.php
apps/files_external/tests/mountconfig.php
+117
-0
117 additions, 0 deletions
apps/files_external/tests/mountconfig.php
with
130 additions
and
8 deletions
apps/files_external/lib/config.php
+
13
−
8
View file @
eae45dca
...
...
@@ -427,6 +427,7 @@ class OC_Mount_Config {
* @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
* @param string $applicable User or group to apply mount to
* @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page
* @param int|null $priority Mount point priority, null for default
* @return boolean
*/
public
static
function
addMountPoint
(
$mountPoint
,
...
...
@@ -434,7 +435,8 @@ class OC_Mount_Config {
$classOptions
,
$mountType
,
$applicable
,
$isPersonal
=
false
)
{
$isPersonal
=
false
,
$priority
=
null
)
{
$backends
=
self
::
getBackends
();
$mountPoint
=
OC\Files\Filesystem
::
normalizePath
(
$mountPoint
);
if
(
$mountPoint
===
''
||
$mountPoint
===
'/'
)
{
...
...
@@ -464,12 +466,19 @@ class OC_Mount_Config {
'options'
=>
self
::
encryptPasswords
(
$classOptions
))
)
);
if
(
!
$isPersonal
)
{
$mount
[
$applicable
][
$mountPoint
][
'priority'
]
=
$
backends
[
$class
][
'
priority
'
]
;
if
(
!
$isPersonal
&&
!
is_null
(
$priority
)
)
{
$mount
[
$applicable
][
$mountPoint
][
'priority'
]
=
$priority
;
}
$mountPoints
=
self
::
readData
(
$isPersonal
?
OCP\User
::
getUser
()
:
NULL
);
$mountPoints
=
self
::
mergeMountPoints
(
$mountPoints
,
$mount
,
$mountType
);
// Set default priority if none set
if
(
!
isset
(
$mountPoints
[
$mountType
][
$applicable
][
$mountPoint
][
'priority'
]))
{
$mountPoints
[
$mountType
][
$applicable
][
$mountPoint
][
'priority'
]
=
$backends
[
$class
][
'priority'
];
}
self
::
writeData
(
$isPersonal
?
OCP\User
::
getUser
()
:
NULL
,
$mountPoints
);
return
self
::
getBackendStatus
(
$class
,
$classOptions
,
$isPersonal
);
...
...
@@ -757,13 +766,9 @@ class OC_Mount_Config {
*/
private
static
function
mergeMountPoints
(
$data
,
$mountPoint
,
$mountType
)
{
$applicable
=
key
(
$mountPoint
);
$mountPath
=
key
(
$mountPoint
[
$applicable
]);
if
(
isset
(
$data
[
$mountType
]))
{
if
(
isset
(
$data
[
$mountType
][
$applicable
]))
{
if
(
isset
(
$mountPoints
[
$mountType
][
$applicable
][
$mountPoint
])
&&
isset
(
$mountPoints
[
$mountType
][
$applicable
][
$mountPoint
][
'priority'
]))
{
$mount
[
$applicable
][
$mountPoint
][
'priority'
]
=
$mountPoints
[
$mountType
][
$applicable
][
$mountPoint
][
'priority'
];
}
$data
[
$mountType
][
$applicable
]
=
array_merge
(
$data
[
$mountType
][
$applicable
],
$mountPoint
[
$applicable
]);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
apps/files_external/tests/mountconfig.php
+
117
−
0
View file @
eae45dca
...
...
@@ -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'
]);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment