mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #5481 from mikenz/file-name-filter-test
Explictly set the FileNameFilter replacements before testing them
This commit is contained in:
commit
24bea79cd9
@ -5,6 +5,18 @@
|
|||||||
*/
|
*/
|
||||||
class FileNameFilterTest extends SapphireTest {
|
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() {
|
public function testFilter() {
|
||||||
$name = 'Brötchen für allë-mit_Unterstrich!.jpg';
|
$name = 'Brötchen für allë-mit_Unterstrich!.jpg';
|
||||||
$filter = new FileNameFilter();
|
$filter = new FileNameFilter();
|
||||||
|
@ -21,6 +21,15 @@ class FolderTest extends SapphireTest {
|
|||||||
// Set backend root to /FolderTest
|
// Set backend root to /FolderTest
|
||||||
AssetStoreTest_SpyStore::activate('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
|
// Create a test folders for each of the fixture references
|
||||||
foreach(Folder::get() as $folder) {
|
foreach(Folder::get() as $folder) {
|
||||||
$path = AssetStoreTest_SpyStore::getLocalPath($folder);
|
$path = AssetStoreTest_SpyStore::getLocalPath($folder);
|
||||||
|
@ -24,6 +24,15 @@ class HTMLEditorFieldTest extends FunctionalTest {
|
|||||||
// Set backend root to /HTMLEditorFieldTest
|
// Set backend root to /HTMLEditorFieldTest
|
||||||
AssetStoreTest_SpyStore::activate('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
|
// Create a test files for each of the fixture references
|
||||||
$files = File::get()->exclude('ClassName', 'Folder');
|
$files = File::get()->exclude('ClassName', 'Folder');
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
|
@ -28,6 +28,15 @@ class UploadFieldTest extends FunctionalTest {
|
|||||||
// Set backend root to /UploadFieldTest
|
// Set backend root to /UploadFieldTest
|
||||||
AssetStoreTest_SpyStore::activate('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
|
// Create a test folders for each of the fixture references
|
||||||
foreach(Folder::get() as $folder) {
|
foreach(Folder::get() as $folder) {
|
||||||
$path = AssetStoreTest_SpyStore::getLocalPath($folder);
|
$path = AssetStoreTest_SpyStore::getLocalPath($folder);
|
||||||
|
Loading…
Reference in New Issue
Block a user