Skip to content

Commit d53c7ca

Browse files
author
Hwashiang Yu
committed
MC-31362: Media folder update
- Fixed missed unit test mock data
1 parent 09470aa commit d53c7ca

File tree

1 file changed

+38
-16
lines changed
  • app/code/Magento/Theme/Test/Unit/Model/Design/Backend

1 file changed

+38
-16
lines changed

app/code/Magento/Theme/Test/Unit/Model/Design/Backend/ImageTest.php

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88

99
namespace Magento\Theme\Test\Unit\Model\Design\Backend;
1010

11+
use Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface;
12+
use Magento\Framework\App\Cache\TypeListInterface;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\Data\Collection\AbstractDb;
15+
use Magento\Framework\Filesystem;
16+
use Magento\Framework\Filesystem\Io\File;
17+
use Magento\Framework\Model\Context;
18+
use Magento\Framework\Model\ResourceModel\AbstractResource;
19+
use Magento\Framework\Registry;
20+
use Magento\Framework\UrlInterface;
21+
use Magento\MediaStorage\Helper\File\Storage\Database;
22+
use Magento\MediaStorage\Model\File\UploaderFactory;
1123
use Magento\Theme\Model\Design\Backend\Image;
1224
use PHPUnit_Framework_MockObject_MockObject;
1325

@@ -19,25 +31,26 @@ class ImageTest extends \PHPUnit\Framework\TestCase
1931
/** @var Image */
2032
private $imageBackend;
2133

34+
/** @var File */
35+
private $ioFileSystem;
36+
2237
/**
2338
* @inheritdoc
2439
*/
2540
public function setUp()
2641
{
27-
$context = $this->getMockObject(\Magento\Framework\Model\Context::class);
28-
$registry = $this->getMockObject(\Magento\Framework\Registry::class);
29-
$config = $this->getMockObject(\Magento\Framework\App\Config\ScopeConfigInterface::class);
30-
$cacheTypeList = $this->getMockObject(\Magento\Framework\App\Cache\TypeListInterface::class);
31-
$uploaderFactory = $this->getMockObject(\Magento\MediaStorage\Model\File\UploaderFactory::class);
32-
$requestData = $this->getMockObject(
33-
\Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface::class
34-
);
35-
$filesystem = $this->getMockObject(\Magento\Framework\Filesystem::class);
36-
$urlBuilder = $this->getMockObject(\Magento\Framework\UrlInterface::class);
37-
$databaseHelper = $this->getMockObject(\Magento\MediaStorage\Helper\File\Storage\Database::class);
38-
$abstractResource = $this->getMockObject(\Magento\Framework\Model\ResourceModel\AbstractResource::class);
39-
$abstractDb = $this->getMockObject(\Magento\Framework\Data\Collection\AbstractDb::class);
40-
$ioFileSystem = $this->getMockObject(\Magento\Framework\Filesystem\Io\File::class);
42+
$context = $this->getMockObject(Context::class);
43+
$registry = $this->getMockObject(Registry::class);
44+
$config = $this->getMockObject(ScopeConfigInterface::class);
45+
$cacheTypeList = $this->getMockObject(TypeListInterface::class);
46+
$uploaderFactory = $this->getMockObject(UploaderFactory::class);
47+
$requestData = $this->getMockObject(RequestDataInterface::class);
48+
$filesystem = $this->getMockObject(Filesystem::class);
49+
$urlBuilder = $this->getMockObject(UrlInterface::class);
50+
$databaseHelper = $this->getMockObject(Database::class);
51+
$abstractResource = $this->getMockObject(AbstractResource::class);
52+
$abstractDb = $this->getMockObject(AbstractDb::class);
53+
$this->ioFileSystem = $this->getMockObject(File::class);
4154
$this->imageBackend = new Image(
4255
$context,
4356
$registry,
@@ -51,7 +64,7 @@ public function setUp()
5164
$abstractDb,
5265
[],
5366
$databaseHelper,
54-
$ioFileSystem
67+
$this->ioFileSystem
5568
);
5669
}
5770

@@ -86,15 +99,24 @@ private function getMockObject(string $class, array $methods = []): PHPUnit_Fram
8699
*/
87100
public function testBeforeSaveWithInvalidExtensionFile()
88101
{
102+
$invalidFileName = 'fileName.invalidExtension';
89103
$this->imageBackend->setData(
90104
[
91105
'value' => [
92106
[
93-
'file' => 'fileName.invalidExtension',
107+
'file' => $invalidFileName,
94108
]
95109
],
96110
]
97111
);
112+
$expectedPathInfo = [
113+
'extension' => 'invalidExtension'
114+
];
115+
$this->ioFileSystem
116+
->expects($this->any())
117+
->method('getPathInfo')
118+
->with($invalidFileName)
119+
->willReturn($expectedPathInfo);
98120
$this->imageBackend->beforeSave();
99121
}
100122
}

0 commit comments

Comments
 (0)