1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ContentTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_files\Extended\Config; |
8
|
|
|
use kalanis\kw_files\FilesException; |
9
|
|
|
use kalanis\kw_files\Processing\Storage; |
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\MimeType; |
17
|
|
|
use kalanis\kw_storage\Storage\Key; |
18
|
|
|
use kalanis\kw_storage\Storage\Target; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class ImagesTest extends CommonTestClass |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @throws FilesException |
25
|
|
|
* @throws ImagesException |
26
|
|
|
*/ |
27
|
|
|
public function testImage(): void |
28
|
|
|
{ |
29
|
|
|
$tgt = ['testtree', 'testimage.png']; |
30
|
|
|
$lib = $this->getLib(); |
31
|
|
|
|
32
|
|
|
$this->assertEmpty($lib->get($tgt)); |
33
|
|
|
$this->assertTrue($lib->set($tgt, static::TEST_STRING)); |
34
|
|
|
$this->assertEquals(static::TEST_STRING, $lib->get($tgt)); |
35
|
|
|
$this->assertTrue($lib->remove($tgt)); |
36
|
|
|
$this->assertEmpty($lib->get($tgt)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @throws FilesException |
41
|
|
|
* @throws ImagesException |
42
|
|
|
*/ |
43
|
|
|
public function testDescription(): void |
44
|
|
|
{ |
45
|
|
|
$tgt = ['testtree', 'testimage.png']; |
46
|
|
|
$lib = $this->getLib(); |
47
|
|
|
|
48
|
|
|
$this->assertEmpty($lib->getDescription($tgt)); |
49
|
|
|
$this->assertTrue($lib->updateDescription($tgt, static::TEST_STRING)); |
50
|
|
|
$this->assertEquals(static::TEST_STRING, $lib->getDescription($tgt)); |
51
|
|
|
$this->assertTrue($lib->updateDescription($tgt)); |
52
|
|
|
$this->assertEmpty($lib->getDescription($tgt)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws FilesException |
57
|
|
|
* @throws ImagesException |
58
|
|
|
*/ |
59
|
|
|
public function testThumb(): void |
60
|
|
|
{ |
61
|
|
|
$src = ['testtree', 'testimage.png']; |
62
|
|
|
|
63
|
|
|
$params = []; |
64
|
|
|
$storage = new \kalanis\kw_storage\Storage\Storage(new Key\DefaultKey(), new Target\Memory()); |
65
|
|
|
$nodes = new Storage\ProcessNode($storage); |
66
|
|
|
$files = new Storage\ProcessFile($storage); |
67
|
|
|
$config = (new Config())->setData($params); |
68
|
|
|
|
69
|
|
|
$images = new Sources\Image($nodes, $files, $config); |
70
|
|
|
$thumbs = new Sources\Thumb($nodes, $files, $config); |
71
|
|
|
$lib = new Images( |
72
|
|
|
new ImageSize( |
73
|
|
|
new Graphics(new Graphics\Processor(new Format\Factory()), new MimeType(true)), |
74
|
|
|
(new Graphics\ImageConfig())->setData($params), |
75
|
|
|
$images |
76
|
|
|
), |
77
|
|
|
$images, |
78
|
|
|
$thumbs, |
79
|
|
|
new Sources\Desc($nodes, $files, $config) |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$this->assertEmpty($lib->getThumb($src)); |
83
|
|
|
$this->assertTrue($images->set($src, strval(@file_get_contents($this->targetPath() . DIRECTORY_SEPARATOR . 'testimage.png')))); |
84
|
|
|
$this->assertFalse($thumbs->isHere($src)); |
85
|
|
|
$this->assertTrue($lib->updateThumb($src)); |
86
|
|
|
$this->assertTrue($thumbs->isHere($src)); |
87
|
|
|
$this->assertNotEmpty($lib->getThumb($src)); |
88
|
|
|
$this->assertTrue($lib->removeThumb($src)); |
89
|
|
|
$this->assertFalse($thumbs->isHere($src)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param array<string, string|int> $params |
94
|
|
|
* @param Sources\Image|null $image |
95
|
|
|
* @throws ImagesException |
96
|
|
|
* @return Images |
97
|
|
|
*/ |
98
|
|
|
protected function getLib(array $params = []): Images |
99
|
|
|
{ |
100
|
|
|
$storage = new \kalanis\kw_storage\Storage\Storage(new Key\DefaultKey(), new Target\Memory()); |
101
|
|
|
$nodes = new Storage\ProcessNode($storage); |
102
|
|
|
$files = new Storage\ProcessFile($storage); |
103
|
|
|
$config = (new Config())->setData($params); |
104
|
|
|
|
105
|
|
|
return new Images( |
106
|
|
|
new ImageSize( |
107
|
|
|
new Graphics(new Graphics\Processor(new Format\Factory()), new MimeType(true)), |
108
|
|
|
(new Graphics\ImageConfig())->setData($params), |
109
|
|
|
new Sources\Image($nodes, $files, $config) |
110
|
|
|
), |
111
|
|
|
new Sources\Image($nodes, $files, $config), |
112
|
|
|
new Sources\Thumb($nodes, $files, $config), |
113
|
|
|
new Sources\Desc($nodes, $files, $config) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|