From e2d180a754eadf026e1a7f288143184e08ffaa20 Mon Sep 17 00:00:00 2001 From: "Cochrane, Mike" Date: Mon, 9 May 2016 20:03:58 +1200 Subject: [PATCH 1/2] Explictly set the FileNameFilter replacements before testing them --- tests/filesystem/FileNameFilterTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/filesystem/FileNameFilterTest.php b/tests/filesystem/FileNameFilterTest.php index af07208dd..902c83857 100644 --- a/tests/filesystem/FileNameFilterTest.php +++ b/tests/filesystem/FileNameFilterTest.php @@ -5,6 +5,18 @@ */ class FileNameFilterTest extends SapphireTest { + public function setUp() { + parent::setUp(); + + Config::inst()->update('FileNameFilter', 'default_replacements', array( + '/\s/' => '-', // remove whitespace + '/_/' => '-', // underscores to dashes + '/[^A-Za-z0-9+.\-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot + '/[\-]{2,}/' => '-', // remove duplicate dashes + '/^[\.\-_]+/' => '', // Remove all leading dots, dashes or underscores + )); + } + public function testFilter() { $name = 'Brötchen für allë-mit_Unterstrich!.jpg'; $filter = new FileNameFilter(); From faffdf4981106c8d2f763e380974a6c0537c7ecf Mon Sep 17 00:00:00 2001 From: "Cochrane, Mike" Date: Mon, 9 May 2016 20:12:29 +1200 Subject: [PATCH 2/2] Explictly set the FileNameFilter replacements before relying on them --- tests/filesystem/FolderTest.php | 9 +++++++++ tests/forms/HTMLEditorFieldTest.php | 9 +++++++++ tests/forms/uploadfield/UploadFieldTest.php | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/tests/filesystem/FolderTest.php b/tests/filesystem/FolderTest.php index 368696ced..515d6e696 100644 --- a/tests/filesystem/FolderTest.php +++ b/tests/filesystem/FolderTest.php @@ -21,6 +21,15 @@ class FolderTest extends SapphireTest { // Set backend root to /FolderTest AssetStoreTest_SpyStore::activate('FolderTest'); + // Set the File Name Filter replacements so files have the expected names + Config::inst()->update('FileNameFilter', 'default_replacements', array( + '/\s/' => '-', // remove whitespace + '/_/' => '-', // underscores to dashes + '/[^A-Za-z0-9+.\-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot + '/[\-]{2,}/' => '-', // remove duplicate dashes + '/^[\.\-_]+/' => '', // Remove all leading dots, dashes or underscores + )); + // Create a test folders for each of the fixture references foreach(Folder::get() as $folder) { $path = AssetStoreTest_SpyStore::getLocalPath($folder); diff --git a/tests/forms/HTMLEditorFieldTest.php b/tests/forms/HTMLEditorFieldTest.php index bb3ca8211..66c48eaae 100644 --- a/tests/forms/HTMLEditorFieldTest.php +++ b/tests/forms/HTMLEditorFieldTest.php @@ -24,6 +24,15 @@ class HTMLEditorFieldTest extends FunctionalTest { // Set backend root to /HTMLEditorFieldTest AssetStoreTest_SpyStore::activate('HTMLEditorFieldTest'); + // Set the File Name Filter replacements so files have the expected names + Config::inst()->update('FileNameFilter', 'default_replacements', array( + '/\s/' => '-', // remove whitespace + '/_/' => '-', // underscores to dashes + '/[^A-Za-z0-9+.\-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot + '/[\-]{2,}/' => '-', // remove duplicate dashes + '/^[\.\-_]+/' => '', // Remove all leading dots, dashes or underscores + )); + // Create a test files for each of the fixture references $files = File::get()->exclude('ClassName', 'Folder'); foreach($files as $file) { diff --git a/tests/forms/uploadfield/UploadFieldTest.php b/tests/forms/uploadfield/UploadFieldTest.php index aed1a9056..9b2783170 100644 --- a/tests/forms/uploadfield/UploadFieldTest.php +++ b/tests/forms/uploadfield/UploadFieldTest.php @@ -28,6 +28,15 @@ class UploadFieldTest extends FunctionalTest { // Set backend root to /UploadFieldTest AssetStoreTest_SpyStore::activate('UploadFieldTest'); + // Set the File Name Filter replacements so files have the expected names + Config::inst()->update('FileNameFilter', 'default_replacements', array( + '/\s/' => '-', // remove whitespace + '/_/' => '-', // underscores to dashes + '/[^A-Za-z0-9+.\-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot + '/[\-]{2,}/' => '-', // remove duplicate dashes + '/^[\.\-_]+/' => '', // Remove all leading dots, dashes or underscores + )); + // Create a test folders for each of the fixture references foreach(Folder::get() as $folder) { $path = AssetStoreTest_SpyStore::getLocalPath($folder);