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