From cd29b8c74cce9835e69a9137de8c985d2de88644 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Fri, 2 Nov 2012 09:34:34 +1300 Subject: [PATCH] Adding additional tests for special characters in FileNameFilterTest --- tests/filesystem/FileNameFilterTest.php | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/filesystem/FileNameFilterTest.php b/tests/filesystem/FileNameFilterTest.php index 371f4dcdf..bfb94b431 100644 --- a/tests/filesystem/FileNameFilterTest.php +++ b/tests/filesystem/FileNameFilterTest.php @@ -66,4 +66,46 @@ class FileNameFilterTest extends SapphireTest { $this->assertEquals('test.txt', $filter->filter($name)); } + function testDotsStartOfNameRemoved() { + $name = '.test.txt'; + $filter = new FileNameFilter(); + $this->assertEquals('test.txt', $filter->filter($name)); + } + + function testDoubleDotsStartOfNameRemoved() { + $name = '..test.txt'; + $filter = new FileNameFilter(); + $this->assertEquals('test.txt', $filter->filter($name)); + } + + function testMixedInvalidCharsStartOfNameRemoved() { + $name = '..#@$#@$^__test.txt'; + $filter = new FileNameFilter(); + $this->assertEquals('test.txt', $filter->filter($name)); + } + + function testWhitespaceRemoved() { + $name = ' test doc.txt'; + $filter = new FileNameFilter(); + $this->assertEquals('test-doc.txt', $filter->filter($name)); + } + + function testUnderscoresReplacedWithDashes() { + $name = 'test_doc.txt'; + $filter = new FileNameFilter(); + $this->assertEquals('test-doc.txt', $filter->filter($name)); + } + + function testNonAsciiCharsReplacedWithDashes() { + $name = '!@#$%^test_123@##@$#%^.txt'; + $filter = new FileNameFilter(); + $this->assertEquals('test-123.txt', $filter->filter($name)); + } + + function testDuplicateDashesRemoved() { + $name = 'test--document.txt'; + $filter = new FileNameFilter(); + $this->assertEquals('test-document.txt', $filter->filter($name)); + } + }