mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-25 03:55:50 +02:00
+ has a special meaning in the URLs so overall it's a good idea to strip them out. Otherwise they would need to appear in their ugly url encoded form "%2B". Refer: http://open.silverstripe.org/ticket/7929
61 lines
1.2 KiB
PHP
61 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* @package framework
|
|
* @subpackage tests
|
|
*/
|
|
class URLSegmentFilterTest extends SapphireTest {
|
|
|
|
public function testReplacesCommonEnglishSymbols() {
|
|
$f = new URLSegmentFilter();
|
|
$f->setAllowMultibyte(false);
|
|
$this->assertEquals(
|
|
'john-and-spencer',
|
|
$f->filter('John & Spencer')
|
|
);
|
|
}
|
|
|
|
public function testTransliteratesNonAsciiUrls() {
|
|
$f = new URLSegmentFilter();
|
|
$f->setAllowMultibyte(false);
|
|
$this->assertEquals(
|
|
'broetchen',
|
|
$f->filter('Brötchen')
|
|
);
|
|
}
|
|
|
|
public function testReplacesCommonNonAsciiCharacters() {
|
|
$f = new URLSegmentFilter();
|
|
$this->assertEquals(
|
|
urlencode('aa1-.'),
|
|
$f->filter('Aa1~!@#$%^*()_+`-=;\':"[]\{}|,./<>?')
|
|
);
|
|
}
|
|
|
|
public function testRetainsNonAsciiUrlsWithAllowMultiByteOption() {
|
|
$f = new URLSegmentFilter();
|
|
$f->setAllowMultibyte(true);
|
|
$this->assertEquals(
|
|
urlencode('brötchen'),
|
|
$f->filter('Brötchen')
|
|
);
|
|
}
|
|
|
|
public function testReplacements() {
|
|
$f = new URLSegmentFilter();
|
|
$this->assertEquals(
|
|
'tim-and-struppi',
|
|
$f->filter('Tim&Struppi')
|
|
);
|
|
|
|
// Customize replacements
|
|
$rs = $f->getReplacements();
|
|
$rs['/&/u'] = '-und-';
|
|
$f->setReplacements($rs);
|
|
$this->assertEquals(
|
|
'tim-und-struppi',
|
|
$f->filter('Tim&Struppi')
|
|
);
|
|
}
|
|
|
|
}
|