|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MapperTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_files\Interfaces\IFLTranslations; |
|
7
|
|
|
use kalanis\kw_files\Traits\TLang; |
|
8
|
|
|
use kalanis\kw_files_mapper\Processing\Mapper\TEntryLookup; |
|
9
|
|
|
use kalanis\kw_files_mapper\Support\Process; |
|
10
|
|
|
use kalanis\kw_mapper\MapperException; |
|
11
|
|
|
use kalanis\kw_mapper\Records\ARecord; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class EntryLookupTest extends AStorageTest |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @throws MapperException |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testSimple(): void |
|
20
|
|
|
{ |
|
21
|
|
|
if ($this->skipIt) { |
|
22
|
|
|
$this->markTestSkipped('Skipped by config'); |
|
23
|
|
|
return; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$this->dataRefill(); |
|
27
|
|
|
|
|
28
|
|
|
$lib = $this->getLookupLib(); |
|
29
|
|
|
$this->assertNotEmpty($lib->look([])); |
|
30
|
|
|
$this->assertNotEmpty($lib->look(['sub'])); |
|
31
|
|
|
$this->assertNotEmpty($lib->look(['next_one', 'sub_one'])); |
|
32
|
|
|
$this->assertEmpty($lib->look(['unknown'])); |
|
33
|
|
|
$this->assertEmpty($lib->look(['sub', 'unknown'])); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws MapperException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testDeeper(): void |
|
40
|
|
|
{ |
|
41
|
|
|
if ($this->skipIt) { |
|
42
|
|
|
$this->markTestSkipped('Skipped by config'); |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->dataRefill(); |
|
47
|
|
|
|
|
48
|
|
|
$lib = $this->getLookupLib(); |
|
49
|
|
|
$rec = $lib->look(['sub']); |
|
50
|
|
|
$this->assertNotEmpty($rec); |
|
51
|
|
|
$this->assertNotEmpty($lib->look(['dummy3.txt'], $rec)); |
|
52
|
|
|
$this->assertEmpty($lib->look(['unknown'], $rec)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function getLookupLib(): XLookup |
|
56
|
|
|
{ |
|
57
|
|
|
return new XLookup(new SQLiteTestRecord()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
class XLookup |
|
63
|
|
|
{ |
|
64
|
|
|
use TEntryLookup; |
|
65
|
|
|
use TLang; |
|
66
|
|
|
|
|
67
|
|
|
protected ARecord $record; |
|
68
|
|
|
protected Process\Translate $translate; |
|
69
|
|
|
|
|
70
|
|
|
public function __construct(ARecord $record, ?Process\Translate $translate = null, ?IFLTranslations $lang = null) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->setFlLang($lang); |
|
73
|
|
|
$this->record = $record; |
|
74
|
|
|
$this->translate = $translate ?: new Process\Translate(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string[] $path |
|
79
|
|
|
* @param ARecord|null $parentNode |
|
80
|
|
|
* @throws MapperException |
|
81
|
|
|
* @return ARecord|null |
|
82
|
|
|
*/ |
|
83
|
|
|
public function look(array $path, ?ARecord $parentNode = null): ?ARecord |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->getEntry($path, $parentNode); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function getLookupRecord(): ARecord |
|
89
|
|
|
{ |
|
90
|
|
|
return clone $this->record; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function getTranslation(): Process\Translate |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->translate; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|