-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent creation of duplicate terms on slug change (#384)
* Fetch term by old slug if present Signed-off-by: Philipp Daun <[email protected]> * Add a test --------- Signed-off-by: Philipp Daun <[email protected]> Co-authored-by: Ryan Mitchell <[email protected]>
- Loading branch information
1 parent
9b69409
commit b5ed5ba
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Tests\Terms; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Eloquent\Taxonomies\Taxonomy; | ||
use Statamic\Eloquent\Taxonomies\TermModel; | ||
use Statamic\Facades\Term as TermFacade; | ||
use Tests\TestCase; | ||
|
||
class TermTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
#[Test] | ||
public function it_doesnt_create_a_new_model_when_slug_is_changed() | ||
{ | ||
Taxonomy::make('test')->title('test')->save(); | ||
|
||
$term = tap(TermFacade::make('test-term')->taxonomy('test')->data([]))->save(); | ||
|
||
$this->assertCount(1, TermModel::all()); | ||
$this->assertSame('test-term', TermModel::first()->slug); | ||
|
||
$term->slug('new-slug'); | ||
$term->save(); | ||
|
||
$this->assertCount(1, TermModel::all()); | ||
$this->assertSame('new-slug', TermModel::first()->slug); | ||
} | ||
} |