Completed
Push — master ( 1ed12b...1ef741 )
by Nicolas
07:28
created

it_can_create_multiple_tags_at_once()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Modules\Tag\Tests\Integration;
4
5
use Modules\Page\Entities\Page;
6
use Modules\Page\Repositories\PageRepository;
7
use Modules\Tag\Repositories\TagRepository;
8
use Modules\Tag\Tests\BaseTestCase;
9
10
class TaggableTraitTest extends BaseTestCase
11
{
12
    /**
13
     * @var TagRepository
14
     */
15
    private $tag;
16
    /**
17
     * @var PageRepository
18
     */
19
    private $page;
20
21
    public function setUp()
22
    {
23
        parent::setUp();
24
25
        $this->tag = app(TagRepository::class);
26
        $this->page = app(PageRepository::class);
27
    }
28
29
    /** @test */
30
    public function it_creates_tags_on_creation_of_related_model()
31
    {
32
        $page = $this->createPage();
33
34
        $page->setTags(['my first tag']);
35
36
        $this->assertCount(1, $this->tag->all());
37
    }
38
39
    /** @test */
40
    public function it_can_create_multiple_tags_at_once()
41
    {
42
        $page = $this->createPage();
43
44
        $page->setTags(['my first tag', 'second tag', 'third tag']);
45
46
        $this->assertCount(3, $this->tag->all());
47
    }
48
49
    /** @test */
50 View Code Duplication
    public function it_links_tags_to_entity()
0 ignored issues
show
Duplication introduced by Nicolas Widart
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $page = $this->createPage();
53
54
        $page->setTags(['my first tag']);
55
56
        $page = $this->page->findHomepage();
57
58
        $this->assertCount(1, $page->tags);
59
    }
60
61
    /** @test */
62 View Code Duplication
    public function it_removes_tags_from_link_with_entity()
0 ignored issues
show
Duplication introduced by Nicolas Widart
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $this->createPage(['original tag']);
65
66
        $page = $this->page->findHomepage();
67
        $page->setTags(['my first tag']);
68
69
        $page = $this->page->findHomepage();
70
        $this->assertCount(1, $page->tags);
71
    }
72
73
    /** @test */
74 View Code Duplication
    public function it_can_get_pages_with_one_of_specified_tags()
0 ignored issues
show
Duplication introduced by Nicolas Widart
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $this->createPage(['original tag']);
77
        $this->createPage(['original-tag']);
78
        $this->createPage(['random tag']);
79
80
        $this->assertCount(2, Page::withTag(['original-tag', 'some-other-tag'])->get());
81
    }
82
83
    /** @test */
84 View Code Duplication
    public function it_gets_pages_with_all_specified_tags()
0 ignored issues
show
Duplication introduced by Nicolas Widart
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        $this->createPage(['original tag']);
87
        $this->createPage(['original-tag']);
88
        $this->createPage(['random tag', 'original-tag']);
89
90
        $this->assertCount(1, Page::whereTag(['original-tag', 'random-tag'])->get());
91
    }
92
93
    private function createPage(array $tags = [])
94
    {
95
        return $this->page->create([
96
            'is_home' => 1,
97
            'template' => 'default',
98
            'en' => [
99
                'title' => 'My Page',
100
                'slug' => 'my-page',
101
                'body' => 'My Page Body',
102
            ],
103
            'tags' => $tags,
104
        ]);
105
    }
106
}
107