Skip to content

Commit

Permalink
magento/adobe-stock-integration#1712: Remove DataObject usage from Op…
Browse files Browse the repository at this point in the history
…enDialogUrl provider - remove data object usage from OpenDialogUrl provider, added new plugin and modified the integration test
  • Loading branch information
joweecaquicla committed Aug 12, 2020
1 parent be26941 commit 68b35c5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MediaGalleryIntegration\Plugin;

use Magento\MediaGalleryUiApi\Api\ConfigInterface;
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;

class NewMediaGalleryOpenDialogUrl
{
/**
* @var ConfigInterface
*/
private $config;

/**
* @param ConfigInterface $config
*/
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}

/**
* @param OpenDialogUrl $subject
* @param string $result
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @return string
*/
public function afterGet(OpenDialogUrl $subject, string $result)
{
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/newmediagalleryplugin.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->debug(__METHOD__);
$logger->debug("PASSING HERE!");
return $this->config->isEnabled() ? 'media_gallery/index/index' : $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
namespace Magento\MediaGalleryIntegration\Test\Integration\Model;

use Magento\Framework\ObjectManagerInterface;
use Magento\MediaGalleryIntegration\Model\OpenDialogUrlProvider;
use Magento\MediaGalleryUiApi\Api\ConfigInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
use PHPUnit\Framework\TestCase;

/**
* Provide tests cover getting correct url based on the config settings.
* @magentoAppArea adminhtml
*/
class OpenDialogUrlProviderTest extends TestCase
class OpenDialogUrlTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManger;

/**
* @var OpenDialogUrlProvider
* @var OpenDialogUrl
*/
private $openDialogUrlProvider;
private $openDialogUrl;

/**
* @inheritdoc
Expand All @@ -37,8 +37,8 @@ protected function setUp(): void
{
$this->objectManger = Bootstrap::getObjectManager();
$config = $this->objectManger->create(ConfigInterface::class);
$this->openDialogUrlProvider = $this->objectManger->create(
OpenDialogUrlProvider::class,
$this->openDialogUrl = $this->objectManger->create(
OpenDialogUrl::class,
['config' => $config]
);
}
Expand All @@ -49,7 +49,7 @@ protected function setUp(): void
*/
public function testWithEnhancedMediaGalleryDisabled(): void
{
self::assertEquals('cms/wysiwyg_images/index', $this->openDialogUrlProvider->getUrl());
self::assertEquals('cms/wysiwyg_images/index', $this->openDialogUrl->get());
}

/**
Expand All @@ -58,6 +58,6 @@ public function testWithEnhancedMediaGalleryDisabled(): void
*/
public function testWithEnhancedMediaGalleryEnabled(): void
{
self::assertEquals('media_gallery/index/index', $this->openDialogUrlProvider->getUrl());
self::assertEquals('media_gallery/index/index', $this->openDialogUrl->get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl">
<arguments>
<argument name="url" xsi:type="object">Magento\MediaGalleryIntegration\Model\OpenDialogUrlProvider</argument>
</arguments>
<plugin name="new_media_gallery_open_dialog_url" type="Magento\MediaGalleryIntegration\Plugin\NewMediaGalleryOpenDialogUrl" />
</type>
<type name="Magento\Framework\File\Uploader">
<plugin name="save_asset_image" type="Magento\MediaGalleryIntegration\Plugin\SaveImageInformation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

namespace Magento\Ui\Component\Form\Element\DataType\Media;

use Magento\Framework\DataObject;

/**
* Basic configuration for OdenDialogUrl
* Basic configuration for OpenDialogUrl
*/
class OpenDialogUrl
{
Expand All @@ -22,14 +20,6 @@ class OpenDialogUrl
*/
private $openDialogUrl;

/**
* @param DataObject $url
*/
public function __construct(DataObject $url = null)
{
$this->openDialogUrl = $url;
}

/**
* Returns open dialog url for media browser
*
Expand All @@ -38,7 +28,7 @@ public function __construct(DataObject $url = null)
public function get(): string
{
if ($this->openDialogUrl) {
return $this->openDialogUrl->getUrl();
return $this->openDialogUrl;
}
return self::DEFAULT_OPEN_DIALOG_URL;
}
Expand Down

0 comments on commit 68b35c5

Please sign in to comment.