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
6ad7e757
Unverified
Commit
6ad7e757
authored
5 years ago
by
Joas Schilling
Browse files
Options
Downloads
Patches
Plain Diff
Update the unit test to dataProviders
Signed-off-by:
Joas Schilling
<
coding@schilljs.com
>
parent
4a151c54
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/lib/Files/Type/DetectionTest.php
+77
-42
77 additions, 42 deletions
tests/lib/Files/Type/DetectionTest.php
with
77 additions
and
42 deletions
tests/lib/Files/Type/DetectionTest.php
+
77
−
42
View file @
6ad7e757
...
@@ -39,61 +39,96 @@ class DetectionTest extends \Test\TestCase {
...
@@ -39,61 +39,96 @@ class DetectionTest extends \Test\TestCase {
);
);
}
}
public
function
testDetect
()
{
public
function
dataDetectPath
():
array
{
$dir
=
\OC
::
$SERVERROOT
.
'/tests/data'
;
return
[
[
'foo.txt'
,
'text/plain'
],
[
'foo.png'
,
'image/png'
],
[
'foo.bar.png'
,
'image/png'
],
[
'.hidden.png'
,
'image/png'
],
[
'.hidden.foo.png'
,
'image/png'
],
[
'.hidden/foo.png'
,
'image/png'
],
[
'.hidden/.hidden.png'
,
'image/png'
],
[
'test.jpg/foo.png'
,
'image/png'
],
[
'.png'
,
'application/octet-stream'
],
[
'..hidden'
,
'application/octet-stream'
],
[
'foo'
,
'application/octet-stream'
],
[
''
,
'application/octet-stream'
],
[
'foo.png.ocTransferId123456789.part'
,
'image/png'
],
[
'foo.png.v1234567890'
,
'image/png'
],
];
}
$result
=
$this
->
detection
->
detect
(
$dir
.
"/"
);
/**
$expected
=
'httpd/unix-directory'
;
* @dataProvider dataDetectPath
$this
->
assertEquals
(
$expected
,
$result
);
*
* @param string $path
* @param string $expected
*/
public
function
testDetectPath
(
string
$path
,
string
$expected
):
void
{
$this
->
assertEquals
(
$expected
,
$this
->
detection
->
detectPath
(
$path
));
}
$result
=
$this
->
detection
->
detect
(
$dir
.
"/data.tar.gz"
);
public
function
dataDetectContent
():
array
{
$expected
=
'application/x-gzip'
;
return
[
$this
->
assertEquals
(
$expected
,
$result
);
[
'/'
,
'httpd/unix-directory'
],
[
'/data.tar.gz'
,
'application/x-gzip'
],
[
'/data.zip'
,
'application/zip'
],
[
'/testimage.mp3'
,
'audio/mpeg'
],
[
'/testimage.png'
,
'image/png'
],
];
}
$result
=
$this
->
detection
->
detect
(
$dir
.
"/data.zip"
);
/**
$expected
=
'application/zip'
;
* @dataProvider dataDetectContent
$this
->
assertEquals
(
$expected
,
$result
);
*
* @param string $path
* @param string $expected
*/
public
function
testDetectContent
(
string
$path
,
string
$expected
):
void
{
$this
->
assertEquals
(
$expected
,
$this
->
detection
->
detectContent
(
\OC
::
$SERVERROOT
.
'/tests/data'
.
$path
));
}
$result
=
$this
->
detection
->
detect
(
$dir
.
"/testimagelarge.svg"
);
public
function
dataDetect
():
array
{
$expected
=
'image/svg+xml'
;
return
[
$this
->
assertEquals
(
$expected
,
$result
);
[
'/'
,
'httpd/unix-directory'
],
[
'/data.tar.gz'
,
'application/x-gzip'
],
[
'/data.zip'
,
'application/zip'
],
[
'/testimagelarge.svg'
,
'image/svg+xml'
],
[
'/testimage.png'
,
'image/png'
],
];
}
$result
=
$this
->
detection
->
detect
(
$dir
.
"/testimage.png"
);
/**
$expected
=
'image/png'
;
* @dataProvider dataDetect
$this
->
assertEquals
(
$expected
,
$result
);
*
* @param string $path
* @param string $expected
*/
public
function
testDetect
(
string
$path
,
string
$expected
):
void
{
$this
->
assertEquals
(
$expected
,
$this
->
detection
->
detect
(
\OC
::
$SERVERROOT
.
'/tests/data'
.
$path
));
}
}
public
function
test
G
et
S
ec
ureMimeType
()
{
public
function
test
D
etec
tString
():
void
{
$result
=
$this
->
detection
->
g
et
S
ec
ureMimeType
(
'image/svg+xml
'
);
$result
=
$this
->
detection
->
d
etec
tString
(
'/data/data.tar.gz
'
);
$expected
=
'text/plain'
;
$expected
=
'text/plain'
;
$this
->
assertEquals
(
$expected
,
$result
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
$this
->
detection
->
getSecureMimeType
(
'image/png'
);
$expected
=
'image/png'
;
$this
->
assertEquals
(
$expected
,
$result
);
}
}
public
function
testDetectPath
()
{
public
function
dataGetSecureMimeType
():
array
{
$this
->
assertEquals
(
'text/plain'
,
$this
->
detection
->
detectPath
(
'foo.txt'
));
return
[
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'foo.png'
));
[
'image/svg+xml'
,
'text/plain'
],
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'foo.bar.png'
));
[
'image/png'
,
'image/png'
],
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'.hidden.png'
));
];
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'.hidden.foo.png'
));
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'.hidden/foo.png'
));
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'.hidden/.hidden.png'
));
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'test.jpg/foo.png'
));
$this
->
assertEquals
(
'application/octet-stream'
,
$this
->
detection
->
detectPath
(
'.png'
));
$this
->
assertEquals
(
'application/octet-stream'
,
$this
->
detection
->
detectPath
(
'..hidden'
));
$this
->
assertEquals
(
'application/octet-stream'
,
$this
->
detection
->
detectPath
(
'foo'
));
$this
->
assertEquals
(
'application/octet-stream'
,
$this
->
detection
->
detectPath
(
''
));
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'foo.png.ocTransferId123456789.part'
));
$this
->
assertEquals
(
'image/png'
,
$this
->
detection
->
detectPath
(
'foo.png.v1234567890'
));
}
}
public
function
testDetectString
()
{
/**
$result
=
$this
->
detection
->
detectString
(
"/data/data.tar.gz"
);
* @dataProvider dataGetSecureMimeType
$expected
=
'text/plain'
;
*
$this
->
assertEquals
(
$expected
,
$result
);
* @param string $mimeType
* @param string $expected
*/
public
function
testGetSecureMimeType
(
string
$mimeType
,
string
$expected
):
void
{
$this
->
assertEquals
(
$expected
,
$this
->
detection
->
getSecureMimeType
(
$mimeType
));
}
}
public
function
testMimeTypeIcon
()
{
public
function
testMimeTypeIcon
()
{
...
...
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