1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Orchestra\Testbench\TestCase; |
4
|
|
|
use Epesi\Base\CommonData\Database\Models\CommonData; |
5
|
|
|
use Epesi\Base\CommonData\Database\Models\CommonDataNotFound; |
6
|
|
|
|
7
|
|
|
class CommonDataTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
protected function getEnvironmentSetUp($app) |
10
|
|
|
{ |
11
|
|
|
$app['config']->set('database.default', 'testing'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
protected function getPackageProviders($app) |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
return [ |
17
|
|
|
\Kalnoy\Nestedset\NestedSetServiceProvider::class, |
18
|
|
|
]; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
|
25
|
|
|
$this->loadMigrationsFrom(__DIR__ . '../../src/CommonData/Database/Migrations'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testStoreRetrieve() |
29
|
|
|
{ |
30
|
|
|
// creating - retrieving array |
31
|
|
|
$arrayExpected = ['c' => 'cc', 'b' => 'bb', 'a' => 'aa', ]; |
32
|
|
|
|
33
|
|
|
CommonData::newArray('abc/def', $arrayExpected); |
34
|
|
|
|
35
|
|
|
$arrayActual = CommonData::getArray('abc/def'); |
36
|
|
|
|
37
|
|
|
$this->assertEquals($arrayExpected, $arrayActual, 'Problem retrieving commondata sorted by position!'); |
38
|
|
|
|
39
|
|
|
// retrieving sorted array by key |
40
|
|
|
$arraySortKey = $arrayExpected; |
41
|
|
|
ksort($arraySortKey); |
42
|
|
|
|
43
|
|
|
$this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'key'), 'Problem retrieving commondata sorted by key!'); |
44
|
|
|
|
45
|
|
|
// retrieving sorted array by value |
46
|
|
|
$arraySortValue = $arrayExpected; |
47
|
|
|
sort($arraySortValue); |
48
|
|
|
|
49
|
|
|
$this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'value'), 'Problem retrieving commondata sorted by value!'); |
50
|
|
|
|
51
|
|
|
// retrieving array value |
52
|
|
|
$valueActual = CommonData::getValue('abc/def/a'); |
53
|
|
|
|
54
|
|
|
$this->assertEquals($arrayExpected['a'], $valueActual, 'Problem retrieving commondata value!'); |
55
|
|
|
|
56
|
|
|
// setting array values |
57
|
|
|
$arrayChanged = ['a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc']; |
58
|
|
|
|
59
|
|
|
foreach ($arrayChanged as $key => $value) { |
60
|
|
|
CommonData::setValue('abc/def/' . $key, $value); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$arrayActual = CommonData::getArray('abc/def'); |
64
|
|
|
|
65
|
|
|
$this->assertEquals($arrayChanged, $arrayActual, 'Problem setting commondata value!'); |
66
|
|
|
|
67
|
|
|
// deleting array node |
68
|
|
|
unset($arrayChanged['a']); |
69
|
|
|
|
70
|
|
|
CommonData::deleteArray('abc/def/a'); |
71
|
|
|
|
72
|
|
|
$arrayActual = CommonData::getArray('abc/def'); |
73
|
|
|
|
74
|
|
|
$this->assertEquals($arrayChanged, $arrayActual, 'Problem deleting commondata node!'); |
75
|
|
|
|
76
|
|
|
// extending array |
77
|
|
|
$arrayExtension = ['a' => 'aaa']; |
78
|
|
|
|
79
|
|
|
$arrayChanged = array_merge($arrayChanged, $arrayExtension); |
80
|
|
|
|
81
|
|
|
CommonData::extendArray('abc/def', $arrayExtension); |
82
|
|
|
|
83
|
|
|
$arrayActual = CommonData::getArray('abc/def'); |
84
|
|
|
|
85
|
|
|
$this->assertEquals($arrayChanged, $arrayActual, 'Problem extending commondata array!'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testNonExistingArrayException() |
89
|
|
|
{ |
90
|
|
|
$this->expectException(CommonDataNotFound::class); |
91
|
|
|
|
92
|
|
|
CommonData::getArray('abc/d/ef'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testNonExistingArraySilent() |
96
|
|
|
{ |
97
|
|
|
$this->assertEquals([], CommonData::getArray('abc/d/ef', 'position', true), 'Problem retrieving non-existent commondata array silently!'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testNonExistingValue() |
101
|
|
|
{ |
102
|
|
|
$this->assertFalse(CommonData::getValue('abc/d/ef'), 'Problem retrieving non-existent commondata value!'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.