Skip to content

Commit aa25057

Browse files
committed
Merge remote-tracking branch 'origin/BUG#AC-1486' into GL_Mainline_PR_25112021
2 parents bfc8f9e + 02bacbb commit aa25057

File tree

3 files changed

+189
-2
lines changed

3 files changed

+189
-2
lines changed

app/code/Magento/RemoteStorage/Driver/Adapter/Cache/Generic.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public function deleteFile(string $path): void
168168

169169
/**
170170
* @inheritdoc
171+
* @SuppressWarnings("unused")
171172
*/
172173
public function deleteDir(string $dirname): void
173174
{
@@ -194,7 +195,7 @@ public function getMetadata(string $path): ?array
194195
return null;
195196
}
196197
$meta = $this->serializer->unserialize($meta);
197-
if (!$meta[$path]) {
198+
if (empty($meta[$path])) {
198199
return null;
199200
}
200201
$this->cacheData[$path] = $meta[$path];
@@ -216,7 +217,7 @@ public function flushCache(): void
216217
*
217218
* @param string $json
218219
*/
219-
private function setFromStorage(string $json)
220+
public function setFromStorage(string $json)
220221
{
221222
$this->cacheData = array_merge($this->cacheData, $this->serializer->unserialize($json));
222223
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\RemoteStorage\Test\Unit\Driver\Adpater\Cache;
8+
9+
use Magento\Framework\App\CacheInterface;
10+
use Magento\Framework\Serialize\SerializerInterface;
11+
use Magento\RemoteStorage\Driver\Adapter\Cache\Generic;
12+
use Magento\RemoteStorage\Driver\Adapter\PathUtil;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* @see Generic
18+
*/
19+
class GenericTest extends TestCase
20+
{
21+
/**
22+
* @var Generic
23+
*/
24+
private Generic $generic;
25+
26+
/**
27+
* @var CacheInterface|MockObject
28+
*/
29+
private CacheInterface $cacheAdapterMock;
30+
31+
/**
32+
* @var SerializerInterface|MockObject
33+
*/
34+
private SerializerInterface $serializerMock;
35+
36+
/**
37+
* @var PathUtil|MockObject
38+
*/
39+
private PathUtil $pathUtilMock;
40+
41+
protected function setUp(): void
42+
{
43+
$this->cacheAdapterMock = $this->createMock(CacheInterface::class);
44+
$this->serializerMock = $this->createMock(SerializerInterface::class);
45+
$this->pathUtilMock = $this->createMock(PathUtil::class);
46+
47+
$this->generic = new Generic(
48+
$this->cacheAdapterMock,
49+
$this->serializerMock,
50+
$this->pathUtilMock
51+
);
52+
}
53+
54+
/**
55+
* @param string $input
56+
* @param array|null $expectedOutput
57+
* @dataProvider metaDataProvider
58+
*/
59+
public function testGetMetaData(string $input, ?array $expectedOutput): void
60+
{
61+
$cacheData = include __DIR__ . '/_files/CacheData.php';
62+
$this->serializerMock
63+
->method('unserialize')
64+
->willReturn($cacheData);
65+
$this->generic->setFromStorage(json_encode($cacheData));
66+
67+
$this->assertEquals($expectedOutput, $this->generic->getMetaData($input));
68+
}
69+
70+
/**
71+
* @return array
72+
*/
73+
public function metaDataProvider(): array
74+
{
75+
return [
76+
[
77+
'media',
78+
[
79+
'path' => 'media',
80+
'dirname' => '.',
81+
'basename' => 'media',
82+
'filename' => 'media',
83+
'type' => 'dir',
84+
'size' => null,
85+
'timestamp' => null,
86+
'visibility' => null,
87+
'mimetype' => '',
88+
],
89+
],
90+
[
91+
'media/tmp/catalog/product/1/test.jpeg',
92+
[
93+
'path' => 'media/tmp/catalog/product/1/test.jpeg',
94+
'dirname' => 'media/tmp/catalog/product/1',
95+
'basename' => 'test.jpeg',
96+
'extension' => 'jpeg',
97+
'filename' => 'test.jpeg',
98+
'type' => 'file',
99+
'size' => '87066',
100+
'timestamp' => '1635860865',
101+
'visibility' => null,
102+
'mimetype' => 'image/jpeg',
103+
'extra' => [
104+
'image-width' => 680,
105+
'image-height' => 383,
106+
],
107+
],
108+
],
109+
[
110+
'media-nonexistent-path',
111+
null,
112+
],
113+
];
114+
}
115+
116+
protected function tearDown(): void
117+
{
118+
unset($this->generic);
119+
unset($this->cacheAdapterMock);
120+
unset($this->serializerMock);
121+
unset($this->pathUtilMock);
122+
}
123+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
return [
8+
'media' => [
9+
'path' => 'media',
10+
'dirname' => '.',
11+
'basename' => 'media',
12+
'filename' => 'media',
13+
'type' => 'dir',
14+
'size' => null,
15+
'timestamp' => null,
16+
'visibility' => null,
17+
'mimetype' => '',
18+
],
19+
'media/tmp' => [
20+
'path' => 'media/tmp',
21+
'dirname' => 'media',
22+
'basename' => 'tmp',
23+
'filename' => 'tmp',
24+
'type' => 'dir',
25+
],
26+
'media/tmp/catalog' => [
27+
'path' => 'media/tmp/catalog',
28+
'dirname' => 'media/tmp',
29+
'basename' => 'catalog',
30+
'filename' => 'catalog',
31+
'type' => 'dir',
32+
],
33+
'media/tmp/catalog/product' => [
34+
'path' => 'media/tmp/catalog/product',
35+
'dirname' => 'media/tmp/catalog',
36+
'basename' => 'product',
37+
'filename' => 'product',
38+
'type' => 'dir',
39+
],
40+
'media/tmp/catalog/product/1' => [
41+
'path' => 'media/tmp/catalog/product/1',
42+
'dirname' => 'media/tmp/catalog/product',
43+
'basename' => '1',
44+
'filename' => '1',
45+
'type' => 'dir',
46+
],
47+
'media/tmp/catalog/product/1/test.jpeg' => [
48+
'path' => 'media/tmp/catalog/product/1/test.jpeg',
49+
'dirname' => 'media/tmp/catalog/product/1',
50+
'basename' => 'test.jpeg',
51+
'extension' => 'jpeg',
52+
'filename' => 'test.jpeg',
53+
'type' => 'file',
54+
'size' => '87066',
55+
'timestamp' => '1635860865',
56+
'visibility' => null,
57+
'mimetype' => 'image/jpeg',
58+
'extra' => [
59+
'image-width' => 680,
60+
'image-height' => 383,
61+
],
62+
],
63+
];

0 commit comments

Comments
 (0)