From 52d278afe64d009be5081d1f9928b04700bfba7e Mon Sep 17 00:00:00 2001 From: Mariusz Fik Date: Mon, 16 Apr 2018 21:28:54 +0200 Subject: [PATCH] Set tags only if passed any. Signed-off-by: Mariusz Fik --- Modules/Tag/Tests/Integration/TaggableTraitTest.php | 11 +++++++++++ Modules/Tag/Traits/TaggableTrait.php | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/Modules/Tag/Tests/Integration/TaggableTraitTest.php b/Modules/Tag/Tests/Integration/TaggableTraitTest.php index ccee276ea..ae219772e 100644 --- a/Modules/Tag/Tests/Integration/TaggableTraitTest.php +++ b/Modules/Tag/Tests/Integration/TaggableTraitTest.php @@ -153,6 +153,17 @@ public function it_gets_pages_with_non_latin_tags() $this->assertCount(1, Page::whereTag(['ํ•œ๊ธ€-ํƒœ๊ทธ'])->get()); } + /** @test */ + public function it_creates_page_without_tags() + { + $this->createPage(['original tag']); + + $page = $this->page->find(1); + $page->setTags(null); + + $this->assertEmpty(Page::first()->tags->count()); + } + private function createPage(array $tags = []) { return $this->page->create([ diff --git a/Modules/Tag/Traits/TaggableTrait.php b/Modules/Tag/Traits/TaggableTrait.php index 2c6df68e2..08fb9275b 100644 --- a/Modules/Tag/Traits/TaggableTrait.php +++ b/Modules/Tag/Traits/TaggableTrait.php @@ -97,6 +97,10 @@ public static function allTags() */ public function setTags($tags, $type = 'slug') { + if (empty($tags)) { + $tags = []; + } + // Get the current entity tags $entityTags = $this->tags->pluck($type)->all();