Skip to content

Commit e1bea53

Browse files
committed
- Fix unit test
- Refactoring
1 parent 7fd26a9 commit e1bea53

File tree

6 files changed

+28
-57
lines changed

6 files changed

+28
-57
lines changed

app/code/Magento/MediaGallery/Model/Directory/Config.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
class Config
1616
{
17+
private const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns';
18+
1719
/**
1820
* @var DataInterface
1921
*/
@@ -38,4 +40,14 @@ public function get($key = null, $default = null)
3840
{
3941
return $this->data->get($key, $default);
4042
}
43+
44+
/**
45+
* Returns list of blacklist regexp patterns
46+
*
47+
* @return array
48+
*/
49+
public function getBlacklistPatterns() : array
50+
{
51+
return $this->data->get(self::XML_PATH_BLACKLIST_PATTERNS);
52+
}
4153
}

app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function convert($source): array
4040
$result = [];
4141

4242
if (!$source instanceof \DOMDocument) {
43-
return $result;
43+
throw new \InvalidArgumentException('The source should be instance of DOMDocument');
4444
}
4545

4646
foreach ($source->getElementsByTagName(self::BLACKLIST_TAG_NAME) as $blacklist) {

app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77

88
namespace Magento\MediaGallery\Model\Directory\Config;
99

10-
use Magento\Framework\App\Area;
1110
use Magento\Framework\Config\ReaderInterface;
1211
use Magento\Framework\Config\Reader\Filesystem;
13-
use Magento\Framework\Config\FileResolverInterface;
14-
use Magento\Framework\Config\ValidationStateInterface;
15-
use Magento\Framework\Config\Dom;
1612

1713
/**
1814
* Media gallery directory config reader
@@ -28,43 +24,4 @@ class Reader extends Filesystem implements ReaderInterface
2824
'/config/patterns' => 'patterns',
2925
'/config/patterns/pattern' => 'name',
3026
];
31-
32-
/**
33-
* XML Configuration file name
34-
*/
35-
private const XML_FILE_NAME = 'directory.xml';
36-
37-
/**
38-
* Construct the FileSystem Reader Class
39-
*
40-
* @param \Magento\Framework\Config\FileResolverInterface $fileResolver
41-
* @param Converter $converter
42-
* @param SchemaLocator $schemaLocator
43-
* @param \Magento\Framework\Config\ValidationStateInterface $validationState
44-
* @param string $fileName
45-
* @param array $idAttributes
46-
* @param string $domDocumentClass
47-
* @param string $defaultScope
48-
*/
49-
public function __construct(
50-
FileResolverInterface $fileResolver,
51-
Converter $converter,
52-
SchemaLocator $schemaLocator,
53-
ValidationStateInterface $validationState,
54-
$fileName = self::XML_FILE_NAME,
55-
$idAttributes = [],
56-
$domDocumentClass = Dom::class,
57-
$defaultScope = Area::AREA_GLOBAL
58-
) {
59-
parent::__construct(
60-
$fileResolver,
61-
$converter,
62-
$schemaLocator,
63-
$validationState,
64-
$fileName,
65-
$idAttributes,
66-
$domDocumentClass,
67-
$defaultScope
68-
);
69-
}
7027
}

app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
*/
1515
class IsBlacklisted implements IsBlacklistedInterface
1616
{
17-
const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns';
18-
1917
/**
2018
* @var Config
2119
*/
@@ -37,7 +35,7 @@ public function __construct(Config $config)
3735
*/
3836
public function execute(string $path): bool
3937
{
40-
foreach ($this->config->get(self::XML_PATH_BLACKLIST_PATTERNS) as $pattern) {
38+
foreach ($this->config->getBlacklistPatterns() as $pattern) {
4139
if (empty($pattern)) {
4240
continue;
4341
}

app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\MediaGallery\Test\Unit\Model\Asset\Command;
99

10-
use Magento\Eav\Helper\Data;
1110
use Magento\MediaGallery\Model\Asset\Command\Save;
1211
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
1312
use Magento\Framework\App\ResourceConnection;

app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1111
use PHPUnit\Framework\TestCase;
1212
use Magento\MediaGallery\Model\Directory\IsBlacklisted;
13+
use Magento\MediaGallery\Model\Directory\Config;
1314

1415
/**
1516
* Test the Excluded model
@@ -21,20 +22,24 @@ class IsBlacklistedTest extends TestCase
2122
*/
2223
private $object;
2324

25+
/**
26+
* @var
27+
*/
28+
private $config;
29+
2430
/**
2531
* Initialize basic test class mocks
2632
*/
2733
protected function setUp(): void
2834
{
29-
$this->object = (new ObjectManager($this))->getObject(
30-
IsBlacklisted::class,
31-
[
32-
'patterns' => [
33-
'tmp' => '/pub\/media\/tmp/',
34-
'captcha' => '/pub\/media\/captcha/'
35-
]
36-
]
37-
);
35+
$this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
36+
$this->config->expects($this->at(0))->method('getBlacklistPatterns')->willReturn([
37+
'tmp' => '/pub\/media\/tmp/',
38+
'captcha' => '/pub\/media\/captcha/'
39+
]);
40+
$this->object = (new ObjectManager($this))->getObject(IsBlacklisted::class, [
41+
'config' => $this->config
42+
]);
3843
}
3944

4045
/**

0 commit comments

Comments
 (0)