|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MetaSourceTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_menu\Menu\Menu; |
|
7
|
|
|
use kalanis\kw_menu\MetaSource; |
|
8
|
|
|
use kalanis\kw_menu\MenuException; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class VolumeTest extends \CommonTestClass |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @throws MenuException |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testProcess(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$lib = $this->getLib(); |
|
19
|
|
|
$lib->setSource(['not-a-file']); |
|
20
|
|
|
$this->assertFalse($lib->exists()); |
|
21
|
|
|
$lib->setSource(['target.meta']); |
|
22
|
|
|
$this->assertTrue($lib->exists()); |
|
23
|
|
|
$content = $lib->load(); |
|
24
|
|
|
$this->assertNotEmpty($content); |
|
25
|
|
|
$lib->setSource(['copy.meta']); |
|
26
|
|
|
$this->assertTrue($lib->save($content)); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @throws MenuException |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testCannotRead(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$lib = $this->getLib(); |
|
35
|
|
|
$lib->setSource(['unable.meta']); |
|
36
|
|
|
chmod($this->getTargetPath() . 'unable.meta', 0222); |
|
37
|
|
|
$this->expectException(MenuException::class); |
|
38
|
|
|
$lib->load(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @throws MenuException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testCannotWrite(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$lib = $this->getLib(); |
|
47
|
|
|
$lib->setSource(['unable.meta']); |
|
48
|
|
|
chmod($this->getTargetPath() . 'unable.meta', 0444); |
|
49
|
|
|
$this->expectException(MenuException::class); |
|
50
|
|
|
$lib->save(new Menu()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @throws MenuException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testFailExists(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$lib = $this->getLibFailing(); |
|
59
|
|
|
$lib->setSource(['target.meta']); |
|
60
|
|
|
$this->expectException(MenuException::class); |
|
61
|
|
|
$lib->exists(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @throws MenuException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testFailLoad(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$lib = $this->getLibFailing(); |
|
70
|
|
|
$lib->setSource(['target.meta']); |
|
71
|
|
|
$this->expectException(MenuException::class); |
|
72
|
|
|
$lib->load(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @throws MenuException |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testFailSave(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$lib = $this->getLibFailing(); |
|
81
|
|
|
$lib->setSource(['target.meta']); |
|
82
|
|
|
$this->expectException(MenuException::class); |
|
83
|
|
|
$lib->save(new Menu()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function getLib(): MetaSource\Volume |
|
87
|
|
|
{ |
|
88
|
|
|
return new MetaSource\Volume($this->getTargetPath(), new MetaSource\FileParser()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
protected function getLibFailing(): MetaSource\Volume |
|
92
|
|
|
{ |
|
93
|
|
|
return new XVolume($this->getTargetPath(), new MetaSource\FileParser()); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
class XVolume extends MetaSource\Volume |
|
99
|
|
|
{ |
|
100
|
|
|
protected function systemDelimiter(): string |
|
101
|
|
|
{ |
|
102
|
|
|
return ''; |
|
103
|
|
|
} |
|
104
|
|
|
} |