mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-13 16:34:52 +09:00
Add unit tests for FilenameFilter class
This commit is contained in:
parent
b962409652
commit
1c32e993ab
1 changed files with 42 additions and 0 deletions
42
tests/unit/framework/security/FilenameFilterTest.php
Normal file
42
tests/unit/framework/security/FilenameFilterTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
class FilenameFilterTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
public function testFilenameFilterClean()
|
||||
{
|
||||
$tests = array(
|
||||
|
||||
// Illegal characters
|
||||
'foo*\.bar' => 'foo.bar',
|
||||
'foobar{baz}.jpg' => 'foobar(baz).jpg',
|
||||
'foobar^%.docx' => 'foobar_.docx',
|
||||
|
||||
// Control characters
|
||||
'foobar' . chr(127) . '.gif' => 'foobar.gif',
|
||||
'foobar' . "\t\r\n" . '.gif' => 'foobar.gif',
|
||||
|
||||
// Unicode whitepace characters
|
||||
'foobar' . html_entity_decode(' ') . ' space.gif' => 'foobar space.gif',
|
||||
'hello world.png' => 'hello world.png',
|
||||
|
||||
// Extra symbols
|
||||
'_foobar.jpg-' => 'foobar.jpg',
|
||||
'.htaccess' => 'htaccess',
|
||||
|
||||
// PHP extension
|
||||
'foobar.php' => 'foobar.phps',
|
||||
'foobar.php.jpg' => 'foobar.php.jpg',
|
||||
|
||||
// Overlong filenames
|
||||
str_repeat('f', 200) . '.' . str_repeat('b', 30) => str_repeat('f', 111) . '.' . str_repeat('b', 15),
|
||||
str_repeat('한글', 100) . '.hwp' => str_repeat('한글', 61) . '한.hwp',
|
||||
|
||||
);
|
||||
|
||||
foreach ($tests as $from => $to)
|
||||
{
|
||||
$result = Rhymix\Framework\Security\FilenameFilter::clean($from);
|
||||
$this->assertEquals($to, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue