it_creates_plain_setting()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 15
rs 9.4286
c 1
b 0
f 1
cc 1
eloc 7
nc 1
nop 0
1
<?php namespace Modules\Setting\Tests;
2
3
class EloquentSettingRepositoryTest extends BaseSettingTest
4
{
5
    public function setUp()
6
    {
7
        parent::setUp();
8
    }
9
10
    /** @test */
11 View Code Duplication
    public function it_creates_translated_setting()
0 ignored issues
show
Duplication introduced by
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...
12
    {
13
        // Prepare
14
        $data = [
15
            'core::site-name' => [
16
                'en' => 'AsgardCMS_en',
17
                'fr' => 'AsgardCMS_fr',
18
            ],
19
        ];
20
21
        // Run
22
        $this->settingRepository->createOrUpdate($data);
23
24
        // Assert
25
        $setting = $this->settingRepository->find(1);
26
        $this->assertEquals('core::site-name', $setting->name);
27
        $this->assertEquals('AsgardCMS_en', $setting->translate('en')->value);
28
        $this->assertEquals('AsgardCMS_fr', $setting->translate('fr')->value);
29
    }
30
31
    /** @test */
32
    public function it_creates_plain_setting()
33
    {
34
        // Prepare
35
        $data = [
36
            'core::template' => 'asgard',
37
        ];
38
39
        // Run
40
        $this->settingRepository->createOrUpdate($data);
41
42
        // Assert
43
        $setting = $this->settingRepository->find(1);
44
        $this->assertEquals('core::template', $setting->name);
45
        $this->assertEquals('asgard', $setting->plainValue);
46
    }
47
48
    /** @test */
49 View Code Duplication
    public function it_finds_setting_by_name()
0 ignored issues
show
Duplication introduced by
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...
50
    {
51
        // Prepare
52
        $data = [
53
            'core::site-name' => [
54
                'en' => 'AsgardCMS_en',
55
                'fr' => 'AsgardCMS_fr',
56
            ],
57
        ];
58
59
        // Run
60
        $this->settingRepository->createOrUpdate($data);
61
62
        // Assert
63
        $setting = $this->settingRepository->findByName('core::site-name');
64
        $this->assertEquals('core::site-name', $setting->name);
65
        $this->assertEquals('AsgardCMS_en', $setting->translate('en')->value);
66
        $this->assertEquals('AsgardCMS_fr', $setting->translate('fr')->value);
67
    }
68
69
    /** @test */
70
    public function it_returns_module_settings()
71
    {
72
        // Prepare
73
        $data = [
74
            'core::site-name' => [
75
                'en' => 'AsgardCMS_en',
76
                'fr' => 'AsgardCMS_fr',
77
            ],
78
            'core::template' => 'asgard',
79
            'blog::posts-per-page' => 10,
80
        ];
81
82
        // Run
83
        $this->settingRepository->createOrUpdate($data);
84
85
        // Assert
86
        $blogSettings = $this->settingRepository->findByModule('blog');
87
        $this->assertEquals(1, $blogSettings->count());
88
        $coreSettings = $this->settingRepository->findByModule('core');
89
        $this->assertEquals(2, $coreSettings->count());
90
    }
91
92
    /** @test */
93
    public function it_encodes_array_of_non_translatable_data()
94
    {
95
        // Prepare
96
        $data = [
97
            'core::locales' => [
98
                "su",
99
                "bi",
100
                "bs",
101
            ],
102
        ];
103
104
        // Run
105
        $this->settingRepository->createOrUpdate($data);
106
107
        // Assert
108
        $setting = $this->settingRepository->find(1);
109
        $this->assertEquals('core::locales', $setting->name);
110
        $this->assertEquals('["su","bi","bs"]', $setting->plainValue);
111
    }
112
}
113