mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #573 from creative-commoners/pulls/3.2/multibyte-tag-tests
FIX Categories and tags now respect multibyte url configuration
This commit is contained in:
commit
23f05ac21e
@ -17,6 +17,8 @@ use SilverStripe\Forms\NumericField;
|
|||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\ORM\HasManyList;
|
||||||
|
use SilverStripe\ORM\ManyManyList;
|
||||||
use SilverStripe\ORM\SS_List;
|
use SilverStripe\ORM\SS_List;
|
||||||
use SilverStripe\ORM\UnsavedRelationList;
|
use SilverStripe\ORM\UnsavedRelationList;
|
||||||
use SilverStripe\Security\Group;
|
use SilverStripe\Security\Group;
|
||||||
|
@ -267,9 +267,14 @@ class BlogController extends PageController
|
|||||||
$tag = $this->request->param('Tag');
|
$tag = $this->request->param('Tag');
|
||||||
if ($tag) {
|
if ($tag) {
|
||||||
$filter = URLSegmentFilter::create();
|
$filter = URLSegmentFilter::create();
|
||||||
|
// url encode unless it's multibyte (already pre-encoded in the database)
|
||||||
|
// see https://github.com/silverstripe/silverstripe-cms/pull/2384
|
||||||
|
if (!$filter->getAllowMultibyte()) {
|
||||||
|
$tag = rawurlencode($tag);
|
||||||
|
}
|
||||||
|
|
||||||
return $dataRecord->Tags()
|
return $dataRecord->Tags()
|
||||||
->filter('URLSegment', [$tag, $filter->filter($tag)])
|
->filter('URLSegment', $tag)
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -289,9 +294,8 @@ class BlogController extends PageController
|
|||||||
|
|
||||||
if ($this->isRSS()) {
|
if ($this->isRSS()) {
|
||||||
return $this->rssFeed($this->blogPosts, $category->getLink());
|
return $this->rssFeed($this->blogPosts, $category->getLink());
|
||||||
} else {
|
|
||||||
return $this->render();
|
|
||||||
}
|
}
|
||||||
|
return $this->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->httpError(404, 'Not Found');
|
$this->httpError(404, 'Not Found');
|
||||||
@ -313,9 +317,14 @@ class BlogController extends PageController
|
|||||||
$category = $this->request->param('Category');
|
$category = $this->request->param('Category');
|
||||||
if ($category) {
|
if ($category) {
|
||||||
$filter = URLSegmentFilter::create();
|
$filter = URLSegmentFilter::create();
|
||||||
|
// url encode unless it's multibyte (already pre-encoded in the database)
|
||||||
|
// see https://github.com/silverstripe/silverstripe-cms/pull/2384
|
||||||
|
if (!$filter->getAllowMultibyte()) {
|
||||||
|
$category = rawurlencode($category);
|
||||||
|
}
|
||||||
|
|
||||||
return $dataRecord->Categories()
|
return $dataRecord->Categories()
|
||||||
->filter('URLSegment', [$category, $filter->filter($category)])
|
->filter('URLSegment', $category)
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -16,6 +16,7 @@ use SilverStripe\Forms\ToggleCompositeField;
|
|||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||||
use SilverStripe\ORM\FieldType\DBHTMLText;
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||||
|
use SilverStripe\ORM\ManyManyList;
|
||||||
use SilverStripe\ORM\SS_List;
|
use SilverStripe\ORM\SS_List;
|
||||||
use SilverStripe\ORM\UnsavedRelationList;
|
use SilverStripe\ORM\UnsavedRelationList;
|
||||||
use SilverStripe\Security\Group;
|
use SilverStripe\Security\Group;
|
||||||
@ -25,7 +26,6 @@ use SilverStripe\Security\Security;
|
|||||||
use SilverStripe\TagField\TagField;
|
use SilverStripe\TagField\TagField;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
use SilverStripe\View\Parsers\ShortcodeParser;
|
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
39
tests/Model/BlogControllerFunctionalTest.php
Normal file
39
tests/Model/BlogControllerFunctionalTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Blog\Tests\Model;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
|
use SilverStripe\i18n\i18n;
|
||||||
|
use SilverStripe\View\Parsers\URLSegmentFilter;
|
||||||
|
|
||||||
|
class BlogControllerFunctionalTest extends FunctionalTest
|
||||||
|
{
|
||||||
|
protected static $fixture_file = 'BlogControllerFunctionalTest.yml';
|
||||||
|
|
||||||
|
protected static $use_draft_site = true;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
Config::modify()->set(URLSegmentFilter::class, 'default_allow_multibyte', true);
|
||||||
|
i18n::set_locale('fa_IR');
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCategoriesWithMultibyteUrl()
|
||||||
|
{
|
||||||
|
$result = $this->get('my-blog/category/' . rawurlencode('آبید'));
|
||||||
|
|
||||||
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
|
$this->assertContains('آبید', $result->getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetTagsWithMultibyteUrl()
|
||||||
|
{
|
||||||
|
$result = $this->get('my-blog/tag/' . rawurlencode('برتراند'));
|
||||||
|
|
||||||
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
|
$this->assertContains('برتراند', $result->getBody());
|
||||||
|
}
|
||||||
|
}
|
29
tests/Model/BlogControllerFunctionalTest.yml
Normal file
29
tests/Model/BlogControllerFunctionalTest.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
SilverStripe\Blog\Model\BlogCategory:
|
||||||
|
category_a:
|
||||||
|
Title: آبید
|
||||||
|
URLSegment: آبید
|
||||||
|
|
||||||
|
SilverStripe\Blog\Model\BlogTag:
|
||||||
|
tag_a:
|
||||||
|
Title: برتراند
|
||||||
|
URLSegment: برتراند
|
||||||
|
|
||||||
|
SilverStripe\Blog\Model\Blog:
|
||||||
|
blog_a:
|
||||||
|
URLSegment: my-blog
|
||||||
|
Title: My Blog
|
||||||
|
Categories:
|
||||||
|
- =>SilverStripe\Blog\Model\BlogCategory.category_a
|
||||||
|
Tags:
|
||||||
|
- =>SilverStripe\Blog\Model\BlogTag.tag_a
|
||||||
|
|
||||||
|
SilverStripe\Blog\Model\BlogPost:
|
||||||
|
blogpost_a:
|
||||||
|
Title: My Blog Post
|
||||||
|
URLSegment: آبیدآبید
|
||||||
|
PublishDate: 2017-08-01 00:00:00
|
||||||
|
Parent: =>SilverStripe\Blog\Model\Blog.blog_a
|
||||||
|
Categories:
|
||||||
|
- =>SilverStripe\Blog\Model\BlogCategory.category_a
|
||||||
|
Tags:
|
||||||
|
- =>SilverStripe\Blog\Model\BlogTag.tag_a
|
Loading…
Reference in New Issue
Block a user