FIX Translatable now handles multibute URLs when they are enabled

This commit is contained in:
Robbie Averill 2019-04-05 14:22:05 +13:00
parent 4cf60e9393
commit c09866f586
2 changed files with 31 additions and 1 deletions

View File

@ -1473,6 +1473,11 @@ class Translatable extends DataExtension implements PermissionProvider {
$urlSegment = $newTranslation->URLSegment;
}
if (URLSegmentFilter::singleton()->getAllowMultibyte()) {
// Decode the URL segment, it will be re-encoded again on write
$urlSegment = rawurldecode($urlSegment);
}
// Only make segment unique if it should be enforced
if(Config::inst()->get('Translatable', 'enforce_global_unique_urls')) {
$newTranslation->URLSegment = $urlSegment . '-' . i18n::convert_rfc1766($locale);

View File

@ -460,6 +460,31 @@ class TranslatableTest extends FunctionalTest {
Translatable::set_current_locale('en_US');
}
public function testMultibyteUrlsWorkWhenTranslated()
{
Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', true);
$page = new Page();
$page->URLSegment = 'schön-döner';
$page->Content = 'Kebabs in Berlin are amazing.';
$page->write();
$page->doPublish();
$translatedPage = $page->createTranslation('de_DE');
$translatedPage->Content = 'Döner in Berlin sind unglaublich';
$translatedPage->doPublish();
$this->assertSame('schön-döner-de-de', rawurldecode($translatedPage->URLSegment));
// Test pinging the page on the frontend
$pageResult = $this->get('schön-döner');
$this->assertEquals(200, $pageResult->getStatusCode());
$this->assertContains('Kebabs in Berlin', (string) $pageResult->getBody());
$translatedPageResult = $this->get('schön-döner-de-de');
$this->assertEquals(200, $translatedPageResult->getStatusCode());
$this->assertContains('Döner in Berlin', (string) $translatedPageResult->getBody());
}
function testUpdateCMSFieldsOnSiteTree() {
$pageOrigLang = new TranslatableTest_Page();
$pageOrigLang->write();