-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathIlluminateTagTest.php
90 lines (69 loc) · 2.08 KB
/
IlluminateTagTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/*
* Part of the Tags package.
*
* NOTICE OF LICENSE
*
* Licensed under the 3-clause BSD License.
*
* This source file is subject to the 3-clause BSD License that is
* bundled with this package in the LICENSE file.
*
* @package Tags
* @version 15.0.0
* @author Cartalyst LLC
* @license BSD License (3-clause)
* @copyright (c) 2011-2025, Cartalyst LLC
* @link https://cartalyst.com
*/
namespace Cartalyst\Tags\Tests;
use Cartalyst\Tags\IlluminateTag;
use Cartalyst\Tags\IlluminateTagged;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use PHPUnit\Framework\Attributes\Test;
class IlluminateTagTest extends FunctionalTestCase
{
#[Test]
public function it_can_delete_a_tag_and_its_tagged_relations()
{
$post = $this->createPost();
$post->tag('foo, bar');
$this->assertCount(2, $post->tags);
$tag = IlluminateTag::first();
$tag->delete();
$post = $post->fresh();
$this->assertCount(1, $post->tags);
}
#[Test]
public function it_has_a_taggable_relationship()
{
$tag = new IlluminateTag();
$this->assertInstanceOf(MorphTo::class, $tag->taggable());
}
#[Test]
public function it_has_a_tag_relationship()
{
$tag = new IlluminateTag();
$this->assertInstanceOf(HasMany::class, $tag->tagged());
}
#[Test]
public function it_has_a_name_scope()
{
IlluminateTag::create(['name' => 'Foo', 'slug' => 'foo', 'namespace' => 'foo']);
$this->assertCount(1, IlluminateTag::name('Foo')->get());
}
#[Test]
public function it_has_a_slug_scope()
{
IlluminateTag::create(['name' => 'Foo', 'slug' => 'foo', 'namespace' => 'foo']);
$this->assertCount(1, IlluminateTag::slug('foo')->get());
}
#[Test]
public function it_can_get_and_set_the_tagged_model()
{
$tag = new IlluminateTag();
$tag->setTaggedModel(IlluminateTagged::class);
$this->assertSame(IlluminateTagged::class, $tag->getTaggedModel());
}
}