Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
7ad8bf31
Commit
7ad8bf31
authored
12 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
move filesystem test case
parent
286fd788
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/lib/files/filesystem.php
+110
-0
110 additions, 0 deletions
tests/lib/files/filesystem.php
tests/lib/files/view.php
+10
-12
10 additions, 12 deletions
tests/lib/files/view.php
with
120 additions
and
12 deletions
tests/lib/filesystem.php
→
tests/lib/
files/
filesystem.php
+
110
−
0
View file @
7ad8bf31
...
@@ -20,9 +20,9 @@
...
@@ -20,9 +20,9 @@
*
*
*/
*/
use
\OC\Files\Filesystem
as
Filesystem
;
namespace
Test\Files
;
class
Test_
Filesystem
extends
Unit
TestCase
{
class
Filesystem
extends
\PHPUnit_Framework_
TestCase
{
/**
/**
* @var array tmpDirs
* @var array tmpDirs
*/
*/
...
@@ -32,79 +32,79 @@ class Test_Filesystem extends UnitTestCase {
...
@@ -32,79 +32,79 @@ class Test_Filesystem extends UnitTestCase {
* @return array
* @return array
*/
*/
private
function
getStorageData
()
{
private
function
getStorageData
()
{
$dir
=
OC_Helper
::
tmpFolder
();
$dir
=
\
OC_Helper
::
tmpFolder
();
$this
->
tmpDirs
[]
=
$dir
;
$this
->
tmpDirs
[]
=
$dir
;
return
array
(
'datadir'
=>
$dir
);
return
array
(
'datadir'
=>
$dir
);
}
}
public
function
tearDown
()
{
public
function
tearDown
()
{
foreach
(
$this
->
tmpDirs
as
$dir
)
{
foreach
(
$this
->
tmpDirs
as
$dir
)
{
OC_Helper
::
rmdirr
(
$dir
);
\
OC_Helper
::
rmdirr
(
$dir
);
}
}
}
}
public
function
setUp
()
{
public
function
setUp
()
{
Filesystem
::
clearMounts
();
\OC\Files\
Filesystem
::
clearMounts
();
}
}
public
function
testMount
()
{
public
function
testMount
()
{
Filesystem
::
mount
(
'\OC\Files\Storage\Local'
,
self
::
getStorageData
(),
'/'
);
\OC\Files\
Filesystem
::
mount
(
'\OC\Files\Storage\Local'
,
self
::
getStorageData
(),
'/'
);
$this
->
assertEqual
(
'/'
,
Filesystem
::
getMountPoint
(
'/'
));
$this
->
assertEqual
s
(
'/'
,
\OC\Files\
Filesystem
::
getMountPoint
(
'/'
));
$this
->
assertEqual
(
'/'
,
Filesystem
::
getMountPoint
(
'/some/folder'
));
$this
->
assertEqual
s
(
'/'
,
\OC\Files\
Filesystem
::
getMountPoint
(
'/some/folder'
));
list
(
,
$internalPath
)
=
\OC\Files\Filesystem
::
resolvePath
(
'/'
);
list
(
,
$internalPath
)
=
\OC\Files\Filesystem
::
resolvePath
(
'/'
);
$this
->
assertEqual
(
''
,
$internalPath
);
$this
->
assertEqual
s
(
''
,
$internalPath
);
list
(
,
$internalPath
)
=
\OC\Files\Filesystem
::
resolvePath
(
'/some/folder'
);
list
(
,
$internalPath
)
=
\OC\Files\Filesystem
::
resolvePath
(
'/some/folder'
);
$this
->
assertEqual
(
'some/folder'
,
$internalPath
);
$this
->
assertEqual
s
(
'some/folder'
,
$internalPath
);
Filesystem
::
mount
(
'\OC\Files\Storage\Local'
,
self
::
getStorageData
(),
'/some'
);
\OC\Files\
Filesystem
::
mount
(
'\OC\Files\Storage\Local'
,
self
::
getStorageData
(),
'/some'
);
$this
->
assertEqual
(
'/'
,
Filesystem
::
getMountPoint
(
'/'
));
$this
->
assertEqual
s
(
'/'
,
\OC\Files\
Filesystem
::
getMountPoint
(
'/'
));
$this
->
assertEqual
(
'/some/'
,
Filesystem
::
getMountPoint
(
'/some/folder'
));
$this
->
assertEqual
s
(
'/some/'
,
\OC\Files\
Filesystem
::
getMountPoint
(
'/some/folder'
));
$this
->
assertEqual
(
'/some/'
,
Filesystem
::
getMountPoint
(
'/some/'
));
$this
->
assertEqual
s
(
'/some/'
,
\OC\Files\
Filesystem
::
getMountPoint
(
'/some/'
));
$this
->
assertEqual
(
'/'
,
Filesystem
::
getMountPoint
(
'/some'
));
$this
->
assertEqual
s
(
'/'
,
\OC\Files\
Filesystem
::
getMountPoint
(
'/some'
));
list
(
,
$internalPath
)
=
\OC\Files\Filesystem
::
resolvePath
(
'/some/folder'
);
list
(
,
$internalPath
)
=
\OC\Files\Filesystem
::
resolvePath
(
'/some/folder'
);
$this
->
assertEqual
(
'folder'
,
$internalPath
);
$this
->
assertEqual
s
(
'folder'
,
$internalPath
);
}
}
public
function
testNormalize
()
{
public
function
testNormalize
()
{
$this
->
assertEqual
(
'/path'
,
Filesystem
::
normalizePath
(
'/path/'
));
$this
->
assertEqual
s
(
'/path'
,
\OC\Files\
Filesystem
::
normalizePath
(
'/path/'
));
$this
->
assertEqual
(
'/path/'
,
Filesystem
::
normalizePath
(
'/path/'
,
false
));
$this
->
assertEqual
s
(
'/path/'
,
\OC\Files\
Filesystem
::
normalizePath
(
'/path/'
,
false
));
$this
->
assertEqual
(
'/path'
,
Filesystem
::
normalizePath
(
'path'
));
$this
->
assertEqual
s
(
'/path'
,
\OC\Files\
Filesystem
::
normalizePath
(
'path'
));
$this
->
assertEqual
(
'/path'
,
Filesystem
::
normalizePath
(
'\path'
));
$this
->
assertEqual
s
(
'/path'
,
\OC\Files\
Filesystem
::
normalizePath
(
'\path'
));
$this
->
assertEqual
(
'/foo/bar'
,
Filesystem
::
normalizePath
(
'/foo//bar/'
));
$this
->
assertEqual
s
(
'/foo/bar'
,
\OC\Files\
Filesystem
::
normalizePath
(
'/foo//bar/'
));
$this
->
assertEqual
(
'/foo/bar'
,
Filesystem
::
normalizePath
(
'/foo////bar'
));
$this
->
assertEqual
s
(
'/foo/bar'
,
\OC\Files\
Filesystem
::
normalizePath
(
'/foo////bar'
));
if
(
class_exists
(
'Normalizer'
))
{
if
(
class_exists
(
'Normalizer'
))
{
$this
->
assertEqual
(
"/foo/bar
\xC3\xBC
"
,
Filesystem
::
normalizePath
(
"/foo/baru
\xCC\x88
"
));
$this
->
assertEqual
s
(
"/foo/bar
\xC3\xBC
"
,
\OC\Files\
Filesystem
::
normalizePath
(
"/foo/baru
\xCC\x88
"
));
}
}
}
}
public
function
testHooks
()
{
public
function
testHooks
()
{
if
(
Filesystem
::
getView
()){
if
(
\OC\Files\
Filesystem
::
getView
()){
$user
=
OC_User
::
getUser
();
$user
=
\
OC_User
::
getUser
();
}
else
{
}
else
{
$user
=
uniqid
();
$user
=
uniqid
();
Filesystem
::
init
(
'/'
.
$user
.
'/files'
);
\OC\Files\
Filesystem
::
init
(
'/'
.
$user
.
'/files'
);
}
}
OC_Hook
::
clear
(
'OC_Filesystem'
);
\
OC_Hook
::
clear
(
'OC_Filesystem'
);
OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_write'
,
$this
,
'dummyHook'
);
\
OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_write'
,
$this
,
'dummyHook'
);
Filesystem
::
mount
(
'OC\Files\Storage\Temporary'
,
array
(),
'/'
);
\OC\Files\
Filesystem
::
mount
(
'OC\Files\Storage\Temporary'
,
array
(),
'/'
);
$rootView
=
new
\OC\Files\View
(
''
);
$rootView
=
new
\OC\Files\View
(
''
);
$rootView
->
mkdir
(
'/'
.
$user
);
$rootView
->
mkdir
(
'/'
.
$user
);
$rootView
->
mkdir
(
'/'
.
$user
.
'/files'
);
$rootView
->
mkdir
(
'/'
.
$user
.
'/files'
);
Filesystem
::
file_put_contents
(
'/foo'
,
'foo'
);
\OC\Files\
Filesystem
::
file_put_contents
(
'/foo'
,
'foo'
);
Filesystem
::
mkdir
(
'/bar'
);
\OC\Files\
Filesystem
::
mkdir
(
'/bar'
);
Filesystem
::
file_put_contents
(
'/bar//foo'
,
'foo'
);
\OC\Files\
Filesystem
::
file_put_contents
(
'/bar//foo'
,
'foo'
);
$tmpFile
=
OC_Helper
::
tmpFile
();
$tmpFile
=
\
OC_Helper
::
tmpFile
();
file_put_contents
(
$tmpFile
,
'foo'
);
file_put_contents
(
$tmpFile
,
'foo'
);
$fh
=
fopen
(
$tmpFile
,
'r'
);
$fh
=
fopen
(
$tmpFile
,
'r'
);
Filesystem
::
file_put_contents
(
'/bar//foo'
,
$fh
);
\OC\Files\
Filesystem
::
file_put_contents
(
'/bar//foo'
,
$fh
);
}
}
public
function
dummyHook
(
$arguments
)
{
public
function
dummyHook
(
$arguments
)
{
$path
=
$arguments
[
'path'
];
$path
=
$arguments
[
'path'
];
$this
->
assertEqual
(
$path
,
Filesystem
::
normalizePath
(
$path
));
//the path passed to the hook should already be normalized
$this
->
assertEqual
s
(
$path
,
\OC\Files\
Filesystem
::
normalizePath
(
$path
));
//the path passed to the hook should already be normalized
}
}
}
}
This diff is collapsed.
Click to expand it.
tests/lib/files/view.php
+
10
−
12
View file @
7ad8bf31
...
@@ -7,8 +7,6 @@
...
@@ -7,8 +7,6 @@
namespace
Test\Files
;
namespace
Test\Files
;
use
\OC\Files\Filesystem
as
Filesystem
;
class
View
extends
\PHPUnit_Framework_TestCase
{
class
View
extends
\PHPUnit_Framework_TestCase
{
/**
/**
* @var \OC\Files\Storage\Storage[] $storages;
* @var \OC\Files\Storage\Storage[] $storages;
...
@@ -16,7 +14,7 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -16,7 +14,7 @@ class View extends \PHPUnit_Framework_TestCase {
private
$storages
=
array
();
private
$storages
=
array
();
public
function
setUp
()
{
public
function
setUp
()
{
Filesystem
::
clearMounts
();
\OC\Files\
Filesystem
::
clearMounts
();
}
}
public
function
tearDown
()
{
public
function
tearDown
()
{
...
@@ -30,9 +28,9 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -30,9 +28,9 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1
=
$this
->
getTestStorage
();
$storage1
=
$this
->
getTestStorage
();
$storage2
=
$this
->
getTestStorage
();
$storage2
=
$this
->
getTestStorage
();
$storage3
=
$this
->
getTestStorage
();
$storage3
=
$this
->
getTestStorage
();
Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
\OC\Files\
Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
Filesystem
::
mount
(
$storage2
,
array
(),
'/substorage'
);
\OC\Files\
Filesystem
::
mount
(
$storage2
,
array
(),
'/substorage'
);
Filesystem
::
mount
(
$storage3
,
array
(),
'/folder/anotherstorage'
);
\OC\Files\
Filesystem
::
mount
(
$storage3
,
array
(),
'/folder/anotherstorage'
);
$textSize
=
strlen
(
"dummy file data
\n
"
);
$textSize
=
strlen
(
"dummy file data
\n
"
);
$imageSize
=
filesize
(
\OC
::
$SERVERROOT
.
'/core/img/logo.png'
);
$imageSize
=
filesize
(
\OC
::
$SERVERROOT
.
'/core/img/logo.png'
);
$storageSize
=
$textSize
*
2
+
$imageSize
;
$storageSize
=
$textSize
*
2
+
$imageSize
;
...
@@ -84,8 +82,8 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -84,8 +82,8 @@ class View extends \PHPUnit_Framework_TestCase {
public
function
testAutoScan
()
{
public
function
testAutoScan
()
{
$storage1
=
$this
->
getTestStorage
(
false
);
$storage1
=
$this
->
getTestStorage
(
false
);
$storage2
=
$this
->
getTestStorage
(
false
);
$storage2
=
$this
->
getTestStorage
(
false
);
Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
\OC\Files\
Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
Filesystem
::
mount
(
$storage2
,
array
(),
'/substorage'
);
\OC\Files\
Filesystem
::
mount
(
$storage2
,
array
(),
'/substorage'
);
$textSize
=
strlen
(
"dummy file data
\n
"
);
$textSize
=
strlen
(
"dummy file data
\n
"
);
$rootView
=
new
\OC\Files\View
(
''
);
$rootView
=
new
\OC\Files\View
(
''
);
...
@@ -103,9 +101,9 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -103,9 +101,9 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1
=
$this
->
getTestStorage
();
$storage1
=
$this
->
getTestStorage
();
$storage2
=
$this
->
getTestStorage
();
$storage2
=
$this
->
getTestStorage
();
$storage3
=
$this
->
getTestStorage
();
$storage3
=
$this
->
getTestStorage
();
Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
\OC\Files\
Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
Filesystem
::
mount
(
$storage2
,
array
(),
'/substorage'
);
\OC\Files\
Filesystem
::
mount
(
$storage2
,
array
(),
'/substorage'
);
Filesystem
::
mount
(
$storage3
,
array
(),
'/folder/anotherstorage'
);
\OC\Files\
Filesystem
::
mount
(
$storage3
,
array
(),
'/folder/anotherstorage'
);
$rootView
=
new
\OC\Files\View
(
''
);
$rootView
=
new
\OC\Files\View
(
''
);
...
@@ -113,7 +111,7 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -113,7 +111,7 @@ class View extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
6
,
count
(
$results
));
$this
->
assertEquals
(
6
,
count
(
$results
));
$paths
=
array
();
$paths
=
array
();
foreach
(
$results
as
$result
)
{
foreach
(
$results
as
$result
)
{
$this
->
assertEquals
(
$result
[
'path'
],
Filesystem
::
normalizePath
(
$result
[
'path'
]));
$this
->
assertEquals
(
$result
[
'path'
],
\OC\Files\
Filesystem
::
normalizePath
(
$result
[
'path'
]));
$paths
[]
=
$result
[
'path'
];
$paths
[]
=
$result
[
'path'
];
}
}
$this
->
assertContains
(
'/foo.txt'
,
$paths
);
$this
->
assertContains
(
'/foo.txt'
,
$paths
);
...
...
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