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
d771f659
Unverified
Commit
d771f659
authored
7 years ago
by
Julius Härtl
Browse files
Options
Downloads
Patches
Plain Diff
Add more tests for ImageManager
Signed-off-by:
Julius Härtl
<
jus@bitgrid.net
>
parent
b385f1c7
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
apps/theming/tests/ImageManagerTest.php
+91
-0
91 additions, 0 deletions
apps/theming/tests/ImageManagerTest.php
with
91 additions
and
0 deletions
apps/theming/tests/ImageManagerTest.php
+
91
−
0
View file @
d771f659
...
@@ -55,6 +55,97 @@ class ImageManagerTest extends TestCase {
...
@@ -55,6 +55,97 @@ class ImageManagerTest extends TestCase {
);
);
}
}
public
function
mockGetImage
(
$key
,
$file
)
{
/** @var \PHPUnit_Framework_MockObject_MockObject $folder */
$folder
=
$this
->
createMock
(
ISimpleFolder
::
class
);
if
(
$file
===
null
)
{
$folder
->
expects
(
$this
->
once
())
->
method
(
'getFile'
)
->
with
(
'logo'
)
->
willThrowException
(
new
NotFoundException
());
}
else
{
$folder
->
expects
(
$this
->
once
())
->
method
(
'getFile'
)
->
with
(
'logo'
)
->
willReturn
(
$file
);
$this
->
appData
->
expects
(
$this
->
once
())
->
method
(
'getFolder'
)
->
with
(
'images'
)
->
willReturn
(
$folder
);
}
}
public
function
testGetImageUrl
()
{
$file
=
$this
->
createMock
(
ISimpleFile
::
class
);
$this
->
config
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'getAppValue'
)
->
withConsecutive
(
[
'theming'
,
'cachebuster'
,
'0'
],
[
'theming'
,
'logoMime'
,
false
]
)
->
willReturn
(
0
);
$this
->
mockGetImage
(
'logo'
,
$file
);
$this
->
urlGenerator
->
expects
(
$this
->
once
())
->
method
(
'linkToRoute'
)
->
willReturn
(
'url-to-image'
);
$this
->
assertEquals
(
'url-to-image?v=0'
,
$this
->
imageManager
->
getImageUrl
(
'logo'
));
}
public
function
testGetImageUrlDefault
()
{
$this
->
config
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'getAppValue'
)
->
withConsecutive
(
[
'theming'
,
'cachebuster'
,
'0'
],
[
'theming'
,
'logoMime'
,
false
]
)
->
willReturnOnConsecutiveCalls
(
0
,
false
);
$this
->
urlGenerator
->
expects
(
$this
->
once
())
->
method
(
'imagePath'
)
->
with
(
'core'
,
'logo.png'
)
->
willReturn
(
'logo.png'
);
$this
->
assertEquals
(
'logo.png?v=0'
,
$this
->
imageManager
->
getImageUrl
(
'logo'
));
}
public
function
testGetImageUrlAbsolute
()
{
$file
=
$this
->
createMock
(
ISimpleFile
::
class
);
$this
->
config
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'getAppValue'
)
->
withConsecutive
(
[
'theming'
,
'cachebuster'
,
'0'
],
[
'theming'
,
'logoMime'
,
false
]
)
->
willReturn
(
0
);
$this
->
mockGetImage
(
'logo'
,
$file
);
$this
->
urlGenerator
->
expects
(
$this
->
at
(
0
))
->
method
(
'linkToRoute'
)
->
willReturn
(
'url-to-image'
);
$this
->
urlGenerator
->
expects
(
$this
->
at
(
1
))
->
method
(
'getAbsoluteUrl'
)
->
with
(
'url-to-image?v=0'
)
->
willReturn
(
'url-to-image-absolute?v=0'
);
$this
->
assertEquals
(
'url-to-image-absolute?v=0'
,
$this
->
imageManager
->
getImageUrlAbsolute
(
'logo'
));
}
public
function
testGetImage
()
{
$this
->
config
->
expects
(
$this
->
once
())
->
method
(
'getAppValue'
)
->
with
(
'theming'
,
'logoMime'
,
false
)
->
willReturn
(
'png'
);
$file
=
$this
->
createMock
(
ISimpleFile
::
class
);
$this
->
mockGetImage
(
'logo'
,
$file
);
$this
->
assertEquals
(
$file
,
$this
->
imageManager
->
getImage
(
'logo'
));
}
/**
* @expectedException OCP\Files\NotFoundException
*/
public
function
testGetImageUnset
()
{
$this
->
config
->
expects
(
$this
->
once
())
->
method
(
'getAppValue'
)
->
with
(
'theming'
,
'logoMime'
,
false
)
->
willReturn
(
false
);
$this
->
imageManager
->
getImage
(
'logo'
);
}
public
function
testGetCacheFolder
()
{
public
function
testGetCacheFolder
()
{
$folder
=
$this
->
createMock
(
ISimpleFolder
::
class
);
$folder
=
$this
->
createMock
(
ISimpleFolder
::
class
);
$this
->
config
->
expects
(
$this
->
once
())
$this
->
config
->
expects
(
$this
->
once
())
...
...
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