Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7426664
FileBackendStoreTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
FileBackendStoreTest.php
View Options
<?php
use
Wikimedia\FileBackend\FileBackend
;
use
Wikimedia\FileBackend\MemoryFileBackend
;
use
Wikimedia\TestingAccessWrapper
;
/**
* @covers \Wikimedia\FileBackend\FileBackendStore
*/
class
FileBackendStoreTest
extends
MediaWikiIntegrationTestCase
{
/**
* @dataProvider provideGetContentType
*/
public
function
testGetContentType
(
$mimeFromString
)
{
global
$IP
;
if
(
$mimeFromString
)
{
$mimeCallback
=
[
$this
->
getServiceContainer
()->
getFileBackendGroup
(),
'guessMimeInternal'
];
}
else
{
$mimeCallback
=
null
;
}
$be
=
TestingAccessWrapper
::
newFromObject
(
new
MemoryFileBackend
(
[
'name'
=>
'testing'
,
'class'
=>
MemoryFileBackend
::
class
,
'wikiId'
=>
'meow'
,
'mimeCallback'
=>
$mimeCallback
,
]
)
);
$dst
=
'mwstore://testing/container/path/to/file_no_ext'
;
$src
=
"$IP/tests/phpunit/data/media/srgb.jpg"
;
$this
->
assertEquals
(
'image/jpeg'
,
$be
->
getContentType
(
$dst
,
null
,
$src
)
);
$this
->
assertEquals
(
$mimeFromString
?
'image/jpeg'
:
'unknown/unknown'
,
$be
->
getContentType
(
$dst
,
file_get_contents
(
$src
),
null
)
);
$src
=
"$IP/tests/phpunit/data/media/Png-native-test.png"
;
$this
->
assertEquals
(
'image/png'
,
$be
->
getContentType
(
$dst
,
null
,
$src
)
);
$this
->
assertEquals
(
$mimeFromString
?
'image/png'
:
'unknown/unknown'
,
$be
->
getContentType
(
$dst
,
file_get_contents
(
$src
),
null
)
);
}
public
static
function
provideGetContentType
()
{
return
[
[
false
],
[
true
],
];
}
public
function
testSanitizeOpHeaders
()
{
$be
=
TestingAccessWrapper
::
newFromObject
(
new
MemoryFileBackend
(
[
'name'
=>
'localtesting'
,
'wikiId'
=>
'wikidb'
,
]
)
);
$input
=
[
'headers'
=>
[
'content-Disposition'
=>
FileBackend
::
makeContentDisposition
(
'inline'
,
'name'
),
'Content-dUration'
=>
25.6
,
'X-LONG-VALUE'
=>
str_pad
(
'0'
,
300
),
'CONTENT-LENGTH'
=>
855055
,
],
];
$expected
=
[
'headers'
=>
[
'content-disposition'
=>
FileBackend
::
makeContentDisposition
(
'inline'
,
'name'
),
'content-duration'
=>
25.6
,
'content-length'
=>
855055
,
],
];
$actual
=
@
$be
->
sanitizeOpHeaders
(
$input
);
$this
->
assertEquals
(
$expected
,
$actual
,
"Header sanitized properly"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 08:34 (17 h, 50 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
43/88/e453eb961b8052320d53a5ff8ecd
Default Alt Text
FileBackendStoreTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment