Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

70 lines (62 sloc) 1.685 kb
<?php
/**
* @package framework
* @subpackage tests
*/
class FileNameFilterTest extends SapphireTest {
public function testFilter() {
$name = 'Brötchen für allë-mit_Unterstrich!.jpg';
$filter = new FileNameFilter();
$filter->setTransliterator(false);
$this->assertEquals(
'Brtchen-fr-all-mit-Unterstrich.jpg',
$filter->filter($name)
);
}
public function testFilterWithTransliterator() {
$name = 'Brötchen für allë-mit_Unterstrich!.jpg';
$filter = new FileNameFilter();
$filter->setTransliterator(new SS_Transliterator());
$this->assertEquals(
'Broetchen-fuer-alle-mit-Unterstrich.jpg',
$filter->filter($name)
);
}
public function testFilterWithCustomRules() {
$name = 'Kuchen ist besser.jpg';
$filter = new FileNameFilter();
$filter->setTransliterator(false);
$filter->setReplacements(array('/[\s-]/' => '_'));
$this->assertEquals(
'Kuchen_ist_besser.jpg',
$filter->filter($name)
);
}
public function testFilterWithEmptyString() {
$name = 'ö ö ö.jpg';
$filter = new FileNameFilter();
$filter->setTransliterator(new SS_Transliterator());
$result = $filter->filter($name);
$this->assertFalse(
empty($result)
);
$this->assertStringEndsWith(
'.jpg',
$result
);
$this->assertGreaterThan(
strlen('.jpg'),
strlen($result)
);
}
function testUnderscoresStartOfNameRemoved() {
$name = '_test.txt';
$filter = new FileNameFilter();
$this->assertEquals('test.txt', $filter->filter($name));
}
function testDoubleUnderscoresStartOfNameRemoved() {
$name = '__test.txt';
$filter = new FileNameFilter();
$this->assertEquals('test.txt', $filter->filter($name));
}
}
Jump to Line
Something went wrong with that request. Please try again.