-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mimetypedetector #15543
Mimetypedetector #15543
Conversation
CC: @DeepDiver1975 @Xenopathic |
|
||
public function testGetSecureMimeType() { | ||
$detection = new Detection(); | ||
$detection->registerTypeArray(include 'mimetypes.list.php'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mimetypes.list.php
is used for custom mimetypes, so probably shouldn't be used here in the tests. Unless you want to try and tackle #15384 in this PR as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you are right. I just made the old unit tests work again. I'll have a look later this week to make more proper unit tests.
@rullzer Still valid? Then please rebase ;) |
Rebased, moved all the mimetype related stuff to OC/Files/Type/Detection (OCP/Files/IMimetypeDetector). Test still work. Altough I might extend them. Lets see what jenkins has to say. |
@@ -496,9 +428,10 @@ static function getSecureMimeType($mimeType) { | |||
* | |||
* @param string $data | |||
* @return string | |||
* @deprecated Use \OC::$server->getMimeTypeDetector->detectString($data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getMimeTypeDetector()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks fixed
@DeepDiver1975 this should fix #17421 As you can see I deprecated a lot of functions in OC_Helper. Now I know that we can usually just remove private functions but this was used in a lot of places since there was no OCP alternative. What to do in that case? |
Review time! |
|
||
// Is it a dir? | ||
if ($mimetype === 'dir') { | ||
$this->mimetypeIcons[$mimetype] = \OC::$server->getURLGenerator()->imagePath('core', 'filetypes/folder.png'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use dependency injection for the URL generator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, much cleaner.
Would also allow unit tests next to the integration tests
@Xenopathic you are right. It looks cleaner now. |
Lets see if Jenkins is still happy |
Looking good. Could you squash some of those commits though? We have 8 commits here, most of them fixes or adjustments of earlier ones. |
@Xenopathic yeah will do. Just waiting for Jenkins to be finished. |
Ok rebased and squashed... let see |
rebased... lets see if docker does its thing now. |
👍 for the code, just need the whitespace and phpdoc fixes |
It seems unit testing the functions is not so trivial in the current setup (you can't set the vars to something you want easily since they read from a hard coded path). Let me think about how to solve that in a clean way. |
@rullzer How about making the Alternatively, pass the config directory path to the constructor? That's how |
@Xenopathic I was thinking about the latter one (so passing the config dir to the constructor). That way it is easily testable with a temp dir that is passed. And the full class can actually be properly unit tested. I'll fix that hopefully this evening. |
Unit tests are added. But depend on owncloud-archive/3rdparty#185. |
@rullzer Rebase needed |
@MorrisJobke will do once the 3rdparty is merged and bumbed on master. |
Makes sense 😃 |
public function testMimeTypeIconStaticIcons() { | ||
if (!class_exists('org\\bovigo\\vfs\\vfsStream')) { | ||
$this->markTestSkipped('Pacakge vfsStream not installed'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only run this test if the vfsStream pacakge is avaialble.. since the outcome of owncloud-archive/3rdparty#185 is unclear
Rebased and added conditional to only run the test requiring vfsStream if it is available. Review time! |
Jenkins is happy! #17889 Review time: @MorrisJobke @PVince81 @DeepDiver1975 @Xenopathic your 👍 is still valid I assume? |
@@ -496,9 +428,10 @@ static function getSecureMimeType($mimeType) { | |||
* | |||
* @param string $data | |||
* @return string | |||
* @deprecated Use \OC::$server->getMimeTypeDetector()->detectString($data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing deprecation version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add (right before merge) else jenkins migt die...
* Copied unit tests from old functions
In order to properly test the mimetype function: * constructor takes path to configdir * Added unit tests for mimetype (only if vfsStream is available)
A new inspection was created. |
👍 Let's go! cc @MorrisJobke @PVince81 |
Code looks good and it still works 👍 |
As described in #4774 (comment)
Moving aways from the mimetype stuff in OC_Helper.
available unit tests are copied and modified.
It should not provide to much trouble as most functions were already wrappers around this.