From 1c32e993abaefce4bdba93ee4cf221808039ec4a Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sat, 12 Mar 2016 17:42:28 +0900 Subject: [PATCH] Add unit tests for FilenameFilter class --- .../framework/security/FilenameFilterTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/unit/framework/security/FilenameFilterTest.php diff --git a/tests/unit/framework/security/FilenameFilterTest.php b/tests/unit/framework/security/FilenameFilterTest.php new file mode 100644 index 000000000..935ffd473 --- /dev/null +++ b/tests/unit/framework/security/FilenameFilterTest.php @@ -0,0 +1,42 @@ + '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); + } + } +}