|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ContentTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_files\Access\Factory; |
|
8
|
|
|
use kalanis\kw_files\Extended\Config; |
|
9
|
|
|
use kalanis\kw_files\FilesException; |
|
10
|
|
|
use kalanis\kw_images\Content\Images; |
|
11
|
|
|
use kalanis\kw_images\Content\ImageSize; |
|
12
|
|
|
use kalanis\kw_images\Graphics; |
|
13
|
|
|
use kalanis\kw_images\Graphics\Format; |
|
14
|
|
|
use kalanis\kw_images\ImagesException; |
|
15
|
|
|
use kalanis\kw_images\Sources; |
|
16
|
|
|
use kalanis\kw_mime\Check\CustomList; |
|
17
|
|
|
use kalanis\kw_mime\MimeException; |
|
18
|
|
|
use kalanis\kw_paths\PathsException; |
|
19
|
|
|
use kalanis\kw_storage\Storage\Key; |
|
20
|
|
|
use kalanis\kw_storage\Storage\Target; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
class ImagesTest extends CommonTestClass |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @throws FilesException |
|
27
|
|
|
* @throws ImagesException |
|
28
|
|
|
* @throws PathsException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testImage(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$tgt = ['testtree', 'testimage.png']; |
|
33
|
|
|
$lib = $this->getLib(); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertEquals($tgt, $lib->reversePath($tgt)); |
|
36
|
|
|
$this->assertFalse($lib->exists($tgt)); |
|
37
|
|
|
$this->assertEmpty($lib->get($tgt)); |
|
38
|
|
|
$this->assertTrue($lib->set($tgt, static::TEST_STRING)); |
|
39
|
|
|
$this->assertTrue($lib->exists($tgt)); |
|
40
|
|
|
$this->assertEquals(static::TEST_STRING, $lib->get($tgt)); |
|
41
|
|
|
$this->assertTrue($lib->remove($tgt)); |
|
42
|
|
|
$this->assertFalse($lib->exists($tgt)); |
|
43
|
|
|
$this->assertEmpty($lib->get($tgt)); |
|
44
|
|
|
$this->assertEmpty($lib->created($tgt)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @throws FilesException |
|
49
|
|
|
* @throws ImagesException |
|
50
|
|
|
* @throws PathsException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testDescription(): void |
|
53
|
|
|
{ |
|
54
|
|
|
$tgt = ['testtree', 'testimage.png']; |
|
55
|
|
|
$lib = $this->getLib(); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals(['testtree', '.txt', 'testimage.png.dsc'], $lib->reverseDescriptionPath($tgt)); |
|
58
|
|
|
$this->assertEmpty($lib->getDescription($tgt)); |
|
59
|
|
|
$this->assertTrue($lib->updateDescription($tgt, static::TEST_STRING)); |
|
60
|
|
|
$this->assertEquals(static::TEST_STRING, $lib->getDescription($tgt)); |
|
61
|
|
|
$this->assertTrue($lib->updateDescription($tgt)); |
|
62
|
|
|
$this->assertEmpty($lib->getDescription($tgt)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @throws FilesException |
|
67
|
|
|
* @throws ImagesException |
|
68
|
|
|
* @throws MimeException |
|
69
|
|
|
* @throws PathsException |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testThumb(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$src = ['testtree', 'testimage.png']; |
|
74
|
|
|
|
|
75
|
|
|
$params = []; |
|
76
|
|
|
$storage = new \kalanis\kw_storage\Storage\Storage(new Key\DefaultKey(), new Target\Memory()); |
|
77
|
|
|
$config = (new Config())->setData($params); |
|
78
|
|
|
$composite = new Factory(); |
|
79
|
|
|
$access = $composite->getClass($storage); |
|
80
|
|
|
|
|
81
|
|
|
$images = new Sources\Image($access, $config); |
|
82
|
|
|
$thumbs = new Sources\Thumb($access, $config); |
|
83
|
|
|
$lib = new Images( |
|
84
|
|
|
new ImageSize( |
|
85
|
|
|
new Graphics(new Graphics\Processor(new Format\Factory()), new CustomList()), |
|
86
|
|
|
(new Graphics\ImageConfig())->setData($params), |
|
87
|
|
|
$images |
|
88
|
|
|
), |
|
89
|
|
|
$images, |
|
90
|
|
|
$thumbs, |
|
91
|
|
|
new Sources\Desc($access, $config) |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertEquals(['testtree', '.tmb', 'testimage.png'], $lib->reverseThumbPath($src)); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertEmpty($lib->getThumb($src)); |
|
97
|
|
|
$this->assertTrue($images->set($src, strval(@file_get_contents($this->targetPath() . DIRECTORY_SEPARATOR . 'testimage.png')))); |
|
98
|
|
|
$this->assertFalse($thumbs->isHere($src)); |
|
99
|
|
|
$this->assertTrue($lib->updateThumb($src)); |
|
100
|
|
|
$this->assertTrue($thumbs->isHere($src)); |
|
101
|
|
|
$this->assertNotEmpty($lib->getThumb($src)); |
|
102
|
|
|
$this->assertTrue($lib->removeThumb($src)); |
|
103
|
|
|
$this->assertFalse($thumbs->isHere($src)); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param array<string, string|int> $params |
|
108
|
|
|
* @throws FilesException |
|
109
|
|
|
* @throws ImagesException |
|
110
|
|
|
* @throws PathsException |
|
111
|
|
|
* @return Images |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function getLib(array $params = []): Images |
|
114
|
|
|
{ |
|
115
|
|
|
$storage = new \kalanis\kw_storage\Storage\Storage(new Key\DefaultKey(), new Target\Memory()); |
|
116
|
|
|
$config = (new Config())->setData($params); |
|
117
|
|
|
$composite = new Factory(); |
|
118
|
|
|
$access = $composite->getClass($storage); |
|
119
|
|
|
|
|
120
|
|
|
return new Images( |
|
121
|
|
|
new ImageSize( |
|
122
|
|
|
new Graphics(new Graphics\Processor(new Format\Factory()), new CustomList()), |
|
123
|
|
|
(new Graphics\ImageConfig())->setData($params), |
|
124
|
|
|
new Sources\Image($access, $config) |
|
125
|
|
|
), |
|
126
|
|
|
new Sources\Image($access, $config), |
|
127
|
|
|
new Sources\Thumb($access, $config), |
|
128
|
|
|
new Sources\Desc($access, $config) |
|
129
|
|
|
); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|