Skip to content

Commit 71955aa

Browse files
committed
Merge pull request #609 from magento-ogre/PR_Branch
[Ogres] Bug Fixes
2 parents f2a66a4 + 20038e0 commit 71955aa

File tree

16 files changed

+588
-75
lines changed

16 files changed

+588
-75
lines changed

app/code/Magento/Theme/Model/Uploader/Service.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace Magento\Theme\Model\Uploader;
99

10+
use Magento\Framework\Convert\DataSize;
1011
use Magento\Framework\Filesystem;
1112
use Magento\Framework\Filesystem\DirectoryList;
1213

@@ -31,6 +32,13 @@ class Service
3132
*/
3233
protected $_fileSize;
3334

35+
/**
36+
* Data size converter
37+
*
38+
* @var \Magento\Framework\Convert\DataSize
39+
*/
40+
protected $dataSize;
41+
3442
/**
3543
* File uploader
3644
*
@@ -58,18 +66,21 @@ class Service
5866
*
5967
* @param \Magento\Framework\Filesystem $filesystem
6068
* @param \Magento\Framework\File\Size $fileSize
69+
* @param \Magento\Framework\Convert\DataSize $dataSize
6170
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
6271
* @param array $uploadLimits keys are 'css' and 'js' for file type, values defines maximum file size, example: 2M
6372
*/
6473
public function __construct(
6574
\Magento\Framework\Filesystem $filesystem,
6675
\Magento\Framework\File\Size $fileSize,
76+
\Magento\Framework\Convert\DataSize $dataSize,
6777
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
6878
array $uploadLimits = []
6979
) {
7080
$this->_tmpDirectory = $filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
7181
$this->_fileSize = $fileSize;
7282
$this->_uploaderFactory = $uploaderFactory;
83+
$this->dataSize = $dataSize;
7384
if (isset($uploadLimits['css'])) {
7485
$this->_cssUploadLimit = $uploadLimits['css'];
7586
}
@@ -173,7 +184,7 @@ private function _getMaxUploadSize($configuredLimit)
173184
if ($configuredLimit === null) {
174185
return $maxIniUploadSize;
175186
}
176-
$maxUploadSize = $this->_fileSize->convertSizeToInteger($configuredLimit);
187+
$maxUploadSize = $this->dataSize->convertSizeToBytes($configuredLimit);
177188
return min($maxUploadSize, $maxIniUploadSize);
178189
}
179190

app/code/Magento/Theme/Test/Unit/Block/Adminhtml/System/Design/Theme/Tab/CssTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ protected function setUp()
6666
public function testGetUploadCssFileNote()
6767
{
6868
$method = self::getMethod('_getUploadCssFileNote');
69-
/** @var $sizeModel \Magento\Framework\File\Size */
70-
$sizeModel = $this->getMock('Magento\Framework\File\Size', null, [], '', false);
69+
/** @var $sizeModel \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\File\Size */
70+
$sizeModel = $this->getMock('Magento\Framework\File\Size', [], [], '', false);
71+
$sizeModel->expects($this->any())->method('getMaxFileSizeInMb')->willReturn('2M');
7172

7273
$this->_objectManager->expects(
7374
$this->any()

app/code/Magento/Theme/Test/Unit/Model/Uploader/ServiceTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace Magento\Theme\Test\Unit\Model\Uploader;
1111

12+
use Magento\Framework\Convert\DataSize;
13+
1214
class ServiceTest extends \PHPUnit_Framework_TestCase
1315
{
1416
/**
@@ -31,6 +33,11 @@ class ServiceTest extends \PHPUnit_Framework_TestCase
3133
*/
3234
protected $_fileSizeMock;
3335

36+
/**
37+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Convert\DataSize
38+
*/
39+
protected $dataSize;
40+
3441
/**
3542
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem
3643
*/
@@ -49,6 +56,7 @@ class ServiceTest extends \PHPUnit_Framework_TestCase
4956
protected function setUp()
5057
{
5158
$this->_uploader = $this->getMock('Magento\MediaStorage\Model\File\Uploader', [], [], '', false);
59+
$this->dataSize = new DataSize();
5260
$this->_uploaderFactory = $this->getMock(
5361
'Magento\MediaStorage\Model\File\UploaderFactory',
5462
['create'],
@@ -103,6 +111,7 @@ public function testUploadLimitNotConfigured()
103111
$this->_service = new \Magento\Theme\Model\Uploader\Service(
104112
$this->_filesystemMock,
105113
$this->_fileSizeMock,
114+
$this->dataSize,
106115
$this->_uploaderFactory
107116
);
108117
$this->assertEquals(600 * self::MB_MULTIPLIER, $this->_service->getJsUploadMaxSize());
@@ -114,6 +123,7 @@ public function testGetCssUploadMaxSize()
114123
$this->_service = new \Magento\Theme\Model\Uploader\Service(
115124
$this->_filesystemMock,
116125
$this->_fileSizeMock,
126+
$this->dataSize,
117127
$this->_uploaderFactory,
118128
['css' => '5M']
119129
);
@@ -125,6 +135,7 @@ public function testGetJsUploadMaxSize()
125135
$this->_service = new \Magento\Theme\Model\Uploader\Service(
126136
$this->_filesystemMock,
127137
$this->_fileSizeMock,
138+
$this->dataSize,
128139
$this->_uploaderFactory,
129140
['js' => '3M']
130141
);
@@ -158,6 +169,7 @@ public function testGetFileContent()
158169
$this->_service = new \Magento\Theme\Model\Uploader\Service(
159170
$this->_filesystemMock,
160171
$this->_fileSizeMock,
172+
$this->dataSize,
161173
$this->_uploaderFactory,
162174
['js' => '3M']
163175
);
@@ -171,6 +183,7 @@ public function testUploadCssFile()
171183
$this->_service = new \Magento\Theme\Model\Uploader\Service(
172184
$this->_filesystemMock,
173185
$this->_fileSizeMock,
186+
$this->dataSize,
174187
$this->_uploaderFactory,
175188
['css' => '3M']
176189
);
@@ -226,6 +239,7 @@ public function testUploadInvalidCssFile()
226239
$this->_service = new \Magento\Theme\Model\Uploader\Service(
227240
$this->_filesystemMock,
228241
$this->_fileSizeMock,
242+
$this->dataSize,
229243
$this->_uploaderFactory,
230244
['css' => '10M']
231245
);
@@ -248,6 +262,7 @@ public function testUploadJsFile()
248262
$this->_service = new \Magento\Theme\Model\Uploader\Service(
249263
$this->_filesystemMock,
250264
$this->_fileSizeMock,
265+
$this->dataSize,
251266
$this->_uploaderFactory,
252267
['js' => '500M']
253268
);
@@ -296,6 +311,7 @@ public function testUploadInvalidJsFile()
296311
$this->_service = new \Magento\Theme\Model\Uploader\Service(
297312
$this->_filesystemMock,
298313
$this->_fileSizeMock,
314+
$this->dataSize,
299315
$this->_uploaderFactory,
300316
['js' => '100M']
301317
);

dev/tests/integration/testsuite/Magento/Framework/File/SizeTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,4 @@ public function testGetMaxFileSize()
3030
$this->assertGreaterThanOrEqual(0, $this->_fileSize->getMaxFileSize());
3131
$this->assertGreaterThanOrEqual(0, $this->_fileSize->getMaxFileSizeInMb());
3232
}
33-
34-
/**
35-
* @dataProvider getConvertSizeToIntegerDataProvider
36-
* @backupStaticAttributes
37-
* @param string $value
38-
* @param int $expected
39-
*/
40-
public function testConvertSizeToInteger($value, $expected)
41-
{
42-
$this->assertEquals($expected, $this->_fileSize->convertSizeToInteger($value));
43-
}
44-
45-
/**
46-
* @return array
47-
*/
48-
public function getConvertSizeToIntegerDataProvider()
49-
{
50-
return [
51-
['0K', 0],
52-
['123K', 125952],
53-
['1K', 1024],
54-
['1g', 1073741824],
55-
['asdas', 0],
56-
['1M', 1048576]
57-
];
58-
}
5933
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Convert;
8+
9+
/**
10+
* Magento data size converter class
11+
*/
12+
class DataSize
13+
{
14+
/**
15+
* Converts a size value to bytes
16+
* Example input: 100 (bytes), 10K (kilobytes), 13M (megabytes), 2G (gigabytes)
17+
*
18+
* @param string $size
19+
* @return integer
20+
*/
21+
public function convertSizeToBytes($size)
22+
{
23+
if (!is_numeric($size)) {
24+
$type = strtoupper(substr($size, -1));
25+
$size = (int)$size;
26+
27+
switch ($type) {
28+
case 'K':
29+
$size *= 1024;
30+
break;
31+
32+
case 'M':
33+
$size *= 1024 * 1024;
34+
break;
35+
36+
case 'G':
37+
$size *= 1024 * 1024 * 1024;
38+
break;
39+
40+
default:
41+
break;
42+
}
43+
}
44+
return (int)$size;
45+
}
46+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Convert\Test\Unit;
8+
9+
use Magento\Framework\Convert\DataSize;
10+
11+
/**
12+
* Class DataSizeTest
13+
*/
14+
class DataSizeTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var \Magento\Framework\Convert\DataSize
18+
*/
19+
protected $dataSize;
20+
21+
/**
22+
* Setup
23+
*
24+
* @return void
25+
*/
26+
protected function setUp()
27+
{
28+
$this->dataSize = new DataSize();
29+
}
30+
31+
/**
32+
* @dataProvider getConvertSizeToIntegerDataProvider
33+
* @backupStaticAttributes
34+
* @param string $value
35+
* @param int $expected
36+
* @return void
37+
*/
38+
public function testConvertSizeToInteger($value, $expected)
39+
{
40+
$this->assertEquals($expected, $this->dataSize->convertSizeToBytes($value));
41+
}
42+
43+
/**
44+
* @return array
45+
*/
46+
public function getConvertSizeToIntegerDataProvider()
47+
{
48+
return [
49+
['0K', 0],
50+
['123K', 125952],
51+
['1K', 1024],
52+
['1g', 1073741824],
53+
['asdas', 0],
54+
['1M', 1048576]
55+
];
56+
}
57+
}

lib/internal/Magento/Framework/File/Size.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111

1212
class Size
1313
{
14+
/**
15+
* Data size converter
16+
*
17+
* @var \Magento\Framework\Convert\DataSize
18+
*/
19+
private $dataSize;
20+
1421
/**
1522
* Maximum file size for MAX_FILE_SIZE attribute of a form
1623
*
@@ -72,8 +79,8 @@ public function getFileSizeInMb($fileSize, $precision = 0, $mode = PHP_ROUND_HAL
7279
public function getMaxFileSize()
7380
{
7481
if (self::$_maxFileSize < 0) {
75-
$postMaxSize = $this->convertSizeToInteger($this->getPostMaxSize());
76-
$uploadMaxSize = $this->convertSizeToInteger($this->getUploadMaxSize());
82+
$postMaxSize = $this->getDataSize()->convertSizeToBytes($this->getPostMaxSize());
83+
$uploadMaxSize = $this->getDataSize()->convertSizeToBytes($this->getUploadMaxSize());
7784
$min = max($postMaxSize, $uploadMaxSize);
7885

7986
if ($postMaxSize > 0) {
@@ -93,33 +100,14 @@ public function getMaxFileSize()
93100
/**
94101
* Converts a ini setting to a integer value
95102
*
103+
* @deprecated Please use \Magento\Framework\Convert\DataSize
104+
*
96105
* @param string $size
97106
* @return integer
98107
*/
99108
public function convertSizeToInteger($size)
100109
{
101-
if (!is_numeric($size)) {
102-
$type = strtoupper(substr($size, -1));
103-
$size = (int)$size;
104-
105-
switch ($type) {
106-
case 'K':
107-
$size *= 1024;
108-
break;
109-
110-
case 'M':
111-
$size *= 1024 * 1024;
112-
break;
113-
114-
case 'G':
115-
$size *= 1024 * 1024 * 1024;
116-
break;
117-
118-
default:
119-
break;
120-
}
121-
}
122-
return (int)$size;
110+
return $this->getDataSize()->convertSizeToBytes($size);
123111
}
124112

125113
/**
@@ -133,4 +121,21 @@ protected function _iniGet($param)
133121
{
134122
return trim(ini_get($param));
135123
}
124+
125+
/**
126+
* The getter function to get the new dependency for real application code
127+
*
128+
* @return \Magento\Framework\Convert\DataSize
129+
*
130+
* @deprecated
131+
*/
132+
private function getDataSize()
133+
{
134+
if ($this->dataSize === null) {
135+
$this->dataSize =
136+
\Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Convert\DataSize::class);
137+
}
138+
139+
return $this->dataSize;
140+
}
136141
}

setup/pub/magento/setup/readiness-check.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ angular.module('readiness-check', [])
7777
visible: false,
7878
processed: false,
7979
expanded: false,
80-
isRequestError: false
80+
isRequestError: false,
81+
isRequestWarning: false
8182
};
8283
$scope.extensions = {
8384
visible: false,

0 commit comments

Comments
 (0)