Skip to content

Commit a8ba203

Browse files
committed
#27499: Moved configuration xsd to MediaGalleryApi module
1 parent 5aceeab commit a8ba203

File tree

9 files changed

+44
-71
lines changed

9 files changed

+44
-71
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public function get($key = null, $default = null)
4848
*/
4949
public function getBlacklistPatterns() : array
5050
{
51-
return $this->data->get(self::XML_PATH_BLACKLIST_PATTERNS);
51+
return $this->get(self::XML_PATH_BLACKLIST_PATTERNS);
5252
}
5353
}

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SchemaLocator implements SchemaLocatorInterface
2828
*/
2929
public function __construct(Reader $moduleReader)
3030
{
31-
$this->schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_MediaGallery') . '/directory.xsd';
31+
$this->schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_MediaGalleryApi') . '/directory.xsd';
3232
}
3333

3434
/**

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
@@ -24,7 +24,6 @@
2424
*/
2525
class SaveTest extends TestCase
2626
{
27-
2827
/**
2928
* Constant for tablename of media gallery assets
3029
*/

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@
3434
<plugin name="media_gallery_image_remove_metadata_after_wysiwyg" type="Magento\MediaGallery\Plugin\Wysiwyg\Images\Storage"
3535
sortOrder="10" disabled="false"/>
3636
</type>
37-
<type name="Magento\MediaGallery\Model\Directory\Config\Reader">
37+
<virtualType name="Magento\MediaGallery\Model\Directory\Config\Reader" type="Magento\Framework\Config\Reader\Filesystem">
3838
<arguments>
3939
<argument name="fileName" xsi:type="string">directory.xml</argument>
4040
<argument name="converter" xsi:type="object">Magento\MediaGallery\Model\Directory\Config\Converter</argument>
4141
<argument name="schemaLocator" xsi:type="object">Magento\MediaGallery\Model\Directory\Config\SchemaLocator</argument>
42+
<argument name="idAttributes" xsi:type="array">
43+
<item name="/config/blacklist/patterns/pattern" xsi:type="string">name</item>
44+
</argument>
4245
</arguments>
43-
</type>
46+
</virtualType>
4447
<virtualType name="Magento\MediaGallery\Model\Directory\Config\Data" type="Magento\Framework\Config\Data">
4548
<arguments>
4649
<argument name="reader" xsi:type="object">Magento\MediaGallery\Model\Directory\Config\Reader</argument>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_MediaGallery:etc/directory.xsd">
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_MediaGalleryApi:etc/directory.xsd">
99
<blacklist>
1010
<patterns>
1111
<pattern name="captcha">/^captcha/</pattern>

app/code/Magento/MediaGallery/etc/directory.xsd renamed to app/code/Magento/MediaGalleryApi/etc/directory.xsd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,33 @@
1616
</xs:complexType>
1717

1818
<xs:complexType name="blacklistType">
19+
<xs:annotation>
20+
<xs:documentation>
21+
Blacklist used for excluding directories from media gallery rendering and operations
22+
</xs:documentation>
23+
</xs:annotation>
1924
<xs:sequence>
2025
<xs:element type="patternsType" name="patterns" maxOccurs="unbounded" minOccurs="0"/>
2126
</xs:sequence>
2227
</xs:complexType>
2328

2429
<xs:complexType name="patternsType">
30+
<xs:annotation>
31+
<xs:documentation>
32+
List of directory paths regexp patterns
33+
</xs:documentation>
34+
</xs:annotation>
2535
<xs:sequence>
2636
<xs:element type="patternType" name="pattern" maxOccurs="unbounded" minOccurs="0"/>
2737
</xs:sequence>
2838
</xs:complexType>
2939

3040
<xs:complexType name="patternType">
41+
<xs:annotation>
42+
<xs:documentation>
43+
Directory path regexp pattern
44+
</xs:documentation>
45+
</xs:annotation>
3146
<xs:simpleContent>
3247
<xs:extension base="xs:string">
3348
<xs:attribute type="xs:string" name="name" use="required"/>

dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\MediaGallery\Model\Directory\Command;
810

911
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -19,33 +21,26 @@ class CreateByPathTest extends \PHPUnit\Framework\TestCase
1921
/**
2022
* Test directory name
2123
*/
22-
private CONST TEST_DIRECTORY_NAME = 'testCreateDirectory';
24+
private const TEST_DIRECTORY_NAME = 'testCreateDirectory';
2325

2426
/**
2527
* Absolute path to the media direcrory
2628
*/
27-
private static $_mediaPath;
29+
private $mediaDirectoryPath;
2830

2931
/**
3032
* @var CreateByPathInterface
3133
*/
3234
private $createByPath;
3335

34-
/**
35-
* @inheritdoc
36-
*/
37-
public static function setUpBeforeClass()
38-
{
39-
self::$_mediaPath = Bootstrap::getObjectManager()->get(Filesystem::class)
40-
->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
41-
}
42-
4336
/**
4437
* @inheritdoc
4538
*/
4639
public function setUp()
4740
{
4841
$this->createByPath = Bootstrap::getObjectManager()->create(CreateByPathInterface::class);
42+
$this->mediaDirectoryPath = Bootstrap::getObjectManager()->get(Filesystem::class)
43+
->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
4944
}
5045

5146
/**
@@ -54,7 +49,7 @@ public function setUp()
5449
*/
5550
public function testCreateDirectory(): void
5651
{
57-
$fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME;
52+
$fullPath = $this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME;
5853
$this->createByPath->execute('', self::TEST_DIRECTORY_NAME);
5954
$this->assertFileExists($fullPath);
6055
}

dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\MediaGallery\Model\Directory\Command;
810

911
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -16,31 +18,15 @@
1618
*/
1719
class DeleteByPathTest extends \PHPUnit\Framework\TestCase
1820
{
19-
/**
20-
* Test directory name
21-
*/
22-
private CONST TEST_DIRECTORY_NAME = 'testDeleteDirectory';
23-
24-
/**
25-
* Absolute path to the media direcrory
26-
*/
27-
private static $_mediaPath;
28-
2921
/**
3022
* @var DeleteByPathInterface
3123
*/
3224
private $deleteByPath;
3325

3426
/**
35-
* @inheritdoc
27+
* @var string
3628
*/
37-
public static function setUpBeforeClass()
38-
{
39-
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */
40-
$directory = Bootstrap::getObjectManager()->get(Filesystem::class)->getDirectoryWrite(DirectoryList::MEDIA);
41-
self::$_mediaPath = $directory->getAbsolutePath();
42-
$directory->create(self::TEST_DIRECTORY_NAME);
43-
}
29+
private $testDirectoryName = 'testDeleteDirectory';
4430

4531
/**
4632
* @inheritdoc
@@ -51,19 +37,22 @@ public function setUp()
5137
}
5238

5339
/**
54-
* @return void
5540
* @throws \Magento\Framework\Exception\CouldNotDeleteException
41+
* @throws \Magento\Framework\Exception\FileSystemException
5642
*/
5743
public function testDeleteDirectoryWithExistingDirectoryAndCorrectAbsolutePath(): void
5844
{
59-
$fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME;
45+
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
46+
$mediaDirectory = Bootstrap::getObjectManager()->get(Filesystem::class)
47+
->getDirectoryRead(DirectoryList::MEDIA);
48+
$mediaDirectory->create($this->testDirectoryName);
49+
$fullPath = $mediaDirectory->getAbsolutePath($this->testDirectoryName);
6050
$this->assertFileExists($fullPath);
61-
$this->deleteByPath->execute(self::TEST_DIRECTORY_NAME);
51+
$this->deleteByPath->execute($this->testDirectoryName);
6252
$this->assertFileNotExists($fullPath);
6353
}
6454

6555
/**
66-
* @return void
6756
* @throws \Magento\Framework\Exception\CouldNotDeleteException
6857
* @expectedException \Magento\Framework\Exception\CouldNotDeleteException
6958
*/
@@ -73,7 +62,6 @@ public function testDeleteDirectoryWithRelativePathUnderMediaFolder(): void
7362
}
7463

7564
/**
76-
* @return void
7765
* @throws \Magento\Framework\Exception\CouldNotDeleteException
7866
* @expectedException \Magento\Framework\Exception\CouldNotDeleteException
7967
*/
@@ -85,14 +73,14 @@ public function testDeleteDirectoryThatIsNotAllowed(): void
8573
/**
8674
* @throws \Magento\Framework\Exception\FileSystemException
8775
*/
88-
public static function tearDownAfterClass()
76+
public function tearDown()
8977
{
9078
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
9179
->get(\Magento\Framework\Filesystem::class);
9280
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */
9381
$directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
94-
if ($directory->isExist(self::TEST_DIRECTORY_NAME)) {
95-
$directory->delete(self::TEST_DIRECTORY_NAME);
82+
if ($directory->isExist($this->testDirectoryName)) {
83+
$directory->delete($this->testDirectoryName);
9684
}
9785
}
9886
}

0 commit comments

Comments
 (0)