Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — add-span-to-buttons ( b5e4e4...27bfb1 )
by Pedro
28:14
created

testCompactRelationshipSubfields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 15
c 2
b 1
f 1
nc 1
nop 0
dl 0
loc 25
rs 9.7666
1
<?php
2
3
namespace Backpack\CRUD\Tests\Unit\CrudPanel;
4
5
use Backpack\CRUD\Tests\config\Models\Article;
6
use Backpack\CRUD\Tests\config\Models\User;
7
8
/**
9
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\FakeFields
10
 */
11
class CrudPanelFakeFieldsTest extends \Backpack\CRUD\Tests\config\CrudPanel\BaseCrudPanel
12
{
13
    private $fakeFieldsArray = [
14
        [
15
            'name' => 'field',
16
            'label' => 'Normal Field',
17
        ],
18
        [
19
            'name' => 'meta_title',
20
            'label' => 'Meta Title',
21
            'fake' => true,
22
            'store_in' => 'metas',
23
        ],
24
        [
25
            'name' => 'meta_description',
26
            'label' => 'Meta Description',
27
            'fake' => true,
28
            'store_in' => 'metas',
29
        ],
30
        [
31
            'name' => 'meta_keywords',
32
            'label' => 'Meta Keywords',
33
            'fake' => true,
34
            'store_in' => 'metas',
35
        ],
36
        [
37
            'name' => 'tags',
38
            'label' => 'Tags',
39
            'fake' => true,
40
            'store_in' => 'tags',
41
        ],
42
        [
43
            'name' => 'extra_details',
44
            'label' => 'Extra Details',
45
            'fake' => true,
46
        ],
47
        [
48
            'name' => 'cast_meta_title',
49
            'label' => 'Meta Title',
50
            'fake' => true,
51
            'store_in' => 'cast_metas',
52
        ],
53
        [
54
            'name' => 'cast_meta_description',
55
            'label' => 'Meta Description',
56
            'fake' => true,
57
            'store_in' => 'cast_metas',
58
        ],
59
        [
60
            'name' => 'cast_meta_keywords',
61
            'label' => 'Meta Keywords',
62
            'fake' => true,
63
            'store_in' => 'cast_metas',
64
        ],
65
        [
66
            'name' => 'cast_tags',
67
            'label' => 'Tags',
68
            'fake' => true,
69
            'store_in' => 'cast_tags',
70
        ],
71
        [
72
            'name' => 'cast_extra_details',
73
            'label' => 'Extra Details',
74
            'fake' => true,
75
            'store_in' => 'cast_extras',
76
        ],
77
    ];
78
79
    private $noFakeFieldsInputData = [
80
        'value1' => 'Value 1',
81
        'value2' => 'Value 2',
82
        'value3' => 'Value 3',
83
    ];
84
85
    private $fakeFieldsInputData = [
86
        'value1' => 'Value 1',
87
        'value2' => 'Value 2',
88
        'value3' => 'Value 3',
89
        'meta_title' => 'Meta Title Value',
90
        'meta_description' => 'Meta Description Value',
91
        'tags' => ['tag1', 'tag2', 'tag3'],
92
        'extra_details' => ['detail1', 'detail2', 'detail3'],
93
        'cast_meta_title' => 'Meta Title Value',
94
        'cast_meta_description' => 'Meta Description Value',
95
        'cast_tags' => ['tag1', 'tag2', 'tag3'],
96
        'cast_extra_details' => ['detail1', 'detail2', 'detail3'],
97
    ];
98
99
    private $expectedInputDataWithCompactedFakeFields = [
100
        'value1' => 'Value 1',
101
        'value2' => 'Value 2',
102
        'value3' => 'Value 3',
103
        'metas' => '{"meta_title":"Meta Title Value","meta_description":"Meta Description Value"}',
104
        'tags' => '{"tags":["tag1","tag2","tag3"]}',
105
        'extras' => '{"extra_details":["detail1","detail2","detail3"]}',
106
        'cast_metas' => [
107
            'cast_meta_title' => 'Meta Title Value',
108
            'cast_meta_description' => 'Meta Description Value',
109
        ],
110
        'cast_tags' => [
111
            'cast_tags' => ['tag1', 'tag2', 'tag3'],
112
        ],
113
        'cast_extras' => [
114
            'cast_extra_details' => ['detail1', 'detail2', 'detail3'],
115
        ],
116
    ];
117
118
    public function testCompactFakeFieldsFromCreateForm()
119
    {
120
        $this->crudPanel->addFields($this->fakeFieldsArray);
121
        $this->crudPanel->setModel(Article::class);
122
123
        $compactedFakeFields = $this->crudPanel->compactFakeFields($this->fakeFieldsInputData);
124
125
        $this->assertEquals($this->expectedInputDataWithCompactedFakeFields, $compactedFakeFields);
126
    }
127
128
    public function testCompactFakeFieldsFromUpdateForm()
129
    {
130
        $this->crudPanel->setModel(Article::class);
131
        $this->crudPanel->addFields($this->fakeFieldsArray);
132
133
        $compactedFakeFields = $this->crudPanel->compactFakeFields($this->fakeFieldsInputData);
134
135
        $this->assertEquals($this->expectedInputDataWithCompactedFakeFields, $compactedFakeFields);
136
    }
137
138
    public function testCompactFakeFieldsFromUpdateFormWithoutId()
139
    {
140
        $this->crudPanel->setModel(Article::class);
141
        $this->crudPanel->setOperation('update');
142
        $this->crudPanel->addFields($this->fakeFieldsArray);
143
144
        $compactedFakeFields = $this->crudPanel->compactFakeFields($this->fakeFieldsInputData);
145
146
        $this->assertEquals($this->expectedInputDataWithCompactedFakeFields, $compactedFakeFields);
147
    }
148
149
    public function testCompactFakeFieldsFromUpdateFormWithUnknownId()
150
    {
151
        $this->crudPanel->setModel(Article::class);
152
        $this->crudPanel->setOperation('update');
153
        $this->crudPanel->addFields($this->fakeFieldsArray);
154
155
        $compactedFakeFields = $this->crudPanel->compactFakeFields($this->fakeFieldsInputData);
156
157
        $this->assertEquals($this->expectedInputDataWithCompactedFakeFields, $compactedFakeFields);
158
    }
159
160
    public function testCompactFakeFieldsFromEmptyRequest()
161
    {
162
        $compactedFakeFields = $this->crudPanel->compactFakeFields([]);
163
164
        $this->assertEmpty($compactedFakeFields);
165
    }
166
167
    public function testCompactFakeFieldsFromRequestWithNoFakes()
168
    {
169
        $compactedFakeFields = $this->crudPanel->compactFakeFields($this->noFakeFieldsInputData);
170
171
        $this->assertEquals($this->noFakeFieldsInputData, $compactedFakeFields);
172
    }
173
174
    public function testCompactRelationshipSubfields()
175
    {
176
        $this->crudPanel->setModel(User::class);
177
        $this->crudPanel->addField([
178
            'name' => 'articles',
179
            'subfields' => [
180
                [
181
                    'name' => 'content',
182
                    'fake' => true,
183
                ],
184
                [
185
                    'name' => 'metas',
186
                    'fake' => true,
187
                ],
188
            ],
189
        ]);
190
191
        $compactedFakeFields = $this->crudPanel->compactFakeFields([
192
            'content' => 'Content Value',
193
            'metas' => ['meta1', 'meta2', 'meta3'],
194
        ], Article::class);
195
196
        $this->assertEquals([
197
            'extras' => '{"content":"Content Value","metas":["meta1","meta2","meta3"]}',
198
        ], $compactedFakeFields);
199
    }
200
}
201