Skip to content

Commit 259e16d

Browse files
authored
ENGCOM-7196: {ASI} :- Image size is not passed to image-uploader when inserting an image from new media gallery #27388
2 parents a6332d6 + 60ac99c commit 259e16d

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

app/code/Magento/MediaGallery/Model/Asset.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Asset extends AbstractExtensibleModel implements AssetInterface
2424
private const CONTENT_TYPE = 'content_type';
2525
private const WIDTH = 'width';
2626
private const HEIGHT = 'height';
27+
private const SIZE = 'size';
2728
private const CREATED_AT = 'created_at';
2829
private const UPDATED_AT = 'updated_at';
2930

@@ -89,6 +90,14 @@ public function getHeight(): int
8990
return (int) $this->getData(self::HEIGHT);
9091
}
9192

93+
/**
94+
* @inheritdoc
95+
*/
96+
public function getSize(): int
97+
{
98+
return (int) $this->getData(self::SIZE);
99+
}
100+
92101
/**
93102
* @inheritdoc
94103
*/

app/code/Magento/MediaGallery/Test/Unit/Model/DataExtractorTest.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1111
use Magento\MediaGallery\Model\Asset;
12+
use Magento\MediaGallery\Model\DataExtractor;
1213
use Magento\MediaGallery\Model\Keyword;
1314
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
14-
use Magento\MediaGalleryApi\Api\Data\KeywordInterface;
15-
use Magento\MediaGallery\Model\DataExtractor;
1615
use PHPUnit\Framework\MockObject\MockObject;
1716
use PHPUnit\Framework\TestCase;
1817

@@ -54,22 +53,41 @@ public function testExtractData(string $class, $interfaceClass, array $expectedD
5453
'data' => $data,
5554
]
5655
);
57-
$receivedData = $this->dataExtractor->extract($model, $interfaceClass);
58-
$this->checkValues($expectedData, $receivedData, $model);
56+
if ($interfaceClass) {
57+
$receivedData = $this->dataExtractor->extract($model, $interfaceClass);
58+
$this->checkAssetValues($expectedData, $receivedData, $model);
59+
} else {
60+
$receivedData = $this->dataExtractor->extract($model);
61+
$this->checkKeyWordValues($expectedData, $receivedData, $model);
62+
}
63+
}
64+
65+
/**
66+
* @param array $expectedData
67+
* @param array $data
68+
* @param object $model
69+
*/
70+
private function checkAssetValues(array $expectedData, array $data, $model)
71+
{
72+
foreach ($expectedData as $expectedDataKey => $expectedDataItem) {
73+
$this->assertEquals($data[$expectedDataKey] ?? null, $model->{$expectedDataItem['method']}());
74+
$this->assertEquals($data[$expectedDataKey] ?? null, $expectedDataItem['value']);
75+
}
76+
$this->assertEquals(array_keys($expectedData), array_keys($data));
5977
}
6078

6179
/**
6280
* @param array $expectedData
6381
* @param array $data
6482
* @param object $model
6583
*/
66-
protected function checkValues(array $expectedData, array $data, $model)
84+
private function checkKeyWordValues(array $expectedData, array $data, $model)
6785
{
6886
foreach ($expectedData as $expectedDataKey => $expectedDataItem) {
6987
$this->assertEquals($data[$expectedDataKey] ?? null, $model->{$expectedDataItem['method']}());
7088
$this->assertEquals($data[$expectedDataKey] ?? null, $expectedDataItem['value']);
7189
}
72-
$this->assertEquals(array_keys($expectedData), array_keys($expectedData));
90+
$this->assertEquals(array_keys($expectedData), array_keys(array_slice($data, 0, 2)));
7391
}
7492

7593
/**
@@ -102,13 +120,17 @@ public function assetProvider()
102120
'value' => 'content_type',
103121
'method' => 'getContentType',
104122
],
123+
'height' => [
124+
'value' => 4,
125+
'method' => 'getHeight',
126+
],
105127
'width' => [
106128
'value' => 3,
107129
'method' => 'getWidth',
108130
],
109-
'height' => [
110-
'value' => 4,
111-
'method' => 'getHeight',
131+
'size' => [
132+
'value' => 300,
133+
'method' => 'getSize',
112134
],
113135
'created_at' => [
114136
'value' => '2019-11-28 10:40:09',
@@ -122,7 +144,7 @@ public function assetProvider()
122144
],
123145
'Keyword conversion without interface' => [
124146
Keyword::class,
125-
null,
147+
'',
126148
[
127149
'id' => [
128150
'value' => 2,

app/code/Magento/MediaGallery/etc/db_schema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<column xsi:type="varchar" name="content_type" length="255" nullable="true" comment="Content Type"/>
1515
<column xsi:type="int" name="width" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Width"/>
1616
<column xsi:type="int" name="height" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Height"/>
17+
<column xsi:type="int" name="size" padding="10" unsigned="true" nullable="false" identity="false" comment="Asset file size in bytes"/>
1718
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
1819
<column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
1920
<constraint xsi:type="primary" referenceId="PRIMARY">

app/code/Magento/MediaGallery/etc/db_schema_whitelist.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"content_type": true,
99
"width": true,
1010
"height": true,
11+
"size": true,
1112
"created_at": true,
1213
"updated_at": true
1314
},
@@ -53,4 +54,4 @@
5354
"MEDIA_GALLERY_ASSET_KEYWORD_ASSET_ID_MEDIA_GALLERY_ASSET_ID": true
5455
}
5556
}
56-
}
57+
}

app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public function getHeight(): int;
6565
*/
6666
public function getWidth(): int;
6767

68+
/**
69+
* Retrieve asset file size in bytes
70+
*
71+
* @return int
72+
*/
73+
public function getSize(): int;
74+
6875
/**
6976
* Get created at
7077
*

0 commit comments

Comments
 (0)