1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ProcessingTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_menu\MetaProcessor; |
7
|
|
|
use kalanis\kw_menu\MetaSource; |
8
|
|
|
use kalanis\kw_menu\MenuException; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class MetaProcessorTest extends \CommonTestClass |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @throws MenuException |
15
|
|
|
*/ |
16
|
|
|
public function testMenu(): void |
17
|
|
|
{ |
18
|
|
|
$lib = $this->getLib(); |
19
|
|
|
$lib->setKey(['target.meta']); |
20
|
|
|
$this->assertTrue($lib->exists()); |
21
|
|
|
$this->assertNotEmpty($lib->getMenu()); |
22
|
|
|
$this->assertEmpty($lib->getWorking()); |
23
|
|
|
$lib->load(); |
24
|
|
|
$this->assertNotEmpty($lib->getWorking()); |
25
|
|
|
$lib->setKey(['copy.meta']); |
26
|
|
|
$lib->updateInfo('another target', 'another testing', null); // metadata info |
27
|
|
|
$lib->addEntry('other1.htm', 'ijn', 'uhb', true); |
28
|
|
|
$lib->updateEntry('dummy3.htm', 'edc', 'rfv', false); // entry info |
29
|
|
|
$lib->updateEntry('dummy4.htm', null, 'more lines' . PHP_EOL . 'than | it' . "\r\n" . 'worth', false); // entry info |
30
|
|
|
$lib->removeEntry('dummy2.htm'); |
31
|
|
|
$lib->clearData(); |
32
|
|
|
$lib->save(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @throws MenuException |
37
|
|
|
*/ |
38
|
|
|
public function testPositions(): void |
39
|
|
|
{ |
40
|
|
|
$lib = $this->getLib(); |
41
|
|
|
$lib->setKey(['target.meta']); |
42
|
|
|
$this->assertTrue($lib->exists()); |
43
|
|
|
$lib->load(); |
44
|
|
|
$lib->setKey(['copy.meta']); |
45
|
|
|
$lib->rearrangePositions([ // file => new position |
46
|
|
|
'dummy4.htm' => 3, |
47
|
|
|
'dummy2.htm' => 4, |
48
|
|
|
]); |
49
|
|
|
$lib->clearData(); |
50
|
|
|
$lib->save(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @throws MenuException |
55
|
|
|
*/ |
56
|
|
|
public function testNotEntry(): void |
57
|
|
|
{ |
58
|
|
|
$lib = $this->getLib(); |
59
|
|
|
$lib->setKey(['target.meta']); |
60
|
|
|
$this->assertTrue($lib->exists()); |
61
|
|
|
$lib->load(); |
62
|
|
|
$this->expectException(MenuException::class); |
63
|
|
|
$lib->updateEntry('not-a-file', 'no-save', 'nope', false); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Try to rearrange empty settings |
68
|
|
|
* @throws MenuException |
69
|
|
|
*/ |
70
|
|
|
public function testNotPositions(): void |
71
|
|
|
{ |
72
|
|
|
$lib = $this->getLib(); |
73
|
|
|
$lib->setKey(['target.meta']); |
74
|
|
|
$this->assertTrue($lib->exists()); |
75
|
|
|
$lib->load(); |
76
|
|
|
$this->expectException(MenuException::class); |
77
|
|
|
$lib->rearrangePositions([]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Try to rearrange meta file which has not been loaded here |
82
|
|
|
* @throws MenuException |
83
|
|
|
*/ |
84
|
|
|
public function testNotPositionsItems(): void |
85
|
|
|
{ |
86
|
|
|
$lib = $this->getLib(); |
87
|
|
|
$lib->setKey(['not-a-file']); |
88
|
|
|
$this->assertFalse($lib->exists()); |
89
|
|
|
$this->expectException(MenuException::class); |
90
|
|
|
$lib->rearrangePositions([1 => 3, 2 => 4]); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Try to rearrange meta file which has set string, not number |
95
|
|
|
* @throws MenuException |
96
|
|
|
*/ |
97
|
|
|
public function testNotPositionsData(): void |
98
|
|
|
{ |
99
|
|
|
$lib = $this->getLib(); |
100
|
|
|
$lib->setKey(['target.meta']); |
101
|
|
|
$this->assertTrue($lib->exists()); |
102
|
|
|
$lib->load(); |
103
|
|
|
$this->expectException(MenuException::class); |
104
|
|
|
$lib->rearrangePositions([ |
105
|
|
|
'dummy4.htm' => 'fail-there', |
106
|
|
|
]); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
protected function getLib() |
110
|
|
|
{ |
111
|
|
|
return new MetaProcessor(new MetaSource\Volume($this->getTargetPath(), new MetaSource\FileParser())); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|