Commit 8e8bc6d2 authored by 박관영's avatar 박관영

Add test to assure generateTagSlug() works like str_slug()

parent b8097224
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Modules\Tag\Tests\Integration; namespace Modules\Tag\Tests\Integration;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Modules\Page\Entities\Page; use Modules\Page\Entities\Page;
use Modules\Page\Repositories\PageRepository; use Modules\Page\Repositories\PageRepository;
use Modules\Tag\Repositories\TagRepository; use Modules\Tag\Repositories\TagRepository;
...@@ -132,6 +133,18 @@ class TaggableTraitTest extends BaseTestCase ...@@ -132,6 +133,18 @@ class TaggableTraitTest extends BaseTestCase
$this->assertCount(3, Page::allTags()->get()); $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 */ /** @test */
public function it_gets_pages_with_non_latin_tags() public function it_gets_pages_with_non_latin_tags()
{ {
......
...@@ -204,7 +204,7 @@ trait TaggableTrait ...@@ -204,7 +204,7 @@ trait TaggableTrait
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function generateTagSlug($name, $separator = '-') public function generateTagSlug($name, $separator = '-')
{ {
// Convert all dashes/underscores into separator // Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-'; $flip = $separator == '-' ? '_' : '-';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment