Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Element\Context;
use Magento\Framework\View\Element\Html\Select;
use Magento\Framework\View\Layout\ProcessorFactory;
use Magento\Framework\View\Model\PageLayout\Config\BuilderInterface as PageLayoutConfigBuilder;
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory;

/**
* A chooser for container for widget instances
*
Expand All @@ -13,40 +22,53 @@
* @method \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Container setTheme($theme)
* @method \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Container setArea($area)
*/
class Container extends \Magento\Framework\View\Element\Html\Select
class Container extends Select
{
/**#@+
* Frontend page layouts
* @deprecated hardcoded list was replaced with checking actual existing layouts
* @see \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface::getPageLayoutsConfig
*/
const PAGE_LAYOUT_1COLUMN = '1column-center';
const PAGE_LAYOUT_2COLUMNS_LEFT = '2columns-left';
const PAGE_LAYOUT_2COLUMNS_RIGHT = '2columns-right';
const PAGE_LAYOUT_3COLUMNS = '3columns';
/**#@-*/

/**#@-*/
/**
* @var ProcessorFactory
*/
protected $_layoutProcessorFactory;

/**
* @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory
* @var CollectionFactory
*/
protected $_themesFactory;

/**
* @param \Magento\Framework\View\Element\Context $context
* @param \Magento\Framework\View\Layout\ProcessorFactory $layoutProcessorFactory
* @param \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $themesFactory
* @var PageLayoutConfigBuilder
*/
private $pageLayoutConfigBuilder;

/**
* @param Context $context
* @param ProcessorFactory $layoutProcessorFactory
* @param CollectionFactory $themesFactory
* @param array $data
* @param PageLayoutConfigBuilder|null $pageLayoutConfigBuilder
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Framework\View\Layout\ProcessorFactory $layoutProcessorFactory,
\Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $themesFactory,
array $data = []
Context $context,
ProcessorFactory $layoutProcessorFactory,
CollectionFactory $themesFactory,
array $data = [],
PageLayoutConfigBuilder $pageLayoutConfigBuilder = null
) {
parent::__construct($context, $data);
$this->_layoutProcessorFactory = $layoutProcessorFactory;
$this->_themesFactory = $themesFactory;
parent::__construct($context, $data);
$this->pageLayoutConfigBuilder = $pageLayoutConfigBuilder
?? ObjectManager::getInstance()->get(PageLayoutConfigBuilder::class);
}

/**
Expand Down Expand Up @@ -101,19 +123,22 @@ protected function _beforeToHtml()
$this->addOption($containerName, $containerLabel);
}
}

return parent::_beforeToHtml();
}

/**
* Retrieve theme instance by its identifier
*
* @param int $themeId
*
* @return \Magento\Theme\Model\Theme|null
*/
protected function _getThemeInstance($themeId)
{
/** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */
$themeCollection = $this->_themesFactory->create();

return $themeCollection->getItemById($themeId);
}

Expand All @@ -124,11 +149,8 @@ protected function _getThemeInstance($themeId)
*/
protected function getPageLayouts()
{
return [
self::PAGE_LAYOUT_1COLUMN,
self::PAGE_LAYOUT_2COLUMNS_LEFT,
self::PAGE_LAYOUT_2COLUMNS_RIGHT,
self::PAGE_LAYOUT_3COLUMNS,
];
$pageLayoutsConfig = $this->pageLayoutConfigBuilder->getPageLayoutsConfig();

return array_keys($pageLayoutsConfig->getPageLayouts());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Escaper;
use Magento\Framework\Event\Manager;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\View\Layout\ProcessorFactory;
use Magento\Framework\View\Model\Layout\Merge;
use Magento\Framework\View\Model\PageLayout\Config\BuilderInterface as PageLayoutConfigBuilder;
use Magento\Framework\View\PageLayout\Config as PageLayoutConfig;
use Magento\Theme\Model\ResourceModel\Theme\Collection;
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory;
use Magento\Theme\Model\Theme;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
abstract class AbstractContainerTest extends TestCase
{
/**
Expand Down Expand Up @@ -69,17 +73,15 @@ abstract class AbstractContainerTest extends TestCase
protected $escaperMock;

/**
* @var ObjectManagerHelper
* @var PageLayoutConfigBuilder|MockObject
*/
protected $objectManagerHelper;
protected $pageLayoutConfigBuilderMock;

/**
* @return void
*/
protected function setUp(): void
{
$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->eventManagerMock = $this->getMockBuilder(Manager::class)
->setMethods(['dispatch'])
->disableOriginalConstructor()
Expand Down Expand Up @@ -116,7 +118,7 @@ protected function setUp(): void
Escaper::class,
['escapeHtml', 'escapeHtmlAttr']
);
$this->escaperMock->expects($this->any())->method('escapeHtmlAttr')->willReturnArgument(0);
$this->escaperMock->method('escapeHtmlAttr')->willReturnArgument(0);

$this->contextMock = $this->getMockBuilder(Context::class)
->setMethods(['getEventManager', 'getScopeConfig', 'getEscaper'])
Expand All @@ -125,5 +127,16 @@ protected function setUp(): void
$this->contextMock->expects($this->once())->method('getEventManager')->willReturn($this->eventManagerMock);
$this->contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
$this->contextMock->expects($this->once())->method('getEscaper')->willReturn($this->escaperMock);

$this->pageLayoutConfigBuilderMock = $this->getMockBuilder(PageLayoutConfigBuilder::class)
->getMockForAbstractClass();
$pageLayoutConfigMock = $this->getMockBuilder(PageLayoutConfig::class)
->onlyMethods(['getPageLayouts'])
->disableOriginalConstructor()
->getMock();
$pageLayoutConfigMock->method('getPageLayouts')
->willReturn(['empty' => 'Empty']);
$this->pageLayoutConfigBuilderMock->method('getPageLayoutsConfig')
->willReturn($pageLayoutConfigMock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ protected function setUp(): void
{
parent::setUp();

$this->containerBlock = $this->objectManagerHelper->getObject(
Container::class,
[
'context' => $this->contextMock,
'themesFactory' => $this->themeCollectionFactoryMock,
'layoutProcessorFactory' => $this->layoutProcessorFactoryMock
]
$this->containerBlock = new Container(
$this->contextMock,
$this->layoutProcessorFactoryMock,
$this->themeCollectionFactoryMock,
[],
$this->pageLayoutConfigBuilderMock
);
}

Expand Down