|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AccessTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_files\Access\CompositeAdapter; |
|
8
|
|
|
use kalanis\kw_files\Interfaces\IProcessNodes; |
|
9
|
|
|
use kalanis\kw_files\Processing as original_processing; |
|
10
|
|
|
use kalanis\kw_files_mapper\Processing; |
|
11
|
|
|
use kalanis\kw_files_mapper\Access\Factory; |
|
12
|
|
|
use kalanis\kw_files\FilesException; |
|
13
|
|
|
use kalanis\kw_files_mapper\Support\Process; |
|
14
|
|
|
use kalanis\kw_mapper\Interfaces\IEntryType; |
|
15
|
|
|
use kalanis\kw_mapper\MapperException; |
|
16
|
|
|
use kalanis\kw_mapper\Mappers; |
|
17
|
|
|
use kalanis\kw_mapper\Records\ASimpleRecord; |
|
18
|
|
|
use kalanis\kw_paths\PathsException; |
|
19
|
|
|
use kalanis\kw_storage\Storage\Key\DefaultKey; |
|
20
|
|
|
use kalanis\kw_storage\Storage\Storage; |
|
21
|
|
|
use kalanis\kw_storage\Storage\Target\Memory; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class FactoryTest extends CommonTestClass |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @param $param |
|
28
|
|
|
* @throws FilesException |
|
29
|
|
|
* @throws PathsException |
|
30
|
|
|
* @dataProvider passProvider |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testPass($param): void |
|
33
|
|
|
{ |
|
34
|
|
|
$lib = new Factory(); |
|
35
|
|
|
$this->assertInstanceOf(CompositeAdapter::class, $lib->getClass($param)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function passProvider(): array |
|
39
|
|
|
{ |
|
40
|
|
|
$storage = new Storage(new DefaultKey(), new Memory()); |
|
41
|
|
|
$composite = new CompositeAdapter( |
|
42
|
|
|
new original_processing\Volume\ProcessNode(), |
|
43
|
|
|
new original_processing\Volume\ProcessDir(), |
|
44
|
|
|
new original_processing\Volume\ProcessFile(), |
|
45
|
|
|
new original_processing\Volume\ProcessFile() |
|
46
|
|
|
); |
|
47
|
|
|
return [ |
|
48
|
|
|
['somewhere'], |
|
49
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'tree'], |
|
50
|
|
|
[['path' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'tree']], |
|
51
|
|
|
[['source' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'tree']], |
|
52
|
|
|
[$composite], |
|
53
|
|
|
[$storage], |
|
54
|
|
|
[new XSrc()], |
|
55
|
|
|
[['source' => $composite]], |
|
56
|
|
|
[['source' => $storage]], |
|
57
|
|
|
[['source' => $storage, 'translate' => new XTr()]], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @throws FilesException |
|
63
|
|
|
* @throws MapperException |
|
64
|
|
|
* @throws PathsException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testPassExtra(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$lib = new Factory(); |
|
69
|
|
|
$adapt = $lib->getClass(['source' => new XSrc(), 'translate' => new XTr(), ]); |
|
70
|
|
|
$this->assertInstanceOf(Processing\Mapper\ProcessDir::class, $adapt->getDir()); |
|
71
|
|
|
$this->assertInstanceOf(Processing\Mapper\ProcessFile::class, $adapt->getFile()); |
|
72
|
|
|
$this->assertInstanceOf(Processing\Mapper\ProcessNode::class, $adapt->getNode()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param mixed $param |
|
77
|
|
|
* @throws PathsException |
|
78
|
|
|
* @throws FilesException |
|
79
|
|
|
* @dataProvider failProvider |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testFail($param): void |
|
82
|
|
|
{ |
|
83
|
|
|
$lib = new Factory(); |
|
84
|
|
|
$this->expectException(FilesException::class); |
|
85
|
|
|
$lib->getClass($param); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function failProvider(): array |
|
89
|
|
|
{ |
|
90
|
|
|
return [ |
|
91
|
|
|
[true], |
|
92
|
|
|
[false], |
|
93
|
|
|
[null], |
|
94
|
|
|
[new \stdClass()], |
|
95
|
|
|
[['what' => 'irrelevant']], |
|
96
|
|
|
[['path' => []]], |
|
97
|
|
|
[['path' => null]], |
|
98
|
|
|
[['path' => new \stdClass()]], |
|
99
|
|
|
[['source' => []]], |
|
100
|
|
|
[['source' => null]], |
|
101
|
|
|
[['source' => new \stdClass()]], |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
class XSrc extends ASimpleRecord |
|
108
|
|
|
{ |
|
109
|
|
|
protected function addEntries(): void |
|
110
|
|
|
{ |
|
111
|
|
|
$this->addEntry('name', IEntryType::TYPE_STRING, 256); |
|
112
|
|
|
$this->addEntry('content', IEntryType::TYPE_STRING, 65536); |
|
113
|
|
|
$this->addEntry('parentName', IEntryType::TYPE_STRING, 256); |
|
114
|
|
|
$this->setMapper(XSrcMapper::class); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
class XSrcMapper extends Mappers\APreset |
|
120
|
|
|
{ |
|
121
|
|
|
protected function setMap(): void |
|
122
|
|
|
{ |
|
123
|
|
|
$this->setSource('preset'); |
|
124
|
|
|
$this->setRelation('name', 0); |
|
125
|
|
|
$this->setRelation('parentName', 1); |
|
126
|
|
|
$this->setRelation('content', 2); |
|
127
|
|
|
$this->addPrimaryKey('id'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
protected function loadFromStorage(): array |
|
131
|
|
|
{ |
|
132
|
|
|
return [ |
|
133
|
|
|
['', null, IProcessNodes::STORAGE_NODE_KEY], |
|
134
|
|
|
['dum', '', IProcessNodes::STORAGE_NODE_KEY], |
|
135
|
|
|
['cegf', 'dum', IProcessNodes::STORAGE_NODE_KEY], |
|
136
|
|
|
['vdrvda', 'cegf', 'vfddv1234567uhbzgv'], |
|
137
|
|
|
['wstgs', 'dum', 'bgdsdfsdv54321dbxb'], |
|
138
|
|
|
]; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
class XTr extends Process\Translate |
|
144
|
|
|
{ |
|
145
|
|
|
protected string $current = 'name'; |
|
146
|
|
|
protected string $parent = 'parentName'; |
|
147
|
|
|
protected string $primary = 'name'; |
|
148
|
|
|
protected string $content = 'content'; |
|
149
|
|
|
protected ?string $created = null; |
|
150
|
|
|
} |
|
151
|
|
|
|