2011-11-14 12:26:51 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2011-11-14 12:26:51 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class URLSegmentFilterTest extends SapphireTest {
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testReplacesCommonEnglishSymbols() {
|
2011-11-14 12:26:51 +01:00
|
|
|
$f = new URLSegmentFilter();
|
|
|
|
$f->setAllowMultibyte(false);
|
|
|
|
$this->assertEquals(
|
|
|
|
'john-and-spencer',
|
|
|
|
$f->filter('John & Spencer')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testTransliteratesNonAsciiUrls() {
|
2011-11-14 12:26:51 +01:00
|
|
|
$f = new URLSegmentFilter();
|
|
|
|
$f->setAllowMultibyte(false);
|
|
|
|
$this->assertEquals(
|
|
|
|
'broetchen',
|
|
|
|
$f->filter('Brötchen')
|
|
|
|
);
|
|
|
|
}
|
2012-12-18 03:43:05 +01:00
|
|
|
|
|
|
|
public function testReplacesCommonNonAsciiCharacters() {
|
|
|
|
$f = new URLSegmentFilter();
|
|
|
|
$this->assertEquals(
|
|
|
|
urlencode('aa1-.'),
|
|
|
|
$f->filter('Aa1~!@#$%^*()_+`-=;\':"[]\{}|,./<>?')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRetainsNonAsciiUrlsWithAllowMultiByteOption() {
|
2011-11-14 12:26:51 +01:00
|
|
|
$f = new URLSegmentFilter();
|
|
|
|
$f->setAllowMultibyte(true);
|
|
|
|
$this->assertEquals(
|
2012-02-06 11:56:26 +01:00
|
|
|
urlencode('brötchen'),
|
2011-11-14 12:26:51 +01:00
|
|
|
$f->filter('Brötchen')
|
|
|
|
);
|
|
|
|
}
|
2011-12-17 01:13:27 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testReplacements() {
|
2011-12-17 01:13:27 +01:00
|
|
|
$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')
|
|
|
|
);
|
|
|
|
}
|
2011-11-14 12:26:51 +01:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|