1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudTrait; |
4
|
|
|
|
5
|
|
|
use Unit\CrudPanel\Models\FakeColumnsModel; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class CrudTraitFakeFieldsTest. |
9
|
|
|
* |
10
|
|
|
* @group CrudTraitFakeFields |
11
|
|
|
*/ |
12
|
|
|
class CrudTraitFakeFieldsTest extends BaseCrudTraitTest |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
private $locale; |
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var FakeColumnsModel |
17
|
|
|
*/ |
18
|
|
|
private $model; |
19
|
|
|
|
20
|
|
|
// DEFINE THE DATA |
21
|
|
|
|
22
|
|
|
private $extras = [ |
23
|
|
|
'extras_first' => 'Extras first', |
24
|
|
|
'extras_second' => 'Extras second', |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
private $extras_translatable = [ |
28
|
|
|
'en' => [ |
29
|
|
|
'extras_translatable_first' => 'extras_translatable first en', |
30
|
|
|
'extras_translatable_second' => 'extras_translatable second en', |
31
|
|
|
], |
32
|
|
|
'ro' => [ |
33
|
|
|
'extras_translatable_first' => 'extras_translatable first ro', |
34
|
|
|
'extras_translatable_second' => 'extras_translatable second ro', |
35
|
|
|
], |
36
|
|
|
|
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
private $fake_object = [ |
40
|
|
|
'fake_object_first' => 'fake_object first', |
41
|
|
|
'fake_object_second' => 'fake_object second', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
private $fake_assoc_array = [ |
45
|
|
|
'fake_assoc_array_first' => 'fake_assoc_array first', |
46
|
|
|
'fake_assoc_array_second' => 'fake_assoc_array second', |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Setup function for each test. |
51
|
|
|
*/ |
52
|
|
|
protected function setUp() |
53
|
|
|
{ |
54
|
|
|
parent::setUp(); |
55
|
|
|
|
56
|
|
|
$this->locale = \App::getLocale(); |
57
|
|
|
|
58
|
|
|
$this->fake_object = (object) $this->fake_object; |
59
|
|
|
|
60
|
|
|
$this->model = new FakeColumnsModel(); |
61
|
|
|
|
62
|
|
|
$this->model->extras = json_encode($this->extras); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$this->model->setTranslation('extras_translatable', 'en', json_encode($this->extras_translatable['en'])); |
65
|
|
|
$this->model->setTranslation('extras_translatable', 'ro', json_encode($this->extras_translatable['ro'])); |
66
|
|
|
|
67
|
|
|
$this->model->fake_object = $this->fake_object; |
|
|
|
|
68
|
|
|
$this->model->fake_assoc_array = $this->fake_assoc_array; |
|
|
|
|
69
|
|
|
|
70
|
|
|
$this->model = $this->model->withFakes(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testExtrasGetFaked() |
74
|
|
|
{ |
75
|
|
|
$this->assertEquals($this->extras, json_decode($this->model->extras, true)); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$this->assertEquals($this->extras['extras_first'], $this->model->extras_first); |
|
|
|
|
78
|
|
|
$this->assertEquals($this->extras['extras_second'], $this->model->extras_second); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testExtrasTranslatableGetFaked() |
82
|
|
|
{ |
83
|
|
|
$this->assertEquals($this->extras_translatable[$this->locale], json_decode($this->model->extras_translatable, true)); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$this->assertEquals($this->extras_translatable[$this->locale]['extras_translatable_first'], $this->model->extras_translatable_first); |
|
|
|
|
86
|
|
|
$this->assertEquals($this->extras_translatable[$this->locale]['extras_translatable_second'], $this->model->extras_translatable_second); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testFakeObjectGetsFaked() |
90
|
|
|
{ |
91
|
|
|
$this->assertEquals($this->fake_object, $this->model->fake_object); |
|
|
|
|
92
|
|
|
|
93
|
|
|
$this->assertEquals($this->fake_object->fake_object_first, $this->model->fake_object->fake_object_first); |
|
|
|
|
94
|
|
|
$this->assertEquals($this->fake_object->fake_object_first, $this->model->fake_object_first); |
|
|
|
|
95
|
|
|
|
96
|
|
|
$this->assertEquals($this->fake_object->fake_object_second, $this->model->fake_object->fake_object_second); |
|
|
|
|
97
|
|
|
$this->assertEquals($this->fake_object->fake_object_second, $this->model->fake_object_second); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testFakeAssocArrayGetsFaked() |
101
|
|
|
{ |
102
|
|
|
$this->assertEquals($this->fake_assoc_array, $this->model->fake_assoc_array); |
|
|
|
|
103
|
|
|
|
104
|
|
|
$this->assertEquals($this->fake_assoc_array['fake_assoc_array_first'], $this->model->fake_assoc_array['fake_assoc_array_first']); |
|
|
|
|
105
|
|
|
$this->assertEquals($this->fake_assoc_array['fake_assoc_array_first'], $this->model->fake_assoc_array_first); |
|
|
|
|
106
|
|
|
|
107
|
|
|
$this->assertEquals($this->fake_assoc_array['fake_assoc_array_second'], $this->model->fake_assoc_array['fake_assoc_array_second']); |
|
|
|
|
108
|
|
|
$this->assertEquals($this->fake_assoc_array['fake_assoc_array_second'], $this->model->fake_assoc_array_second); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.