From 8e8bc6d247f150638ba5024de9ed9e2d2959a935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EA=B4=80=EC=98=81?= Date: Tue, 27 Feb 2018 19:09:37 +0900 Subject: [PATCH] Add test to assure generateTagSlug() works like str_slug() --- Modules/Tag/Tests/Integration/TaggableTraitTest.php | 13 +++++++++++++ Modules/Tag/Traits/TaggableTrait.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Modules/Tag/Tests/Integration/TaggableTraitTest.php b/Modules/Tag/Tests/Integration/TaggableTraitTest.php index f7ddfe11b..ccee276ea 100644 --- a/Modules/Tag/Tests/Integration/TaggableTraitTest.php +++ b/Modules/Tag/Tests/Integration/TaggableTraitTest.php @@ -3,6 +3,7 @@ namespace Modules\Tag\Tests\Integration; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Str; use Modules\Page\Entities\Page; use Modules\Page\Repositories\PageRepository; use Modules\Tag\Repositories\TagRepository; @@ -132,6 +133,18 @@ public function it_gets_all_tags_for_a_namespace() $this->assertCount(3, Page::allTags()->get()); } + /** @test */ + public function it_generates_slug_like_original_str_slug() + { + $page = $this->createPage(); + + $this->assertEquals(Str::slug('hello world'), $page->generateTagSlug('hello world')); + $this->assertEquals(Str::slug('hello world'), $page->generateTagSlug('hello-world')); + $this->assertEquals(Str::slug('hello_world'), $page->generateTagSlug('hello_world')); + $this->assertEquals(Str::slug('hello_world', '_'), $page->generateTagSlug('hello_world', '_')); + $this->assertEquals(Str::slug('user@host'), $page->generateTagSlug('user@host')); + } + /** @test */ public function it_gets_pages_with_non_latin_tags() { diff --git a/Modules/Tag/Traits/TaggableTrait.php b/Modules/Tag/Traits/TaggableTrait.php index b8dcbca71..2c6df68e2 100644 --- a/Modules/Tag/Traits/TaggableTrait.php +++ b/Modules/Tag/Traits/TaggableTrait.php @@ -204,7 +204,7 @@ protected function getEntityClassName() /** * {@inheritdoc} */ - protected function generateTagSlug($name, $separator = '-') + public function generateTagSlug($name, $separator = '-') { // Convert all dashes/underscores into separator $flip = $separator == '-' ? '_' : '-';