diff --git a/app/code/Magento/Backend/Model/View/Result/Page.php b/app/code/Magento/Backend/Model/View/Result/Page.php index e81e4d982700c..1386628a8d511 100644 --- a/app/code/Magento/Backend/Model/View/Result/Page.php +++ b/app/code/Magento/Backend/Model/View/Result/Page.php @@ -76,7 +76,11 @@ public function setActiveMenu($itemId) */ public function addBreadcrumb($label, $title, $link = null) { - $this->layout->getBlock('breadcrumbs')->addLink($label, $title, $link); + /** @var \Magento\Backend\Block\Widget\Breadcrumbs $block */ + $block = $this->layout->getBlock('breadcrumbs'); + if ($block) { + $block->addLink($label, $title, $link); + } return $this; } diff --git a/app/code/Magento/Backend/Test/Unit/Model/View/Result/PageTest.php b/app/code/Magento/Backend/Test/Unit/Model/View/Result/PageTest.php new file mode 100644 index 0000000000000..19f7f6e390ea9 --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Model/View/Result/PageTest.php @@ -0,0 +1,89 @@ +layoutMock = $this->getMockBuilder('Magento\Framework\View\LayoutInterface') + ->setMethods(['setGeneratorPool']) + ->getMockForAbstractClass(); + $this->breadcrumbsBlockMock = $this->getMockBuilder('Magento\Backend\Block\Widget\Breadcrumbs') + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->context = $this->objectManagerHelper->getObject( + 'Magento\Framework\View\Element\Template\Context', + ['layout' => $this->layoutMock] + ); + $this->resultPage = $this->objectManagerHelper->getObject( + 'Magento\Backend\Model\View\Result\Page', + ['context' => $this->context] + ); + } + + public function testAddBreadcrumb() + { + $label = 'label'; + $title = 'title'; + $link = '/link'; + + $this->layoutMock->expects($this->once()) + ->method('getBlock') + ->with('breadcrumbs') + ->willReturn($this->breadcrumbsBlockMock); + $this->breadcrumbsBlockMock->expects($this->once()) + ->method('addLink') + ->with($label, $title, $link) + ->willReturnSelf(); + + $this->assertSame($this->resultPage, $this->resultPage->addBreadcrumb($label, $title, $link)); + } + + public function testAddBreadcrumbNoBlock() + { + $label = 'label'; + $title = 'title'; + + $this->layoutMock->expects($this->once()) + ->method('getBlock') + ->with('breadcrumbs') + ->willReturn(false); + $this->breadcrumbsBlockMock->expects($this->never()) + ->method('addLink'); + + $this->assertSame($this->resultPage, $this->resultPage->addBreadcrumb($label, $title)); + } +} diff --git a/app/code/Magento/Backend/view/adminhtml/layout/admin_login.xml b/app/code/Magento/Backend/view/adminhtml/layout/admin_login.xml index 35b8eebed0c28..b0891c464f5f3 100644 --- a/app/code/Magento/Backend/view/adminhtml/layout/admin_login.xml +++ b/app/code/Magento/Backend/view/adminhtml/layout/admin_login.xml @@ -9,15 +9,14 @@ - - - - - - + + + + + - - + + diff --git a/app/code/Magento/Backend/view/adminhtml/layout/popup.xml b/app/code/Magento/Backend/view/adminhtml/layout/popup.xml index 17da4d9b56eb7..e6f59c729501d 100644 --- a/app/code/Magento/Backend/view/adminhtml/layout/popup.xml +++ b/app/code/Magento/Backend/view/adminhtml/layout/popup.xml @@ -7,7 +7,7 @@ --> - - + + diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute.php index 9e15c4246cc04..6d444009f5a77 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute.php @@ -73,9 +73,10 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request) } /** + * @param \Magento\Framework\Phrase|null $title * @return \Magento\Backend\Model\View\Result\Page */ - protected function createActionPage() + protected function createActionPage($title = null) { /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); @@ -91,6 +92,9 @@ protected function createActionPage() $resultPage->addBreadcrumb(__('Catalog'), __('Catalog')) ->addBreadcrumb(__('Manage Product Attributes'), __('Manage Product Attributes')) ->setActiveMenu('Magento_Catalog::catalog_attributes_attributes'); + if (!empty($title)) { + $resultPage->addBreadcrumb($title, $title); + } } $resultPage->getConfig()->getTitle()->prepend(__('Product Attributes')); return $resultPage; diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php index f149ff2506a6c..8aa19c8c91110 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php @@ -52,9 +52,8 @@ public function execute() $item = $id ? __('Edit Product Attribute') : __('New Product Attribute'); - $resultPage = $this->createActionPage(); + $resultPage = $this->createActionPage($item); $resultPage->getConfig()->getTitle()->prepend($id ? $model->getName() : __('New Product Attribute')); - $resultPage->addBreadcrumb($item, $item); $resultPage->getLayout() ->getBlock('attribute_edit_js') ->setIsPopup((bool)$this->getRequest()->getParam('popup')); diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/EditTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/EditTest.php new file mode 100644 index 0000000000000..294860b66a912 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/EditTest.php @@ -0,0 +1,255 @@ +request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')->getMock(); + + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')->getMock(); + + $this->eavAttribute = $this->getMock( + 'Magento\Catalog\Model\Resource\Eav\Attribute', + ['setEntityTypeId', 'load', 'getId', 'getEntityTypeId', 'addData', 'getName'], + [], + '', + false + ); + + $this->registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); + + $this->resultPage = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') + ->disableOriginalConstructor() + ->setMethods(['setActiveMenu', 'getConfig', 'addBreadcrumb', 'addHandle', 'getLayout']) + ->getMock(); + + $this->resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultLayout = $this->getMockBuilder('Magento\Framework\View\Result\Layout') + ->disableOriginalConstructor() + ->getMock(); + + $this->pageConfig = $this->getMockBuilder('Magento\Framework\View\Page\Config') + ->disableOriginalConstructor() + ->getMock(); + + $this->pageTitle = $this->getMockBuilder('Magento\Framework\View\Page\Title') + ->disableOriginalConstructor() + ->getMock(); + + $this->layout = $this->getMock('Magento\Framework\View\Layout', ['getBlock'], [], '', false); + + $this->session = $this->getMockBuilder('Magento\Backend\Model\Session') + ->disableOriginalConstructor() + ->getMock(); + + $this->blockTemplate = $this->getMockBuilder('Magento\Backend\Block\Template') + ->disableOriginalConstructor() + ->getMock(); + + $this->context = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false); + $this->context->expects($this->any())->method('getRequest')->willReturn($this->request); + $this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock); + $this->context->expects($this->any())->method('getResultPageFactory')->willReturn($this->resultPageFactory); + $this->context->expects($this->any())->method('getSession')->willReturn($this->session); + + $this->objectManager = new ObjectManager($this); + $this->editController = $this->objectManager->getObject( + 'Magento\Catalog\Controller\Adminhtml\Product\Attribute\Edit', + [ + 'context' => $this->context, + 'resultPageFactory' => $this->resultPageFactory + ] + ); + } + + public function testExecutePopup() + { + $attributesData = ['frontend_label' => '']; + + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['attribute_id', null, null], + ['attribute', null, $attributesData], + ['popup', null, '1'], + ['product_tab', null, null] + ] + ); + + $this->objectManagerMock->expects($this->any())->method('create') + ->with('Magento\Catalog\Model\Resource\Eav\Attribute') + ->willReturn($this->eavAttribute); + $this->objectManagerMock->expects($this->any())->method('get') + ->with('Magento\Backend\Model\Session') + ->willReturn($this->session); + + $this->eavAttribute->expects($this->once())->method('setEntityTypeId')->willReturnSelf(); + $this->eavAttribute->expects($this->once())->method('addData')->with($attributesData)->willReturnSelf(); + $this->eavAttribute->expects($this->any())->method('getName')->willReturn(null); + + $this->registry->expects($this->any()) + ->method('register') + ->with('entity_attribute', $this->eavAttribute); + + $this->resultPage->expects($this->once()) + ->method('addHandle') + ->with(['popup', 'catalog_product_attribute_edit_popup']) + ->willReturnSelf(); + $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig); + $this->resultPage->expects($this->once())->method('getLayout')->willReturn($this->layout); + + $this->resultPageFactory->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($this->resultPage); + + $this->pageConfig->expects($this->any())->method('addBodyClass')->willReturnSelf(); + $this->pageConfig->expects($this->any())->method('getTitle')->willReturn($this->pageTitle); + + $this->pageTitle->expects($this->any())->method('prepend')->willReturnSelf(); + + $this->layout->expects($this->once())->method('getBlock')->willReturn($this->blockTemplate); + + $this->blockTemplate->expects($this->any())->method('setIsPopup')->willReturnSelf(); + + $this->assertSame($this->resultPage, $this->editController->execute()); + } + + public function testExecuteNoPopup() + { + $attributesData = ['frontend_label' => '']; + + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['attribute_id', null, null], + ['attribute', null, $attributesData], + ['popup', null, false], + ] + ); + + $this->objectManagerMock->expects($this->any())->method('create') + ->with('Magento\Catalog\Model\Resource\Eav\Attribute') + ->willReturn($this->eavAttribute); + $this->objectManagerMock->expects($this->any())->method('get') + ->with('Magento\Backend\Model\Session') + ->willReturn($this->session); + + $this->eavAttribute->expects($this->once())->method('setEntityTypeId')->willReturnSelf(); + $this->eavAttribute->expects($this->once())->method('addData')->with($attributesData)->willReturnSelf(); + + $this->registry->expects($this->any()) + ->method('register') + ->with('entity_attribute', $this->eavAttribute); + + $this->resultPage->expects($this->any())->method('addBreadcrumb')->willReturnSelf(); + $this->resultPage->expects($this->once()) + ->method('setActiveMenu') + ->with('Magento_Catalog::catalog_attributes_attributes') + ->willReturnSelf(); + $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig); + $this->resultPage->expects($this->once())->method('getLayout')->willReturn($this->layout); + + $this->resultPageFactory->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($this->resultPage); + + $this->pageConfig->expects($this->any())->method('getTitle')->willReturn($this->pageTitle); + + $this->pageTitle->expects($this->any())->method('prepend')->willReturnSelf(); + + $this->eavAttribute->expects($this->any())->method('getName')->willReturn(null); + + $this->layout->expects($this->once())->method('getBlock')->willReturn($this->blockTemplate); + + $this->blockTemplate->expects($this->any())->method('setIsPopup')->willReturnSelf(); + + $this->assertSame($this->resultPage, $this->editController->execute()); + } +} diff --git a/app/code/Magento/Catalog/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml b/app/code/Magento/Catalog/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml old mode 100644 new mode 100755 index 82899deca4005..3e99afa0dbeac --- a/app/code/Magento/Catalog/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml +++ b/app/code/Magento/Catalog/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml @@ -5,9 +5,11 @@ * See COPYING.txt for license details. */ --> - + - + + + diff --git a/app/code/Magento/Catalog/view/frontend/layout/catalog_product_gallery.xml b/app/code/Magento/Catalog/view/frontend/layout/catalog_product_gallery.xml old mode 100644 new mode 100755 index d29b981fd47cb..3eba65002e1a2 --- a/app/code/Magento/Catalog/view/frontend/layout/catalog_product_gallery.xml +++ b/app/code/Magento/Catalog/view/frontend/layout/catalog_product_gallery.xml @@ -5,7 +5,7 @@ * See COPYING.txt for license details. */ --> - + diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml index be5917f36ba62..500a2459192ea 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml @@ -411,6 +411,6 @@ - + diff --git a/app/code/Magento/Cms/Model/Resource/AbstractCollection.php b/app/code/Magento/Cms/Model/Resource/AbstractCollection.php index 5d4f961877c59..48188c96b7706 100644 --- a/app/code/Magento/Cms/Model/Resource/AbstractCollection.php +++ b/app/code/Magento/Cms/Model/Resource/AbstractCollection.php @@ -5,132 +5,159 @@ */ namespace Magento\Cms\Model\Resource; -use Magento\Framework\Data\AbstractSearchResult; -use Magento\Store\Model\StoreManagerInterface; -use Magento\Framework\Data\SearchResultProcessorFactory; -use Magento\Framework\Data\SearchResultProcessor; -use Magento\Framework\DB\QueryInterface; -use Magento\Framework\Data\Collection\EntityFactoryInterface; -use Magento\Framework\Event\ManagerInterface; -use Magento\Framework\Data\SearchResultIteratorFactory; - /** - * CMS block model + * Abstract collection of CMS pages and blocks */ -class AbstractCollection extends AbstractSearchResult +abstract class AbstractCollection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection { /** + * Store manager + * * @var \Magento\Store\Model\StoreManagerInterface */ protected $storeManager; /** - * @var SearchResultProcessor + * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory + * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy + * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection + * @param \Magento\Framework\Model\Resource\Db\AbstractDb|null $resource */ - protected $searchResultProcessor; + public function __construct( + \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, + \Psr\Log\LoggerInterface $logger, + \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, + \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, + \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null + ) { + parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); + $this->storeManager = $storeManager; + } /** - * Table which links CMS entity to stores + * Perform operations after collection load * - * @var string + * @param string $tableName + * @param string $columnName + * @return void */ - protected $storeTableName; + protected function performAfterLoad($tableName, $columnName) + { + $items = $this->getColumnValues($columnName); + if (count($items)) { + $connection = $this->getConnection(); + $select = $connection->select()->from(['cms_entity_store' => $this->getTable($tableName)]) + ->where('cms_entity_store.' . $columnName . ' IN (?)', $items); + $result = $connection->fetchPairs($select); + if ($result) { + foreach ($this as $item) { + $entityId = $item->getData($columnName); + if (!isset($result[$entityId])) { + continue; + } + if ($result[$entityId] == 0) { + $stores = $this->storeManager->getStores(false, true); + $storeId = current($stores)->getId(); + $storeCode = key($stores); + } else { + $storeId = $result[$item->getData($columnName)]; + $storeCode = $this->storeManager->getStore($storeId)->getCode(); + } + $item->setData('_first_store_id', $storeId); + $item->setData('store_code', $storeCode); + $item->setData('store_id', [$result[$entityId]]); + } + } + } + } /** - * @var string + * Add field filter to collection + * + * @param array|string $field + * @param string|int|array|null $condition + * @return $this */ - protected $linkFieldName; + public function addFieldToFilter($field, $condition = null) + { + if ($field === 'store_id') { + return $this->addStoreFilter($condition, false); + } + + return parent::addFieldToFilter($field, $condition); + } /** - * @param QueryInterface $query - * @param EntityFactoryInterface $entityFactory - * @param ManagerInterface $eventManager - * @param SearchResultIteratorFactory $resultIteratorFactory - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param SearchResultProcessorFactory $searchResultProcessorFactory + * Add filter by store + * + * @param int|array|\Magento\Store\Model\Store $store + * @param bool $withAdmin + * @return $this */ - public function __construct( - QueryInterface $query, - EntityFactoryInterface $entityFactory, - ManagerInterface $eventManager, - SearchResultIteratorFactory $resultIteratorFactory, - StoreManagerInterface $storeManager, - SearchResultProcessorFactory $searchResultProcessorFactory - ) { - $this->storeManager = $storeManager; - $this->searchResultProcessor = $searchResultProcessorFactory->create($this); - parent::__construct($query, $entityFactory, $eventManager, $resultIteratorFactory); - } + abstract public function addStoreFilter($store, $withAdmin = true); /** + * Perform adding filter by store + * + * @param int|array|\Magento\Store\Model\Store $store + * @param bool $withAdmin * @return void */ - protected function init() + protected function performAddStoreFilter($store, $withAdmin = true) { - $this->query->addCountSqlSkipPart(\Magento\Framework\DB\Select::GROUP, true); + if ($store instanceof \Magento\Store\Model\Store) { + $store = [$store->getId()]; + } + + if (!is_array($store)) { + $store = [$store]; + } + + if ($withAdmin) { + $store[] = \Magento\Store\Model\Store::DEFAULT_STORE_ID; + } + + $this->addFilter('store', ['in' => $store], 'public'); } /** - * @return array + * Join store relation table if there is store filter + * + * @param string $tableName + * @param string $columnName + * @return void */ - public function toOptionIdArray() + protected function joinStoreRelationTable($tableName, $columnName) { - $res = []; - $existingIdentifiers = []; - foreach ($this->getItems() as $item) { - /** @var \Magento\Cms\Model\Block|\Magento\Cms\Model\Page $item */ - $identifier = $item->getIdentifier(); - - $data['value'] = $identifier; - $data['label'] = $item->getTitle(); - - if (in_array($identifier, $existingIdentifiers)) { - $data['value'] .= '|' . $item->getId(); - } else { - $existingIdentifiers[] = $identifier; - } - $res[] = $data; + if ($this->getFilter('store')) { + $this->getSelect()->join( + ['store_table' => $this->getTable($tableName)], + 'main_table.' . $columnName . ' = store_table.' . $columnName, + [] + )->group( + 'main_table.' . $columnName + ); } - return $res; + parent::_renderFiltersBefore(); } /** - * Perform operations after collection load + * Get SQL for get record count * - * @return void + * Extra GROUP BY strip added. + * + * @return \Magento\Framework\DB\Select */ - protected function afterLoad() + public function getSelectCountSql() { - if ($this->getSearchCriteria()->getPart('first_store_flag')) { - $items = $this->searchResultProcessor->getColumnValues($this->linkFieldName); + $countSelect = parent::getSelectCountSql(); + $countSelect->reset(\Magento\Framework\DB\Select::GROUP); - $connection = $this->getQuery()->getConnection(); - $resource = $this->getQuery()->getResource(); - if (count($items)) { - $select = $connection->select()->from(['cps' => $resource->getTable($this->storeTableName)]) - ->where("cps.{$this->linkFieldName} IN (?)", $items); - $result = $connection->fetchPairs($select); - if ($result) { - foreach ($this->getItems() as $item) { - /** @var BlockInterface $item */ - if (!isset($result[$item->getId()])) { - continue; - } - if ($result[$item->getId()] == 0) { - $stores = $this->storeManager->getStores(false, true); - $storeId = current($stores)->getId(); - $storeCode = key($stores); - } else { - $storeId = $result[$item->getId()]; - $storeCode = $this->storeManager->getStore($storeId)->getCode(); - } - $item->setData('_first_store_id', $storeId); - $item->setData('store_code', $storeCode); - $item->setData('store_id', [$result[$item->getId()]]); - } - } - } - } - parent::afterLoad(); + return $countSelect; } } diff --git a/app/code/Magento/Cms/Model/Resource/Block/Collection.php b/app/code/Magento/Cms/Model/Resource/Block/Collection.php index bb7657bdb357f..2a355ca47bcd6 100644 --- a/app/code/Magento/Cms/Model/Resource/Block/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Block/Collection.php @@ -1,16 +1,16 @@ walk('afterLoad'); - parent::_afterLoad(); - } + $this->performAfterLoad('cms_block_store', 'block_id'); - /** - * @param string|array $field - * @param string|int|array|null $condition - * @return \Magento\Cms\Model\Resource\Block\Collection - */ - public function addFieldToFilter($field, $condition = null) - { - if ($field == 'store_id') { - return $this->addStoreFilter($condition, false); - } - return parent::addFieldToFilter($field, $condition); + return parent::_afterLoad(); } /** @@ -63,44 +53,17 @@ public function toOptionArray() /** * Add filter by store * - * @param int|\Magento\Store\Model\Store $store + * @param int|array|\Magento\Store\Model\Store $store * @param bool $withAdmin * @return $this */ public function addStoreFilter($store, $withAdmin = true) { - if ($store instanceof \Magento\Store\Model\Store) { - $store = [$store->getId()]; - } - - if (!is_array($store)) { - $store = [$store]; - } - - if ($withAdmin) { - $store[] = \Magento\Store\Model\Store::DEFAULT_STORE_ID; - } - - $this->addFilter('store', ['in' => $store], 'public'); + $this->performAddStoreFilter($store, $withAdmin); return $this; } - /** - * Get SQL for get record count. - * Extra GROUP BY strip added. - * - * @return \Magento\Framework\DB\Select - */ - public function getSelectCountSql() - { - $countSelect = parent::getSelectCountSql(); - - $countSelect->reset(\Magento\Framework\DB\Select::GROUP); - - return $countSelect; - } - /** * Join store relation table if there is store filter * @@ -108,15 +71,6 @@ public function getSelectCountSql() */ protected function _renderFiltersBefore() { - if ($this->getFilter('store')) { - $this->getSelect()->join( - ['store_table' => $this->getTable('cms_block_store')], - 'main_table.block_id = store_table.block_id', - [] - )->group( - 'main_table.block_id' - ); - } - parent::_renderFiltersBefore(); + $this->joinStoreRelationTable('cms_block_store', 'block_id'); } } diff --git a/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php index 7d8193c4bab99..6f3759681ab8e 100644 --- a/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php @@ -10,8 +10,7 @@ use Magento\Cms\Model\Resource\Block\Collection as BlockCollection; /** - * Class Collection - * Collection for displaying grid of sales documents + * Collection for displaying grid of cms blocks */ class Collection extends BlockCollection implements SearchResultInterface { @@ -25,8 +24,9 @@ class Collection extends BlockCollection implements SearchResultInterface * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param null|\Zend_Db_Adapter_Abstract $mainTable - * @param \Magento\Framework\Model\Resource\Db\AbstractDb $eventPrefix + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param string $mainTable + * @param string $eventPrefix * @param string $eventObject * @param string $resourceModel * @param string $model @@ -40,6 +40,7 @@ public function __construct( \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Store\Model\StoreManagerInterface $storeManager, $mainTable, $eventPrefix, $eventObject, @@ -53,6 +54,7 @@ public function __construct( $logger, $fetchStrategy, $eventManager, + $storeManager, $connection, $resource ); diff --git a/app/code/Magento/Cms/Model/Resource/Page/Collection.php b/app/code/Magento/Cms/Model/Resource/Page/Collection.php index b8eadc87623f8..8ef01de72f127 100644 --- a/app/code/Magento/Cms/Model/Resource/Page/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Page/Collection.php @@ -5,12 +5,12 @@ */ namespace Magento\Cms\Model\Resource\Page; +use \Magento\Cms\Model\Resource\AbstractCollection; + /** * CMS page collection - * - * Class Collection */ -class Collection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection +class Collection extends AbstractCollection { /** * @var string @@ -24,35 +24,6 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac */ protected $_previewFlag; - /** - * Store manager - * - * @var \Magento\Store\Model\StoreManagerInterface - */ - protected $_storeManager; - - /** - * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param mixed $connection - * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource - */ - public function __construct( - \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null - ) { - parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); - $this->_storeManager = $storeManager; - } - /** * Define resource model * @@ -105,45 +76,17 @@ public function setFirstStoreFlag($flag = false) return $this; } - /** - * Add field filter to collection - * - * @param string|array $field - * @param string|int|array|null $condition - * @return \Magento\Cms\Model\Resource\Block\Collection - */ - public function addFieldToFilter($field, $condition = null) - { - if ($field === 'store_id') { - return $this->addStoreFilter($condition, false); - } - - return parent::addFieldToFilter($field, $condition); - } - /** * Add filter by store * - * @param int|\Magento\Store\Model\Store $store + * @param int|array|\Magento\Store\Model\Store $store * @param bool $withAdmin * @return $this */ public function addStoreFilter($store, $withAdmin = true) { if (!$this->getFlag('store_filter_added')) { - if ($store instanceof \Magento\Store\Model\Store) { - $store = [$store->getId()]; - } - - if (!is_array($store)) { - $store = [$store]; - } - - if ($withAdmin) { - $store[] = \Magento\Store\Model\Store::DEFAULT_STORE_ID; - } - - $this->addFilter('store', ['in' => $store], 'public'); + $this->performAddStoreFilter($store, $withAdmin); } return $this; } @@ -155,67 +98,19 @@ public function addStoreFilter($store, $withAdmin = true) */ protected function _afterLoad() { - $items = $this->getColumnValues('page_id'); - if (count($items)) { - $connection = $this->getConnection(); - $select = $connection->select()->from(['cps' => $this->getTable('cms_page_store')]) - ->where('cps.page_id IN (?)', $items); - $result = $connection->fetchPairs($select); - if ($result) { - foreach ($this as $item) { - $pageId = $item->getData('page_id'); - if (!isset($result[$pageId])) { - continue; - } - if ($result[$pageId] == 0) { - $stores = $this->_storeManager->getStores(false, true); - $storeId = current($stores)->getId(); - $storeCode = key($stores); - } else { - $storeId = $result[$item->getData('page_id')]; - $storeCode = $this->_storeManager->getStore($storeId)->getCode(); - } - $item->setData('_first_store_id', $storeId); - $item->setData('store_code', $storeCode); - $item->setData('store_id', [$result[$pageId]]); - } - } - } - + $this->performAfterLoad('cms_page_store', 'page_id'); $this->_previewFlag = false; + return parent::_afterLoad(); } /** - * Join store relation table if there is store filter + * Perform operations before rendering filters * * @return void */ protected function _renderFiltersBefore() { - if ($this->getFilter('store')) { - $this->getSelect()->join( - ['store_table' => $this->getTable('cms_page_store')], - 'main_table.page_id = store_table.page_id', - [] - )->group( - 'main_table.page_id' - ); - } - parent::_renderFiltersBefore(); - } - - /** - * Get SQL for get record count. - * Extra GROUP BY strip added. - * - * @return \Magento\Framework\DB\Select - */ - public function getSelectCountSql() - { - $countSelect = parent::getSelectCountSql(); - $countSelect->reset(\Magento\Framework\DB\Select::GROUP); - - return $countSelect; + $this->joinStoreRelationTable('cms_page_store', 'page_id'); } } diff --git a/app/code/Magento/Cms/Test/Unit/Model/Resource/AbstractCollectionTest.php b/app/code/Magento/Cms/Test/Unit/Model/Resource/AbstractCollectionTest.php new file mode 100644 index 0000000000000..0f091388cc785 --- /dev/null +++ b/app/code/Magento/Cms/Test/Unit/Model/Resource/AbstractCollectionTest.php @@ -0,0 +1,51 @@ +select = $this->getMockBuilder('Magento\Framework\DB\Select') + ->disableOriginalConstructor() + ->getMock(); + + $this->connection = $this->getMockBuilder('Magento\Framework\DB\Adapter\Pdo\Mysql') + ->disableOriginalConstructor() + ->getMock(); + $this->connection->expects($this->any())->method('select')->willReturn($this->select); + + $this->resource = $this->getMockBuilder('Magento\Framework\Model\Resource\Db\AbstractDb') + ->disableOriginalConstructor() + ->setMethods(['getConnection', 'getMainTable', 'getTable']) + ->getMockForAbstractClass(); + $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection); + $this->resource->expects($this->any())->method('getMainTable')->willReturn('table_test'); + $this->resource->expects($this->any())->method('getTable')->willReturn('test'); + + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + } +} diff --git a/app/code/Magento/Cms/Test/Unit/Model/Resource/Block/CollectionTest.php b/app/code/Magento/Cms/Test/Unit/Model/Resource/Block/CollectionTest.php new file mode 100644 index 0000000000000..b87c29ca44249 --- /dev/null +++ b/app/code/Magento/Cms/Test/Unit/Model/Resource/Block/CollectionTest.php @@ -0,0 +1,63 @@ +collection = $this->objectManager->getObject( + 'Magento\Cms\Model\Resource\Block\Collection', + [ + 'resource' => $this->resource, + 'connection' => $this->connection + ] + ); + } + + public function testAddFieldToFilterStore() + { + $storeId = 1; + + $expectedFilter = new DataObject( + [ + 'field' => 'store', + 'value' => ['in' => [1]], + 'type' => 'public' + ] + ); + + $this->assertSame($this->collection, $this->collection->addFieldToFilter('store_id', $storeId)); + // addition call to make sure that correct value was set to filter + $this->assertEquals($expectedFilter, $this->collection->getFilter('store')); + } + + public function testAddFieldToFilter() + { + $field = 'title'; + $value = 'test_filter'; + $searchSql = 'sql query'; + + $this->connection->expects($this->any())->method('quoteIdentifier')->willReturn($searchSql); + $this->connection->expects($this->any())->method('prepareSqlCondition')->willReturn($searchSql); + + $this->select->expects($this->once()) + ->method('where') + ->with($searchSql, null, \Magento\Framework\DB\Select::TYPE_CONDITION); + + $this->assertSame($this->collection, $this->collection->addFieldToFilter($field, $value)); + } +} diff --git a/app/code/Magento/Cms/Test/Unit/Model/Resource/Block/Grid/CollectionTest.php b/app/code/Magento/Cms/Test/Unit/Model/Resource/Block/Grid/CollectionTest.php deleted file mode 100644 index c320124de3624..0000000000000 --- a/app/code/Magento/Cms/Test/Unit/Model/Resource/Block/Grid/CollectionTest.php +++ /dev/null @@ -1,89 +0,0 @@ -select = $this->getMockBuilder('Magento\Framework\DB\Select') - ->disableOriginalConstructor() - ->getMock(); - - $connection = $this->getMockBuilder('Magento\Framework\DB\Adapter\Pdo\Mysql') - ->disableOriginalConstructor() - ->getMock(); - $connection->expects($this->any()) - ->method('select') - ->will($this->returnValue($this->select)); - - $resource = $this->getMockBuilder('Magento\Framework\Model\Resource\Db\AbstractDb') - ->disableOriginalConstructor() - ->setMethods(['__wakeup', 'getConnection']) - ->getMockForAbstractClass(); - $resource->expects($this->any()) - ->method('getConnection') - ->will($this->returnValue($connection)); - - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $arguments = $objectManagerHelper->getConstructArguments( - 'Magento\Cms\Model\Resource\Block\Collection', - ['resource' => $resource, 'connection' => $connection] - ); - - $this->collection = $this->getMockBuilder('Magento\Cms\Model\Resource\Block\Collection') - ->setConstructorArgs($arguments) - ->setMethods(['addFilter', '_translateCondition', 'getMainTable']) - ->getMock(); - } - - public function testAddFieldToFilterSore() - { - $storeId = 1; - $this->collection->expects($this->once()) - ->method('addFilter') - ->with( - $this->equalTo('store'), - $this->equalTo(['in' => [$storeId]]), - $this->equalTo('public') - ); - $this->collection->addFieldToFilter('store_id', $storeId); - } - - public function testAddFieldToFilter() - { - $field = 'title'; - $value = 'test_filter'; - $searchSql = 'sql query'; - - $this->collection->expects($this->once()) - ->method('_translateCondition') - ->with($field, $value) - ->will($this->returnValue($searchSql)); - - $this->select->expects($this->once()) - ->method('where') - ->with( - $this->equalTo($searchSql), - $this->equalTo(null), - $this->equalTo(\Magento\Framework\DB\Select::TYPE_CONDITION) - ); - - $this->collection->addFieldToFilter($field, $value); - } -} diff --git a/app/code/Magento/Cms/Test/Unit/Model/Resource/Page/CollectionTest.php b/app/code/Magento/Cms/Test/Unit/Model/Resource/Page/CollectionTest.php new file mode 100644 index 0000000000000..3ed7babaf1062 --- /dev/null +++ b/app/code/Magento/Cms/Test/Unit/Model/Resource/Page/CollectionTest.php @@ -0,0 +1,63 @@ +collection = $this->objectManager->getObject( + 'Magento\Cms\Model\Resource\Page\Collection', + [ + 'resource' => $this->resource, + 'connection' => $this->connection + ] + ); + } + + public function testAddFieldToFilterStore() + { + $storeId = 1; + + $expectedFilter = new DataObject( + [ + 'field' => 'store', + 'value' => ['in' => [1]], + 'type' => 'public' + ] + ); + + $this->assertSame($this->collection, $this->collection->addFieldToFilter('store_id', $storeId)); + // addition call to make sure that correct value was set to filter + $this->assertEquals($expectedFilter, $this->collection->getFilter('store')); + } + + public function testAddFieldToFilter() + { + $field = 'title'; + $value = 'test_filter'; + $searchSql = 'sql query'; + + $this->connection->expects($this->any())->method('quoteIdentifier')->willReturn($searchSql); + $this->connection->expects($this->any())->method('prepareSqlCondition')->willReturn($searchSql); + + $this->select->expects($this->once()) + ->method('where') + ->with($searchSql, null, \Magento\Framework\DB\Select::TYPE_CONDITION); + + $this->assertSame($this->collection, $this->collection->addFieldToFilter($field, $value)); + } +} diff --git a/app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/Cms/OptionsTest.php b/app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/Cms/OptionsTest.php new file mode 100644 index 0000000000000..37e2e54c25c16 --- /dev/null +++ b/app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/Cms/OptionsTest.php @@ -0,0 +1,123 @@ +systemStoreMock = $this->getMockBuilder('Magento\Store\Model\System\Store') + ->disableOriginalConstructor() + ->getMock(); + + $this->websiteMock = $this->getMock( + 'Magento\Store\Model\Website', + ['getId', 'getName'], + [], + '', + false + ); + + $this->groupMock = $this->getMock('Magento\Store\Model\Group', [], [], '', false); + + $this->storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false); + + $this->escaperMock = $this->getMock('Magento\Framework\Escaper', [], [], '', false); + + $this->options = $objectManager->getObject( + 'Magento\Cms\Ui\Component\Listing\Column\Cms\Options', + [ + 'systemStore' => $this->systemStoreMock, + 'escaper' => $this->escaperMock + ] + ); + } + + public function testToOptionArray() + { + $websiteCollection = [$this->websiteMock]; + $groupCollection = [$this->groupMock]; + $storeCollection = [$this->storeMock]; + + $expectedOptions = [ + [ + 'label' => __('All Store Views'), + 'value' => '0' + ], + [ + 'label' => 'Main Website', + 'value' => [ + [ + 'label' => ' Main Website Store', + 'value' => [ + [ + 'label' => ' Default Store View', + 'value' => '1' + ] + ] + ] + ] + ] + ]; + + $this->systemStoreMock->expects($this->once())->method('getWebsiteCollection')->willReturn($websiteCollection); + $this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn($groupCollection); + $this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn($storeCollection); + + $this->websiteMock->expects($this->atLeastOnce())->method('getId')->willReturn('1'); + $this->websiteMock->expects($this->any())->method('getName')->willReturn('Main Website'); + + $this->groupMock->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn('1'); + $this->groupMock->expects($this->atLeastOnce())->method('getId')->willReturn('1'); + $this->groupMock->expects($this->atLeastOnce())->method('getName')->willReturn('Main Website Store'); + + $this->storeMock->expects($this->atLeastOnce())->method('getGroupId')->willReturn('1'); + $this->storeMock->expects($this->atLeastOnce())->method('getName')->willReturn('Default Store View'); + $this->storeMock->expects($this->atLeastOnce())->method('getId')->willReturn('1'); + + $this->escaperMock->expects($this->atLeastOnce())->method('escapeHtml')->willReturnMap( + [ + ['Default Store View', null, 'Default Store View'], + ['Main Website Store', null, 'Main Website Store'], + ['Main Website', null, 'Main Website'] + ] + ); + + $this->assertEquals($expectedOptions, $this->options->toOptionArray()); + } +} diff --git a/app/code/Magento/Cms/Ui/Component/Listing/Column/Cms/Options.php b/app/code/Magento/Cms/Ui/Component/Listing/Column/Cms/Options.php new file mode 100644 index 0000000000000..f94376305c255 --- /dev/null +++ b/app/code/Magento/Cms/Ui/Component/Listing/Column/Cms/Options.php @@ -0,0 +1,40 @@ +options !== null) { + return $this->options; + } + + $this->currentOptions['All Store Views']['label'] = __('All Store Views'); + $this->currentOptions['All Store Views']['value'] = self::ALL_STORE_VIEWS; + + $this->generateCurrentOptions(); + + $this->options = array_values($this->currentOptions); + + return $this->options; + } +} diff --git a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_block_listing.xml b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_block_listing.xml index c1e9dad73c743..ff1d8285d9c23 100644 --- a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_block_listing.xml +++ b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_block_listing.xml @@ -147,7 +147,7 @@ - Magento\Store\Ui\Component\Listing\Column\Store\Options + Magento\Cms\Ui\Component\Listing\Column\Cms\Options @@ -370,9 +370,10 @@ - Magento_Ui/js/grid/columns/select + Magento_Ui/js/grid/columns/column + ui/grid/cells/html false text left diff --git a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml index 7c027f465769f..230203c34299a 100644 --- a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml +++ b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml @@ -159,7 +159,7 @@ - Magento\Store\Ui\Component\Listing\Column\Store\Options + Magento\Cms\Ui\Component\Listing\Column\Cms\Options diff --git a/app/code/Magento/CmsUrlRewrite/etc/setup/events.xml b/app/code/Magento/CmsUrlRewrite/etc/setup/events.xml new file mode 100644 index 0000000000000..5403719ab7318 --- /dev/null +++ b/app/code/Magento/CmsUrlRewrite/etc/setup/events.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_attribute_edit_product_tab_variations_popup.xml b/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_attribute_edit_product_tab_variations_popup.xml old mode 100644 new mode 100755 index 5f979c8085927..8ffec72e74e4a --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_attribute_edit_product_tab_variations_popup.xml +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_attribute_edit_product_tab_variations_popup.xml @@ -5,6 +5,6 @@ * See COPYING.txt for license details. */ --> - + diff --git a/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_files_index.xml b/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_files_index.xml index 047a056d28d84..aab19bee1d1ae 100644 --- a/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_files_index.xml +++ b/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_files_index.xml @@ -7,7 +7,7 @@ --> - + diff --git a/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_launch.xml b/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_launch.xml index a9f502b6433b2..e39ca884c8c3f 100644 --- a/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_launch.xml +++ b/app/code/Magento/DesignEditor/view/adminhtml/layout/adminhtml_system_design_editor_launch.xml @@ -13,7 +13,7 @@ - + diff --git a/app/code/Magento/GroupedProduct/view/adminhtml/layout/catalog_product_view_type_grouped.xml b/app/code/Magento/GroupedProduct/view/adminhtml/layout/catalog_product_view_type_grouped.xml index d8ba9118949b9..1cfe367c7d69c 100644 --- a/app/code/Magento/GroupedProduct/view/adminhtml/layout/catalog_product_view_type_grouped.xml +++ b/app/code/Magento/GroupedProduct/view/adminhtml/layout/catalog_product_view_type_grouped.xml @@ -10,6 +10,6 @@ - + diff --git a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_preview.xml b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_preview.xml index cb7ac6cb26d42..f4b996bcaa12d 100644 --- a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_preview.xml +++ b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_preview.xml @@ -9,7 +9,7 @@ - + diff --git a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_template_preview.xml b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_template_preview.xml index d468c2a843414..5d6173d564e20 100644 --- a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_template_preview.xml +++ b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_template_preview.xml @@ -9,7 +9,7 @@ - + diff --git a/app/code/Magento/Newsletter/view/frontend/layout/customer_account.xml b/app/code/Magento/Newsletter/view/frontend/layout/customer_account.xml index b2c17400a81e5..e009e753a8bd0 100644 --- a/app/code/Magento/Newsletter/view/frontend/layout/customer_account.xml +++ b/app/code/Magento/Newsletter/view/frontend/layout/customer_account.xml @@ -15,6 +15,5 @@ - diff --git a/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_ordersgrid.xml b/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_ordersgrid.xml index 2798a934f1915..78e295bb5557f 100644 --- a/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_ordersgrid.xml +++ b/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_ordersgrid.xml @@ -15,8 +15,8 @@ - - + + diff --git a/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_view.xml b/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_view.xml index d1a23150b2983..2ea45b4fc1ffb 100644 --- a/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_view.xml +++ b/app/code/Magento/Paypal/view/adminhtml/layout/paypal_billing_agreement_view.xml @@ -18,8 +18,8 @@ - - + + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_transaction_child_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_transaction_child_block.xml index f6281eb9fd04a..f937a16420e78 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_transaction_child_block.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_transaction_child_block.xml @@ -59,6 +59,6 @@ - + diff --git a/app/code/Magento/Sales/view/frontend/layout/checkout_index_index.xml b/app/code/Magento/Sales/view/frontend/layout/checkout_index_index.xml index a9d1349d10f68..a61c83d274f16 100644 --- a/app/code/Magento/Sales/view/frontend/layout/checkout_index_index.xml +++ b/app/code/Magento/Sales/view/frontend/layout/checkout_index_index.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php b/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php index 4cbef52f9fc6c..d55c1f620f007 100644 --- a/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php +++ b/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php @@ -33,6 +33,11 @@ class Options implements OptionSourceInterface */ protected $options; + /** + * @var array + */ + protected $currentOptions = []; + /** * Constructor * @@ -55,11 +60,24 @@ public function toOptionArray() if ($this->options !== null) { return $this->options; } + + $this->generateCurrentOptions(); + + $this->options = array_values($this->currentOptions); + + return $this->options; + } + + /** + * Generate current options + * + * @return void + */ + protected function generateCurrentOptions() + { $websiteCollection = $this->systemStore->getWebsiteCollection(); $groupCollection = $this->systemStore->getGroupCollection(); $storeCollection = $this->systemStore->getStoreCollection(); - - $currentOptions = []; /** @var \Magento\Store\Model\Website $website */ foreach ($websiteCollection as $website) { $groups = []; @@ -84,12 +102,9 @@ public function toOptionArray() } if (!empty($groups)) { $name = $this->escaper->escapeHtml($website->getName()); - $currentOptions[$name]['label'] = $name; - $currentOptions[$name]['value'] = array_values($groups); + $this->currentOptions[$name]['label'] = $name; + $this->currentOptions[$name]['value'] = array_values($groups); } } - $this->options = array_values($currentOptions); - - return $this->options; } } diff --git a/app/code/Magento/Swatches/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml b/app/code/Magento/Swatches/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml old mode 100644 new mode 100755 index bac339489c98f..3f9bfe640b8f1 --- a/app/code/Magento/Swatches/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml +++ b/app/code/Magento/Swatches/view/adminhtml/layout/catalog_product_attribute_edit_popup.xml @@ -5,7 +5,7 @@ * See COPYING.txt for license details. */ --> - + diff --git a/app/code/Magento/Swatches/view/frontend/layout/catalog_product_view_type_configurable.xml b/app/code/Magento/Swatches/view/frontend/layout/catalog_product_view_type_configurable.xml old mode 100644 new mode 100755 index 71bdc2ce6783c..278270a42d0c8 --- a/app/code/Magento/Swatches/view/frontend/layout/catalog_product_view_type_configurable.xml +++ b/app/code/Magento/Swatches/view/frontend/layout/catalog_product_view_type_configurable.xml @@ -10,7 +10,7 @@ - + diff --git a/app/code/Magento/Theme/view/adminhtml/layout/adminhtml_system_design_wysiwyg_files_index.xml b/app/code/Magento/Theme/view/adminhtml/layout/adminhtml_system_design_wysiwyg_files_index.xml index 32bc75a7eda57..5f50ce5eb338d 100644 --- a/app/code/Magento/Theme/view/adminhtml/layout/adminhtml_system_design_wysiwyg_files_index.xml +++ b/app/code/Magento/Theme/view/adminhtml/layout/adminhtml_system_design_wysiwyg_files_index.xml @@ -7,7 +7,7 @@ --> - + diff --git a/app/code/Magento/Theme/view/frontend/layout/print.xml b/app/code/Magento/Theme/view/frontend/layout/print.xml index 3a1b6e54d3e94..a007ffbb9b206 100644 --- a/app/code/Magento/Theme/view/frontend/layout/print.xml +++ b/app/code/Magento/Theme/view/frontend/layout/print.xml @@ -8,9 +8,9 @@ - - - + + + diff --git a/app/design/frontend/Magento/blank/Magento_Checkout/layout/checkout_index_index.xml b/app/design/frontend/Magento/blank/Magento_Checkout/layout/checkout_index_index.xml index bf14f518dd866..9e2266e17b91a 100644 --- a/app/design/frontend/Magento/blank/Magento_Checkout/layout/checkout_index_index.xml +++ b/app/design/frontend/Magento/blank/Magento_Checkout/layout/checkout_index_index.xml @@ -7,12 +7,12 @@ --> - - - - - - - + + + + + + + diff --git a/app/design/frontend/Magento/blank/Magento_Multishipping/layout/multishipping_checkout.xml b/app/design/frontend/Magento/blank/Magento_Multishipping/layout/multishipping_checkout.xml index 9932644c28c8e..e2bf3a4438162 100644 --- a/app/design/frontend/Magento/blank/Magento_Multishipping/layout/multishipping_checkout.xml +++ b/app/design/frontend/Magento/blank/Magento_Multishipping/layout/multishipping_checkout.xml @@ -7,11 +7,11 @@ --> - - - - - - + + + + + + diff --git a/app/design/frontend/Magento/luma/Magento_Theme/layout/default.xml b/app/design/frontend/Magento/luma/Magento_Theme/layout/default.xml index 41178b9cd8dc6..f1033dfd490a4 100644 --- a/app/design/frontend/Magento/luma/Magento_Theme/layout/default.xml +++ b/app/design/frontend/Magento/luma/Magento_Theme/layout/default.xml @@ -23,7 +23,7 @@ - + diff --git a/app/etc/di.xml b/app/etc/di.xml old mode 100644 new mode 100755 index a0e7f103e5aed..ae1df3af1fba0 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -424,7 +424,6 @@ Magento\Framework\View\Layout\Reader\Container Magento\Framework\View\Layout\Reader\Block Magento\Framework\View\Layout\Reader\Move - Magento\Framework\View\Layout\Reader\Remove Magento\Framework\View\Layout\Reader\UiComponent @@ -448,7 +447,6 @@ Magento\Framework\View\Layout\Reader\Container Magento\Framework\View\Layout\Reader\Block Magento\Framework\View\Layout\Reader\Move - Magento\Framework\View\Layout\Reader\Remove Magento\Framework\View\Layout\Reader\UiComponent @@ -467,7 +465,6 @@ Magento\Framework\View\Layout\Reader\Container Magento\Framework\View\Layout\Reader\Block Magento\Framework\View\Layout\Reader\Move - Magento\Framework\View\Layout\Reader\Remove Magento\Framework\View\Layout\Reader\UiComponent @@ -484,7 +481,6 @@ Magento\Framework\View\Layout\Reader\Container Magento\Framework\View\Layout\Reader\Block Magento\Framework\View\Layout\Reader\Move - Magento\Framework\View\Layout\Reader\Remove Magento\Framework\View\Layout\Reader\UiComponent @@ -901,7 +897,6 @@ Magento\Framework\View\Layout\Reader\Container Magento\Framework\View\Layout\Reader\Move - Magento\Framework\View\Layout\Reader\Remove diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Layout/Reader/BlockTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/Layout/Reader/BlockTest.php old mode 100644 new mode 100755 index 4dde9773e60fb..116bc69129a90 --- a/dev/tests/integration/testsuite/Magento/Framework/View/Layout/Reader/BlockTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Layout/Reader/BlockTest.php @@ -61,7 +61,14 @@ public function testInterpretBlockDirective() $resultElementData = $structure->getStructureElementData($this->blockName); $this->assertEquals( - ['group' => 'test.group', 'class' => 'Dummy\Class', 'template' => 'test.phtml', 'ttl' => 3], + [ + Block::ATTRIBUTE_GROUP => 'test.group', + Block::ATTRIBUTE_CLASS => 'Dummy\Class', + Block::ATTRIBUTE_TEMPLATE => 'test.phtml', + Block::ATTRIBUTE_TTL => 3, + Block::ATTRIBUTE_DISPLAY => '', + Block::ATTRIBUTE_ACL => '' + ], $resultElementData['attributes'] ); $this->assertEquals( diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Layout/_files/_layout_update.xml b/dev/tests/integration/testsuite/Magento/Framework/View/Layout/_files/_layout_update.xml old mode 100644 new mode 100755 index 99db6b298d653..51150b0fe56c8 --- a/dev/tests/integration/testsuite/Magento/Framework/View/Layout/_files/_layout_update.xml +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Layout/_files/_layout_update.xml @@ -22,10 +22,10 @@ - - - - + + + + popup.phtml @@ -33,7 +33,7 @@ - + diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php old mode 100644 new mode 100755 index 86be1ce1a2843..3b8d06db7db16 --- a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php @@ -75,11 +75,21 @@ protected function _getLayoutModel($fixtureFile) public function testRenderElement() { $layout = $this->_getLayoutModel('render.xml'); - $this->assertEmpty($layout->renderElement('nonexisting_element')); $this->assertEquals('124', $layout->renderElement('container_one')); $this->assertEquals('12', $layout->renderElement('block_one')); } + /** + * @expectedException \OutOfBoundsException + * @expectedExceptionMessage No element found with ID 'nonexisting_element' + * @magentoAppIsolation enabled + */ + public function testRenderNonExistentElementShouldThrowException() + { + $layout = $this->_getLayoutModel('render.xml'); + $this->assertEmpty($layout->renderElement('nonexisting_element')); + } + /** * Invoke getBlock() while layout is being generated * diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove.xml b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove.xml old mode 100644 new mode 100755 index 55b2f851bb3df..cd906df4586d2 --- a/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove.xml +++ b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove.xml @@ -9,11 +9,11 @@ - - + + - + diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove_broken.xml b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove_broken.xml old mode 100644 new mode 100755 index 1e63211f6690d..5cffdd38799cd --- a/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove_broken.xml +++ b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_directives_test/remove_broken.xml @@ -7,7 +7,7 @@ --> - + test.broken.block diff --git a/dev/tests/integration/testsuite/Magento/Theme/Model/_files/design/frontend/Test/default/Magento_Core/layout_test_handle_main.xml b/dev/tests/integration/testsuite/Magento/Theme/Model/_files/design/frontend/Test/default/Magento_Core/layout_test_handle_main.xml old mode 100644 new mode 100755 index 9b59c31d03704..4e9b9587ed67a --- a/dev/tests/integration/testsuite/Magento/Theme/Model/_files/design/frontend/Test/default/Magento_Core/layout_test_handle_main.xml +++ b/dev/tests/integration/testsuite/Magento/Theme/Model/_files/design/frontend/Test/default/Magento_Core/layout_test_handle_main.xml @@ -7,10 +7,10 @@ --> - - - - + + + + popup.phtml @@ -18,7 +18,7 @@ - + diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php old mode 100644 new mode 100755 index d9a832b66f836..41afe965a83ae --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3824,6 +3824,7 @@ ['Magento\Checkout\Model\Observer', 'corresponding classes in Magento\Checkout\Observer\*'], ['Magento\CurrencySymbol\Model\Observer', 'corresponding classes in Magento\CurrencySymbol\Observer\*'], ['Magento\Catalog\Model\Product\Image\View'], + ['Magento\Framework\View\Layout\Reader\Remove'], ['Magento\Tools\Console\CommandList'], ['Magento\CatalogSearch\Model\Layer\Advanced\CollectionFilter'], ['Magento\CatalogSearch\Model\Layer\Advanced\Context'], diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php old mode 100644 new mode 100755 index cc6253c795d2a..9825140565fa7 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -470,7 +470,11 @@ public function renderElement($name, $useCache = true) { $this->build(); if (!isset($this->_renderElementCache[$name]) || !$useCache) { - $this->_renderElementCache[$name] = $this->renderNonCachedElement($name); + if ($this->displayElement($name)) { + $this->_renderElementCache[$name] = $this->renderNonCachedElement($name); + } else { + return $this->_renderElementCache[$name] = ''; + } } $this->_renderingOutput->setData('output', $this->_renderElementCache[$name]); $this->_eventManager->dispatch( @@ -480,6 +484,25 @@ public function renderElement($name, $useCache = true) return $this->_renderingOutput->getData('output'); } + /** + * Define whether to display element + * Display if 'display' attribute is absent (false, null) or equal true ('1', true, 'true') + * In any other cases - do not display + * + * @param string $name + * @return bool + */ + protected function displayElement($name) + { + $display = $this->structure->getAttribute($name, 'display'); + if ($display === '' || $display === false || $display === null + || filter_var($display, FILTER_VALIDATE_BOOLEAN)) { + + return true; + } + return false; + } + /** * Render non cached element * diff --git a/lib/internal/Magento/Framework/View/Layout/Generator/Block.php b/lib/internal/Magento/Framework/View/Layout/Generator/Block.php old mode 100644 new mode 100755 index d6b0a5b5a11f3..3c52d03868294 --- a/lib/internal/Magento/Framework/View/Layout/Generator/Block.php +++ b/lib/internal/Magento/Framework/View/Layout/Generator/Block.php @@ -205,6 +205,9 @@ protected function generateBlock( if (!empty($attributes['group'])) { $structure->addToParentGroup($elementName, $attributes['group']); } + if (!empty($attributes['display'])) { + $structure->setAttribute($elementName, 'display', $attributes['display']); + } // create block $className = $attributes['class']; diff --git a/lib/internal/Magento/Framework/View/Layout/Reader/Block.php b/lib/internal/Magento/Framework/View/Layout/Reader/Block.php old mode 100644 new mode 100755 index 1ac5fa2d923e0..24a01a4aff785 --- a/lib/internal/Magento/Framework/View/Layout/Reader/Block.php +++ b/lib/internal/Magento/Framework/View/Layout/Reader/Block.php @@ -28,10 +28,27 @@ class Block implements Layout\ReaderInterface const TYPE_ACTION = 'action'; /**#@-*/ + /**#@+ + * Names of block attributes in layout + */ + const ATTRIBUTE_GROUP = 'group'; + const ATTRIBUTE_CLASS = 'class'; + const ATTRIBUTE_TEMPLATE = 'template'; + const ATTRIBUTE_TTL = 'ttl'; + const ATTRIBUTE_DISPLAY = 'display'; + const ATTRIBUTE_ACL = 'acl'; + /**#@-*/ + /** * @var array */ - protected $attributes = ['group', 'class', 'template', 'ttl']; + protected $attributes = [ + self::ATTRIBUTE_GROUP, + self::ATTRIBUTE_CLASS, + self::ATTRIBUTE_TEMPLATE, + self::ATTRIBUTE_TTL, + self::ATTRIBUTE_DISPLAY + ]; /** * @var \Magento\Framework\View\Layout\ScheduledStructure\Helper @@ -135,7 +152,7 @@ protected function scheduleBlock( $currentElement->getParent() ); $data = $scheduledStructure->getStructureElementData($elementName, []); - $data['attributes'] = $this->getAttributes($currentElement); + $data['attributes'] = $this->mergeBlockAttributes($data, $currentElement); $this->updateScheduledData($currentElement, $data); $this->evaluateArguments($currentElement, $data); $scheduledStructure->setStructureElementData($elementName, $data); @@ -146,6 +163,35 @@ protected function scheduleBlock( } } + /** + * Merge Block attributes + * + * @param array $elementData + * @param \Magento\Framework\View\Layout\Element $currentElement + * @return array + */ + protected function mergeBlockAttributes(array $elementData, Layout\Element $currentElement) + { + if (isset($elementData['attributes'])) { + $keys = array_keys($elementData['attributes']); + foreach ($keys as $key) { + if (isset($currentElement[$key])) { + $elementData['attributes'][$key] = (string)$currentElement[$key]; + } + } + } else { + $elementData['attributes'] = [ + self::ATTRIBUTE_CLASS => (string)$currentElement[self::ATTRIBUTE_CLASS], + self::ATTRIBUTE_GROUP => (string)$currentElement[self::ATTRIBUTE_GROUP], + self::ATTRIBUTE_TEMPLATE => (string)$currentElement[self::ATTRIBUTE_TEMPLATE], + self::ATTRIBUTE_TTL => (string)$currentElement[self::ATTRIBUTE_TTL], + self::ATTRIBUTE_DISPLAY => (string)$currentElement[self::ATTRIBUTE_DISPLAY], + self::ATTRIBUTE_ACL => (string)$currentElement[self::ATTRIBUTE_ACL], + ]; + } + return $elementData['attributes']; + } + /** * Schedule reference data * @@ -158,10 +204,16 @@ protected function scheduleReference( Layout\Element $currentElement ) { $elementName = $currentElement->getAttribute('name'); - $data = $scheduledStructure->getStructureElementData($elementName, []); - $this->updateScheduledData($currentElement, $data); - $this->evaluateArguments($currentElement, $data); - $scheduledStructure->setStructureElementData($elementName, $data); + $elementRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN); + if ($elementRemove) { + $scheduledStructure->setElementToRemoveList($elementName); + } else { + $data = $scheduledStructure->getStructureElementData($elementName, []); + $data['attributes'] = $this->mergeBlockAttributes($data, $currentElement); + $this->updateScheduledData($currentElement, $data); + $this->evaluateArguments($currentElement, $data); + $scheduledStructure->setStructureElementData($elementName, $data); + } } /** @@ -275,6 +327,7 @@ protected function parseArguments(Layout\Element $node) * * @param Layout\Element $blockElement * @param array $data + * @return void */ protected function evaluateArguments(Layout\Element $blockElement, array &$data) { diff --git a/lib/internal/Magento/Framework/View/Layout/Reader/Container.php b/lib/internal/Magento/Framework/View/Layout/Reader/Container.php old mode 100644 new mode 100755 index c6c8a643c3c12..3803af8840d57 --- a/lib/internal/Magento/Framework/View/Layout/Reader/Container.php +++ b/lib/internal/Magento/Framework/View/Layout/Reader/Container.php @@ -26,6 +26,7 @@ class Container implements Layout\ReaderInterface const CONTAINER_OPT_HTML_CLASS = 'htmlClass'; const CONTAINER_OPT_HTML_ID = 'htmlId'; const CONTAINER_OPT_LABEL = 'label'; + const CONTAINER_OPT_DISPLAY = 'display'; /**#@-*/ /** @@ -81,7 +82,7 @@ public function interpret(Context $readerContext, Layout\Element $currentElement break; case self::TYPE_REFERENCE_CONTAINER: - $this->mergeContainerAttributes($readerContext->getScheduledStructure(), $currentElement); + $this->containerReference($readerContext->getScheduledStructure(), $currentElement); break; default: @@ -118,8 +119,33 @@ protected function mergeContainerAttributes( self::CONTAINER_OPT_HTML_ID => (string)$currentElement[self::CONTAINER_OPT_HTML_ID], self::CONTAINER_OPT_HTML_CLASS => (string)$currentElement[self::CONTAINER_OPT_HTML_CLASS], self::CONTAINER_OPT_LABEL => (string)$currentElement[self::CONTAINER_OPT_LABEL], + self::CONTAINER_OPT_DISPLAY => (string)$currentElement[self::CONTAINER_OPT_DISPLAY], ]; } $scheduledStructure->setStructureElementData($containerName, $elementData); } + + /** + * Handling reference of container + * + * If attribute remove="true" then add the element to list remove, + * else merge container attributes + * + * @param Layout\ScheduledStructure $scheduledStructure + * @param Layout\Element $currentElement + * @return void + */ + protected function containerReference( + Layout\ScheduledStructure $scheduledStructure, + Layout\Element $currentElement + ) { + $containerName = $currentElement->getAttribute('name'); + $containerRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN); + + if ($containerRemove) { + $scheduledStructure->setElementToRemoveList($containerName); + } else { + $this->mergeContainerAttributes($scheduledStructure, $currentElement); + } + } } diff --git a/lib/internal/Magento/Framework/View/Layout/Reader/Remove.php b/lib/internal/Magento/Framework/View/Layout/Reader/Remove.php deleted file mode 100644 index 6ae075a6c0ac2..0000000000000 --- a/lib/internal/Magento/Framework/View/Layout/Reader/Remove.php +++ /dev/null @@ -1,42 +0,0 @@ -getScheduledStructure(); - $scheduledStructure->setElementToRemoveList((string)$currentElement->getAttribute('name')); - return $this; - } -} diff --git a/lib/internal/Magento/Framework/View/Layout/ScheduledStructure.php b/lib/internal/Magento/Framework/View/Layout/ScheduledStructure.php index 41bcaf682e14c..90ebb4ba60dd2 100644 --- a/lib/internal/Magento/Framework/View/Layout/ScheduledStructure.php +++ b/lib/internal/Magento/Framework/View/Layout/ScheduledStructure.php @@ -15,56 +15,56 @@ class ScheduledStructure * * @var array */ - protected $_scheduledStructure; + protected $scheduledStructure = []; /** * Scheduled structure data * * @var array */ - protected $_scheduledData; + protected $scheduledData = []; /** * Full information about elements to be populated in the layout structure after generating structure * * @var array */ - protected $_scheduledElements; + protected $scheduledElements = []; /** * Scheduled structure elements moves * * @var array */ - protected $_scheduledMoves; + protected $scheduledMoves = []; /** * Scheduled structure elements removes * * @var array */ - protected $_scheduledRemoves; + protected $scheduledRemoves = []; /** * Scheduled structure elements with ifconfig attribute * * @var array */ - protected $_scheduledIfconfig; + protected $scheduledIfconfig = []; /** * Materialized paths for overlapping workaround of scheduled structural elements * * @var array */ - protected $_scheduledPaths; + protected $scheduledPaths = []; /** * Elements with reference to non-existing parent element * * @var array */ - protected $_brokenParent = []; + protected $brokenParent = []; /** * @param array $data @@ -73,13 +73,13 @@ class ScheduledStructure */ public function __construct(array $data = []) { - $this->_scheduledStructure = isset($data['scheduledStructure']) ? $data['scheduledStructure'] : []; - $this->_scheduledData = isset($data['scheduledData']) ? $data['scheduledData'] : []; - $this->_scheduledElements = isset($data['scheduledElements']) ? $data['scheduledElements'] : []; - $this->_scheduledMoves = isset($data['scheduledMoves']) ? $data['scheduledMoves'] : []; - $this->_scheduledRemoves = isset($data['scheduledRemoves']) ? $data['scheduledRemoves'] : []; - $this->_scheduledIfconfig = isset($data['scheduledIfconfig']) ? $data['scheduledIfconfig'] : []; - $this->_scheduledPaths = isset($data['scheduledPaths']) ? $data['scheduledPaths'] : []; + $this->scheduledStructure = isset($data['scheduledStructure']) ? $data['scheduledStructure'] : []; + $this->scheduledData = isset($data['scheduledData']) ? $data['scheduledData'] : []; + $this->scheduledElements = isset($data['scheduledElements']) ? $data['scheduledElements'] : []; + $this->scheduledMoves = isset($data['scheduledMoves']) ? $data['scheduledMoves'] : []; + $this->scheduledRemoves = isset($data['scheduledRemoves']) ? $data['scheduledRemoves'] : []; + $this->scheduledIfconfig = isset($data['scheduledIfconfig']) ? $data['scheduledIfconfig'] : []; + $this->scheduledPaths = isset($data['scheduledPaths']) ? $data['scheduledPaths'] : []; } /** @@ -89,7 +89,7 @@ public function __construct(array $data = []) */ public function getListToMove() { - return array_keys(array_intersect_key($this->_scheduledElements, $this->_scheduledMoves)); + return array_keys(array_intersect_key($this->scheduledElements, $this->scheduledMoves)); } /** @@ -99,7 +99,10 @@ public function getListToMove() */ public function getListToRemove() { - return array_keys(array_intersect_key($this->_scheduledElements, $this->_scheduledRemoves)); + return array_keys(array_intersect_key( + $this->scheduledElements, + array_merge($this->scheduledRemoves, $this->brokenParent) + )); } /** @@ -109,7 +112,7 @@ public function getListToRemove() */ public function getIfconfigList() { - return array_keys(array_intersect_key($this->_scheduledElements, $this->_scheduledIfconfig)); + return array_keys(array_intersect_key($this->scheduledElements, $this->scheduledIfconfig)); } /** @@ -119,7 +122,7 @@ public function getIfconfigList() */ public function getElements() { - return $this->_scheduledElements; + return $this->scheduledElements; } /** @@ -131,7 +134,7 @@ public function getElements() */ public function getElement($elementName, $default = []) { - return $this->hasElement($elementName) ? $this->_scheduledElements[$elementName] : $default; + return $this->hasElement($elementName) ? $this->scheduledElements[$elementName] : $default; } /** @@ -141,7 +144,7 @@ public function getElement($elementName, $default = []) */ public function isElementsEmpty() { - return empty($this->_scheduledElements); + return empty($this->scheduledElements); } /** @@ -153,7 +156,7 @@ public function isElementsEmpty() */ public function setElement($elementName, array $data) { - $this->_scheduledElements[$elementName] = $data; + $this->scheduledElements[$elementName] = $data; } /** @@ -164,7 +167,7 @@ public function setElement($elementName, array $data) */ public function hasElement($elementName) { - return isset($this->_scheduledElements[$elementName]); + return isset($this->scheduledElements[$elementName]); } /** @@ -175,7 +178,7 @@ public function hasElement($elementName) */ public function unsetElement($elementName) { - unset($this->_scheduledElements[$elementName]); + unset($this->scheduledElements[$elementName]); } /** @@ -187,7 +190,7 @@ public function unsetElement($elementName) */ public function getElementToMove($elementName, $default = null) { - return isset($this->_scheduledMoves[$elementName]) ? $this->_scheduledMoves[$elementName] : $default; + return isset($this->scheduledMoves[$elementName]) ? $this->scheduledMoves[$elementName] : $default; } /** @@ -199,7 +202,7 @@ public function getElementToMove($elementName, $default = null) */ public function getIfconfigElement($elementName, $default = null) { - return isset($this->_scheduledIfconfig[$elementName]) ? $this->_scheduledIfconfig[$elementName] : $default; + return isset($this->scheduledIfconfig[$elementName]) ? $this->scheduledIfconfig[$elementName] : $default; } /** @@ -211,7 +214,7 @@ public function getIfconfigElement($elementName, $default = null) */ public function setElementToMove($elementName, array $data) { - $this->_scheduledMoves[$elementName] = $data; + $this->scheduledMoves[$elementName] = $data; } /** @@ -222,7 +225,7 @@ public function setElementToMove($elementName, array $data) */ public function unsetElementFromListToRemove($elementName) { - unset($this->_scheduledRemoves[$elementName]); + unset($this->scheduledRemoves[$elementName]); } /** @@ -233,7 +236,7 @@ public function unsetElementFromListToRemove($elementName) */ public function setElementToRemoveList($elementName) { - $this->_scheduledRemoves[$elementName] = 1; + $this->scheduledRemoves[$elementName] = 1; } /** @@ -244,7 +247,7 @@ public function setElementToRemoveList($elementName) */ public function unsetElementFromIfconfigList($elementName) { - unset($this->_scheduledIfconfig[$elementName]); + unset($this->scheduledIfconfig[$elementName]); } /** @@ -257,7 +260,7 @@ public function unsetElementFromIfconfigList($elementName) */ public function setElementToIfconfigList($elementName, $configPath, $scopeType) { - $this->_scheduledIfconfig[$elementName] = [$configPath, $scopeType]; + $this->scheduledIfconfig[$elementName] = [$configPath, $scopeType]; } /** @@ -267,7 +270,7 @@ public function setElementToIfconfigList($elementName, $configPath, $scopeType) */ public function getStructure() { - return $this->_scheduledStructure; + return $this->scheduledStructure; } /** @@ -279,7 +282,7 @@ public function getStructure() */ public function getStructureElement($elementName, $default = null) { - return $this->hasStructureElement($elementName) ? $this->_scheduledStructure[$elementName] : $default; + return $this->hasStructureElement($elementName) ? $this->scheduledStructure[$elementName] : $default; } /** @@ -289,7 +292,7 @@ public function getStructureElement($elementName, $default = null) */ public function isStructureEmpty() { - return empty($this->_scheduledStructure); + return empty($this->scheduledStructure); } /** @@ -300,7 +303,7 @@ public function isStructureEmpty() */ public function hasStructureElement($elementName) { - return isset($this->_scheduledStructure[$elementName]); + return isset($this->scheduledStructure[$elementName]); } /** @@ -312,7 +315,7 @@ public function hasStructureElement($elementName) */ public function setStructureElement($elementName, array $data) { - $this->_scheduledStructure[$elementName] = $data; + $this->scheduledStructure[$elementName] = $data; } /** @@ -323,8 +326,8 @@ public function setStructureElement($elementName, array $data) */ public function unsetStructureElement($elementName) { - unset($this->_scheduledStructure[$elementName]); - unset($this->_scheduledData[$elementName]); + unset($this->scheduledStructure[$elementName]); + unset($this->scheduledData[$elementName]); } /** @@ -336,7 +339,7 @@ public function unsetStructureElement($elementName) */ public function getStructureElementData($elementName, $default = null) { - return isset($this->_scheduledData[$elementName]) ? $this->_scheduledData[$elementName] : $default; + return isset($this->scheduledData[$elementName]) ? $this->scheduledData[$elementName] : $default; } /** @@ -348,7 +351,7 @@ public function getStructureElementData($elementName, $default = null) */ public function setStructureElementData($elementName, array $data) { - $this->_scheduledData[$elementName] = $data; + $this->scheduledData[$elementName] = $data; } /** @@ -358,7 +361,7 @@ public function setStructureElementData($elementName, array $data) */ public function getPaths() { - return $this->_scheduledPaths; + return $this->scheduledPaths; } /** @@ -370,7 +373,7 @@ public function getPaths() */ public function getPath($elementName, $default = null) { - return $this->hasPath($elementName) ? $this->_scheduledPaths[$elementName] : $default; + return $this->hasPath($elementName) ? $this->scheduledPaths[$elementName] : $default; } /** @@ -381,7 +384,7 @@ public function getPath($elementName, $default = null) */ public function hasPath($elementName) { - return isset($this->_scheduledPaths[$elementName]); + return isset($this->scheduledPaths[$elementName]); } /** @@ -393,7 +396,7 @@ public function hasPath($elementName) */ public function setPathElement($elementName, $data) { - $this->_scheduledPaths[$elementName] = $data; + $this->scheduledPaths[$elementName] = $data; } /** @@ -404,7 +407,7 @@ public function setPathElement($elementName, $data) */ public function unsetPathElement($elementName) { - unset($this->_scheduledPaths[$elementName]); + unset($this->scheduledPaths[$elementName]); } /** @@ -415,7 +418,7 @@ public function unsetPathElement($elementName) */ public function unsetElementFromBrokenParentList($elementName) { - unset($this->_brokenParent[$elementName]); + unset($this->brokenParent[$elementName]); } /** @@ -426,7 +429,7 @@ public function unsetElementFromBrokenParentList($elementName) */ public function setElementToBrokenParentList($elementName) { - $this->_brokenParent[$elementName] = 1; + $this->brokenParent[$elementName] = 1; } /** @@ -436,7 +439,7 @@ public function setElementToBrokenParentList($elementName) */ public function flushPaths() { - $this->_scheduledPaths = []; + $this->scheduledPaths = []; } /** @@ -447,7 +450,7 @@ public function flushPaths() public function flushScheduledStructure() { $this->flushPaths(); - $this->_scheduledElements = []; - $this->_scheduledStructure = []; + $this->scheduledElements = []; + $this->scheduledStructure = []; } } diff --git a/lib/internal/Magento/Framework/View/Layout/etc/body.xsd b/lib/internal/Magento/Framework/View/Layout/etc/body.xsd old mode 100644 new mode 100755 index 3b187137d61fc..94922875f16a2 --- a/lib/internal/Magento/Framework/View/Layout/etc/body.xsd +++ b/lib/internal/Magento/Framework/View/Layout/etc/body.xsd @@ -15,7 +15,6 @@ - diff --git a/lib/internal/Magento/Framework/View/Layout/etc/elements.xsd b/lib/internal/Magento/Framework/View/Layout/etc/elements.xsd old mode 100644 new mode 100755 index fc44f93df682b..2170a38073384 --- a/lib/internal/Magento/Framework/View/Layout/etc/elements.xsd +++ b/lib/internal/Magento/Framework/View/Layout/etc/elements.xsd @@ -314,6 +314,8 @@ + + @@ -329,6 +331,8 @@ + + diff --git a/lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd b/lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd old mode 100644 new mode 100755 index a9f0432bfc4be..a584c5403d9af --- a/lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd +++ b/lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd @@ -15,7 +15,6 @@ - diff --git a/lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd b/lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd old mode 100644 new mode 100755 index 4f6c8603fecb9..d0012ffbd0f50 --- a/lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd +++ b/lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd @@ -13,7 +13,6 @@ - diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/BlockTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/BlockTest.php old mode 100644 new mode 100755 index 86570f82f9d3c..b1fe7bd1ddb62 --- a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/BlockTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/BlockTest.php @@ -9,10 +9,12 @@ */ namespace Magento\Framework\View\Test\Unit\Layout\Reader; +use Magento\Framework\View\Layout\Reader\Block; + /** * Class BlockTest * - * @covers \Magento\Framework\View\Layout\Reader\Block + * @covers Block */ class BlockTest extends \PHPUnit_Framework_TestCase { @@ -43,9 +45,9 @@ class BlockTest extends \PHPUnit_Framework_TestCase */ protected function getElement($xml, $elementType) { - $xml = '<' . \Magento\Framework\View\Layout\Reader\Block::TYPE_BLOCK . '>' + $xml = '<' . Block::TYPE_BLOCK . '>' . $xml - . ''; + . ''; $xml = simplexml_load_string($xml, 'Magento\Framework\View\Layout\Element'); return $xml->{$elementType}; @@ -67,7 +69,7 @@ protected function prepareReaderPool($xml, $elementType) * Return testing instance of block * * @param array $arguments - * @return \Magento\Framework\View\Layout\Reader\Block + * @return Block */ protected function getBlock(array $arguments) { @@ -129,10 +131,12 @@ public function testProcessBlock( $literal, [ 'attributes' => [ - 'group' => '', - 'class' => '', - 'template' => '', - 'ttl' => '', + Block::ATTRIBUTE_GROUP => '', + Block::ATTRIBUTE_CLASS => '', + Block::ATTRIBUTE_TEMPLATE => '', + Block::ATTRIBUTE_TTL => '', + Block::ATTRIBUTE_DISPLAY => '', + Block::ATTRIBUTE_ACL => '' ], 'actions' => [ ['someMethod', [], 'action_config_path', 'scope'], @@ -176,18 +180,26 @@ public function processBlockDataProvider() /** * @param string $literal + * @param string $remove * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $getCondition * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setCondition + * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setRemoveCondition * @dataProvider processReferenceDataProvider */ public function testProcessReference( $literal, + $remove, $getCondition, - $setCondition + $setCondition, + $setRemoveCondition ) { $this->context->expects($this->once())->method('getScheduledStructure') ->will($this->returnValue($this->scheduledStructure)); + $this->scheduledStructure->expects($setRemoveCondition) + ->method('setElementToRemoveList') + ->with($literal); + $this->scheduledStructure->expects($getCondition) ->method('getStructureElementData') ->with($literal, []) @@ -205,11 +217,19 @@ public function testProcessReference( ['someMethod', [], 'action_config_path', 'scope'], ], 'arguments' => [], + 'attributes' => [ + Block::ATTRIBUTE_GROUP => '', + Block::ATTRIBUTE_CLASS => '', + Block::ATTRIBUTE_TEMPLATE => '', + Block::ATTRIBUTE_TTL => '', + Block::ATTRIBUTE_DISPLAY => '', + Block::ATTRIBUTE_ACL => '' + ] ] ); $this->prepareReaderPool( - '<' . $literal . ' name="' . $literal . '">' + '<' . $literal . ' name="' . $literal . '" remove="' . $remove . '">' . '' . '', $literal @@ -231,8 +251,10 @@ public function testProcessReference( public function processReferenceDataProvider() { return [ - ['referenceBlock', $this->once(), $this->once()], - ['page', $this->never(), $this->never()] + ['referenceBlock', 'false', $this->once(), $this->once(), $this->never()], + ['referenceBlock', 'true', $this->never(), $this->never(), $this->once()], + ['page', 'false', $this->never(), $this->never(), $this->never()], + ['page', 'true', $this->never(), $this->never(), $this->never()], ]; } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/ContainerTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/ContainerTest.php old mode 100644 new mode 100755 index 2f90f4c1b1f23..67ca5239018c6 --- a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/ContainerTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/ContainerTest.php @@ -56,6 +56,9 @@ protected function setUp() * @param string $containerName * @param array $structureElement * @param array $expectedData + * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $getStructureCondition + * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setStructureCondition + * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setRemoveCondition * * @dataProvider processDataProvider */ @@ -63,21 +66,27 @@ public function testProcess( $elementCurrent, $containerName, $structureElement, - $expectedData + $expectedData, + $getStructureCondition, + $setStructureCondition, + $setRemoveCondition ) { /** @var ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructureMock */ $scheduledStructureMock = $this->getMockBuilder('Magento\Framework\View\Layout\ScheduledStructure') ->disableOriginalConstructor()->getMock(); - $scheduledStructureMock->expects($this->once()) + $scheduledStructureMock->expects($getStructureCondition) ->method('getStructureElementData') ->with($containerName) ->willReturn($structureElement); - $scheduledStructureMock->expects($this->once()) + $scheduledStructureMock->expects($setStructureCondition) ->method('setStructureElementData') ->with($containerName, $expectedData) ->willReturnSelf(); + $scheduledStructureMock->expects($setRemoveCondition) + ->method('setElementToRemoveList') + ->with($containerName); - /** @var Context|\PHPUnit_Framework_MockObject_MockObject $contextMock */ + /** @var \Magento\Framework\View\Layout\Reader\Context|\PHPUnit_Framework_MockObject_MockObject $contextMock */ $contextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context') ->disableOriginalConstructor()->getMock(); $contextMock->expects($this->any()) @@ -98,6 +107,7 @@ public function testProcess( /** * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function processDataProvider() { @@ -122,6 +132,9 @@ public function processDataProvider() 'unchanged' => 'unchanged_value', ], ], + 'getStructureCondition' => $this->once(), + 'setStructureCondition' => $this->once(), + 'setRemoveCondition' => $this->never(), ], 'referenceContainer' => [ 'elementCurrent' => $this->getElement( @@ -136,8 +149,77 @@ public function processDataProvider() Container::CONTAINER_OPT_HTML_ID => 'id_add', Container::CONTAINER_OPT_HTML_CLASS => 'new', Container::CONTAINER_OPT_LABEL => 'Add', + Container::CONTAINER_OPT_DISPLAY => null, ], ], + 'getStructureCondition' => $this->once(), + 'setStructureCondition' => $this->once(), + 'setRemoveCondition' => $this->never(), + ], + 'referenceContainerNoRemove' => [ + 'elementCurrent' => $this->getElement( + '', + 'referenceContainer' + ), + 'containerName' => 'reference', + 'structureElement' => [], + 'expectedData' => [ + 'attributes' => [ + Container::CONTAINER_OPT_HTML_TAG => null, + Container::CONTAINER_OPT_HTML_ID => null, + Container::CONTAINER_OPT_HTML_CLASS => null, + Container::CONTAINER_OPT_LABEL => null, + Container::CONTAINER_OPT_DISPLAY => null, + ], + ], + 'getStructureCondition' => $this->once(), + 'setStructureCondition' => $this->once(), + 'setRemoveCondition' => $this->never(), + ], + 'referenceContainerRemove' => [ + 'elementCurrent' => $this->getElement( + '', + 'referenceContainer' + ), + 'containerName' => 'reference', + 'structureElement' => [], + 'expectedData' => [], + 'getStructureCondition' => $this->never(), + 'setStructureCondition' => $this->never(), + 'setRemoveCondition' => $this->once(), + ], + 'referenceContainerRemove2' => [ + 'elementCurrent' => $this->getElement( + '', + 'referenceContainer' + ), + 'containerName' => 'reference', + 'structureElement' => [], + 'expectedData' => [], + 'getStructureCondition' => $this->never(), + 'setStructureCondition' => $this->never(), + 'setRemoveCondition' => $this->once(), + ], + 'referenceContainerDisplayFalse' => [ + 'elementCurrent' => $this->getElement( + '', + 'referenceContainer' + ), + 'containerName' => 'reference', + 'structureElement' => [], + 'expectedData' => [ + 'attributes' => [ + Container::CONTAINER_OPT_HTML_TAG => 'span', + Container::CONTAINER_OPT_HTML_ID => 'id_add', + Container::CONTAINER_OPT_HTML_CLASS => 'new', + Container::CONTAINER_OPT_LABEL => 'Add', + Container::CONTAINER_OPT_DISPLAY => 'true', + ], + ], + 'getStructureCondition' => $this->once(), + 'setStructureCondition' => $this->once(), + 'setRemoveCondition' => $this->never(), ] ]; } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/RemoveTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/RemoveTest.php deleted file mode 100644 index 0c0588ecd5430..0000000000000 --- a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/RemoveTest.php +++ /dev/null @@ -1,74 +0,0 @@ -context = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context') - ->disableOriginalConstructor() - ->getMock(); - $this->scheduledStructure = $this->getMockBuilder('Magento\Framework\View\Layout\ScheduledStructure') - ->disableOriginalConstructor()->setMethods(['setElementToRemoveList', '__wakeup']) - ->getMock(); - $this->model = new Remove(); - } - - public function testGetSupportedNodes() - { - $data[] = \Magento\Framework\View\Layout\Reader\Remove::TYPE_REMOVE; - $this->assertEquals($data, $this->model->getSupportedNodes()); - } - - /** - * @dataProvider processDataProvider - */ - public function testProcess($xml) - { - $this->element = new \Magento\Framework\View\Layout\Element($xml); - $this->context->expects($this->any()) - ->method('getScheduledStructure') - ->will($this->returnValue($this->scheduledStructure)); - $this->scheduledStructure->expects($this->once())->method('setElementToRemoveList')->with('header'); - $this->model->interpret($this->context, $this->element, $this->element); - } - - public function processDataProvider() - { - return [ - [ - '', - ] - ]; - } -} diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Layout/ReaderPoolTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Layout/ReaderPoolTest.php old mode 100644 new mode 100755 index 884b941bf6191..83a1500dd4a33 --- a/lib/internal/Magento/Framework/View/Test/Unit/Layout/ReaderPoolTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Layout/ReaderPoolTest.php @@ -29,10 +29,7 @@ protected function setUp() 'Magento\Framework\View\Layout\ReaderPool', [ 'readerFactory' => $this->readerFactoryMock, - 'readers' => [ - 'move' => 'Magento\Framework\View\Layout\Reader\Move', - 'remove' => 'Magento\Framework\View\Layout\Reader\Remove', - ] + 'readers' => ['move' => 'Magento\Framework\View\Layout\Reader\Move'] ] ); } @@ -57,25 +54,9 @@ public function testInterpret() $moveReaderMock->method('getSupportedNodes') ->willReturn(['move']); - /** - * @var \Magento\Framework\View\Layout\Reader\Remove|\PHPUnit_Framework_MockObject_MockObject $removeReaderMock - */ - $removeReaderMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Remove') - ->disableOriginalConstructor()->getMock(); - $removeReaderMock->expects($this->exactly(2))->method('interpret') - ->with() - ->willReturn($this->returnSelf()); - $removeReaderMock->method('getSupportedNodes') - ->willReturn(['remove']); - - $this->readerFactoryMock->expects($this->exactly(2)) + $this->readerFactoryMock->expects($this->once()) ->method('create') - ->will($this->returnValueMap( - [ - ['Magento\Framework\View\Layout\Reader\Move', [], $moveReaderMock], - ['Magento\Framework\View\Layout\Reader\Remove', [], $removeReaderMock], - ] - )); + ->willReturnMap([['Magento\Framework\View\Layout\Reader\Move', [], $moveReaderMock]]); $this->pool->interpret($contextMock, $currentElement); $this->pool->interpret($contextMock, $currentElement); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Layout/ScheduledStructureTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Layout/ScheduledStructureTest.php index de0509c8c6a74..98d8d6a8b1993 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Layout/ScheduledStructureTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Layout/ScheduledStructureTest.php @@ -13,16 +13,16 @@ class ScheduledStructureTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Framework\View\Layout\ScheduledStructure */ - protected $_model; + protected $model; /** * @var array */ - protected $_scheduledData = []; + protected $scheduledData = []; protected function setUp() { - $this->_scheduledData = [ + $this->scheduledData = [ 'scheduledStructure' => [ 'element1' => ['data', 'of', 'element', '1'], 'element2' => ['data', 'of', 'element', '2'], @@ -62,7 +62,7 @@ protected function setUp() 'path4' => 'path 4', ], ]; - $this->_model = new \Magento\Framework\View\Layout\ScheduledStructure($this->_scheduledData); + $this->model = new \Magento\Framework\View\Layout\ScheduledStructure($this->scheduledData); } /** @@ -74,7 +74,7 @@ public function testGetListToMove() * Only elements that are present in elements list and specified in list to move can be moved */ $expected = ['element1', 'element4']; - $this->assertEquals($expected, $this->_model->getListToMove()); + $this->assertEquals($expected, $this->model->getListToMove()); } /** @@ -86,13 +86,13 @@ public function testGetListToRemove() * Only elements that are present in elements list and specified in list to remove can be removed */ $expected = ['element2', 'element3']; - $this->assertEquals($expected, $this->_model->getListToRemove()); + $this->assertEquals($expected, $this->model->getListToRemove()); } public function testGetIfconfigList() { $expected = ['element1', 'element4']; - $this->assertEquals($expected, $this->_model->getIfconfigList()); + $this->assertEquals($expected, $this->model->getIfconfigList()); } /** @@ -100,7 +100,7 @@ public function testGetIfconfigList() */ public function testGetElements() { - $this->assertEquals($this->_scheduledData['scheduledElements'], $this->_model->getElements()); + $this->assertEquals($this->scheduledData['scheduledElements'], $this->model->getElements()); } /** @@ -108,11 +108,11 @@ public function testGetElements() */ public function testGetElement() { - $expected = $this->_scheduledData['scheduledElements']['element2']; - $this->assertEquals($expected, $this->_model->getElement('element2')); + $expected = $this->scheduledData['scheduledElements']['element2']; + $this->assertEquals($expected, $this->model->getElement('element2')); $default = ['some', 'default', 'value']; - $this->assertEquals($default, $this->_model->getElement('not_existing_element', $default)); + $this->assertEquals($default, $this->model->getElement('not_existing_element', $default)); } /** @@ -120,9 +120,9 @@ public function testGetElement() */ public function testIsElementsEmpty() { - $this->assertFalse($this->_model->isElementsEmpty()); - $this->_model->flushScheduledStructure(); - $this->assertTrue($this->_model->isElementsEmpty()); + $this->assertFalse($this->model->isElementsEmpty()); + $this->model->flushScheduledStructure(); + $this->assertTrue($this->model->isElementsEmpty()); } /** @@ -133,14 +133,14 @@ public function testSetElement() $data = ['some', 'new', 'data']; /** Test add new element */ - $this->assertFalse($this->_model->hasElement('new_element')); - $this->_model->setElement('new_element', $data); - $this->assertEquals($data, $this->_model->getElement('new_element')); + $this->assertFalse($this->model->hasElement('new_element')); + $this->model->setElement('new_element', $data); + $this->assertEquals($data, $this->model->getElement('new_element')); /** Test override existing element */ - $this->assertTrue($this->_model->hasElement('element1')); - $this->_model->setElement('element1', $data); - $this->assertEquals($data, $this->_model->getElement('element1')); + $this->assertTrue($this->model->hasElement('element1')); + $this->model->setElement('element1', $data); + $this->assertEquals($data, $this->model->getElement('element1')); } /** @@ -148,8 +148,8 @@ public function testSetElement() */ public function testHasElement() { - $this->assertFalse($this->_model->hasElement('not_existing_element')); - $this->assertTrue($this->_model->hasElement('element1')); + $this->assertFalse($this->model->hasElement('not_existing_element')); + $this->assertTrue($this->model->hasElement('element1')); } /** @@ -157,9 +157,9 @@ public function testHasElement() */ public function testUnsetElement() { - $this->assertTrue($this->_model->hasElement('element1')); - $this->_model->unsetElement('element1'); - $this->assertFalse($this->_model->hasElement('element1')); + $this->assertTrue($this->model->hasElement('element1')); + $this->model->unsetElement('element1'); + $this->assertFalse($this->model->hasElement('element1')); } /** @@ -168,21 +168,21 @@ public function testUnsetElement() public function testGetElementToMove() { $this->assertEquals( - $this->_scheduledData['scheduledMoves']['element1'], - $this->_model->getElementToMove('element1') + $this->scheduledData['scheduledMoves']['element1'], + $this->model->getElementToMove('element1') ); $default = ['some', 'data']; - $this->assertEquals($default, $this->_model->getElementToMove('not_existing_element', $default)); + $this->assertEquals($default, $this->model->getElementToMove('not_existing_element', $default)); } public function getIfconfigElement() { $this->assertEquals( - $this->_scheduledData['scheduledIfconfig']['element1'], - $this->_model->getIfconfigElement('element1') + $this->scheduledData['scheduledIfconfig']['element1'], + $this->model->getIfconfigElement('element1') ); $default = ['some', 'data']; - $this->assertEquals($default, $this->_model->getIfconfigElement('not_existing_element', $default)); + $this->assertEquals($default, $this->model->getIfconfigElement('not_existing_element', $default)); } /** @@ -193,14 +193,14 @@ public function testSetElementToMove() $data = ['some', 'new', 'data', 'element', 'to', 'move']; /** Test add new element */ - $this->assertFalse($this->_model->hasElement('new_element')); - $this->_model->setElementToMove('new_element', $data); - $this->assertEquals($data, $this->_model->getElementToMove('new_element')); + $this->assertFalse($this->model->hasElement('new_element')); + $this->model->setElementToMove('new_element', $data); + $this->assertEquals($data, $this->model->getElementToMove('new_element')); /** Test override existing element */ - $this->assertNotEquals($data, $this->_model->getElementToMove('element1')); - $this->_model->setElementToMove('element1', $data); - $this->assertEquals($data, $this->_model->getElementToMove('element1')); + $this->assertNotEquals($data, $this->model->getElementToMove('element1')); + $this->model->setElementToMove('element1', $data); + $this->assertEquals($data, $this->model->getElementToMove('element1')); } /** @@ -208,9 +208,9 @@ public function testSetElementToMove() */ public function testUnsetElementFromListToRemove() { - $this->assertContains('element2', $this->_model->getListToRemove()); - $this->_model->unsetElementFromListToRemove('element2'); - $this->assertNotContains('element2', $this->_model->getListToRemove()); + $this->assertContains('element2', $this->model->getListToRemove()); + $this->model->unsetElementFromListToRemove('element2'); + $this->assertNotContains('element2', $this->model->getListToRemove()); } /** @@ -218,23 +218,23 @@ public function testUnsetElementFromListToRemove() */ public function testSetElementToRemoveList() { - $this->assertNotContains('element1', $this->_model->getListToRemove()); - $this->_model->setElementToRemoveList('element1'); - $this->assertContains('element1', $this->_model->getListToRemove()); + $this->assertNotContains('element1', $this->model->getListToRemove()); + $this->model->setElementToRemoveList('element1'); + $this->assertContains('element1', $this->model->getListToRemove()); } public function testUnsetElementFromIfconfigList() { - $this->assertContains('element4', $this->_model->getIfconfigList()); - $this->_model->unsetElementFromIfconfigList('element4'); - $this->assertNotContains('element4', $this->_model->getIfconfigList()); + $this->assertContains('element4', $this->model->getIfconfigList()); + $this->model->unsetElementFromIfconfigList('element4'); + $this->assertNotContains('element4', $this->model->getIfconfigList()); } public function testSetElementToIfconfigList() { - $this->assertNotContains('element5', $this->_model->getIfconfigList()); - $this->_model->setElementToIfconfigList('element5', 'config_path', 'scope'); - $this->assertContains('element5', $this->_model->getIfconfigList()); + $this->assertNotContains('element5', $this->model->getIfconfigList()); + $this->model->setElementToIfconfigList('element5', 'config_path', 'scope'); + $this->assertContains('element5', $this->model->getIfconfigList()); } /** @@ -242,7 +242,7 @@ public function testSetElementToIfconfigList() */ public function testGetStructure() { - $this->assertEquals($this->_scheduledData['scheduledStructure'], $this->_model->getStructure()); + $this->assertEquals($this->scheduledData['scheduledStructure'], $this->model->getStructure()); } /** @@ -250,11 +250,11 @@ public function testGetStructure() */ public function testGetStructureElement() { - $expected = $this->_scheduledData['scheduledStructure']['element2']; - $this->assertEquals($expected, $this->_model->getStructureElement('element2')); + $expected = $this->scheduledData['scheduledStructure']['element2']; + $this->assertEquals($expected, $this->model->getStructureElement('element2')); $default = ['some', 'default', 'value']; - $this->assertEquals($default, $this->_model->getStructureElement('not_existing_element', $default)); + $this->assertEquals($default, $this->model->getStructureElement('not_existing_element', $default)); } /** @@ -262,9 +262,9 @@ public function testGetStructureElement() */ public function testIsStructureEmpty() { - $this->assertFalse($this->_model->isStructureEmpty()); - $this->_model->flushScheduledStructure(); - $this->assertTrue($this->_model->isStructureEmpty()); + $this->assertFalse($this->model->isStructureEmpty()); + $this->model->flushScheduledStructure(); + $this->assertTrue($this->model->isStructureEmpty()); } /** @@ -272,8 +272,8 @@ public function testIsStructureEmpty() */ public function testHasStructureElement() { - $this->assertTrue($this->_model->hasStructureElement('element1')); - $this->assertFalse($this->_model->hasStructureElement('not_existing_element')); + $this->assertTrue($this->model->hasStructureElement('element1')); + $this->assertFalse($this->model->hasStructureElement('not_existing_element')); } /** @@ -284,14 +284,14 @@ public function testSetStructureElement() $data = ['some', 'new', 'data', 'structure', 'element']; /** Test add new structure element */ - $this->assertFalse($this->_model->hasStructureElement('new_element')); - $this->_model->setStructureElement('new_element', $data); - $this->assertEquals($data, $this->_model->getStructureElement('new_element')); + $this->assertFalse($this->model->hasStructureElement('new_element')); + $this->model->setStructureElement('new_element', $data); + $this->assertEquals($data, $this->model->getStructureElement('new_element')); /** Test override existing structure element */ - $this->assertTrue($this->_model->hasStructureElement('element1')); - $this->_model->setStructureElement('element1', $data); - $this->assertEquals($data, $this->_model->getStructureElement('element1')); + $this->assertTrue($this->model->hasStructureElement('element1')); + $this->model->setStructureElement('element1', $data); + $this->assertEquals($data, $this->model->getStructureElement('element1')); } /** @@ -299,9 +299,9 @@ public function testSetStructureElement() */ public function testUnsetStructureElement() { - $this->assertTrue($this->_model->hasStructureElement('element1')); - $this->_model->unsetStructureElement('element1'); - $this->assertFalse($this->_model->hasStructureElement('element1')); + $this->assertTrue($this->model->hasStructureElement('element1')); + $this->model->unsetStructureElement('element1'); + $this->assertFalse($this->model->hasStructureElement('element1')); } /** @@ -309,7 +309,7 @@ public function testUnsetStructureElement() */ public function testGetPaths() { - $this->assertEquals($this->_scheduledData['scheduledPaths'], $this->_model->getPaths()); + $this->assertEquals($this->scheduledData['scheduledPaths'], $this->model->getPaths()); } /** @@ -317,9 +317,9 @@ public function testGetPaths() */ public function testGetPath() { - $this->assertEquals($this->_scheduledData['scheduledPaths']['path1'], $this->_model->getPath('path1')); + $this->assertEquals($this->scheduledData['scheduledPaths']['path1'], $this->model->getPath('path1')); $default = ['some', 'data']; - $this->assertEquals($default, $this->_model->getPath('not_existing_element', $default)); + $this->assertEquals($default, $this->model->getPath('not_existing_element', $default)); } /** @@ -327,8 +327,8 @@ public function testGetPath() */ public function testHasPath() { - $this->assertTrue($this->_model->hasPath('path1')); - $this->assertFalse($this->_model->hasPath('not_existing_element')); + $this->assertTrue($this->model->hasPath('path1')); + $this->assertFalse($this->model->hasPath('not_existing_element')); } /** @@ -339,14 +339,14 @@ public function testSetPathElement() $data = ['some', 'new', 'data', 'path']; /** Test add new structure element */ - $this->assertFalse($this->_model->hasPath('new_element')); - $this->_model->setPathElement('new_element', $data); - $this->assertEquals($data, $this->_model->getPath('new_element')); + $this->assertFalse($this->model->hasPath('new_element')); + $this->model->setPathElement('new_element', $data); + $this->assertEquals($data, $this->model->getPath('new_element')); /** Test override existing structure element */ - $this->assertTrue($this->_model->hasPath('path1')); - $this->_model->setPathElement('path1', $data); - $this->assertEquals($data, $this->_model->getPath('path1')); + $this->assertTrue($this->model->hasPath('path1')); + $this->model->setPathElement('path1', $data); + $this->assertEquals($data, $this->model->getPath('path1')); } /** @@ -354,9 +354,9 @@ public function testSetPathElement() */ public function testUnsetPathElement() { - $this->assertTrue($this->_model->hasPath('path1')); - $this->_model->unsetPathElement('path1'); - $this->assertFalse($this->_model->hasPath('path1')); + $this->assertTrue($this->model->hasPath('path1')); + $this->model->unsetPathElement('path1'); + $this->assertFalse($this->model->hasPath('path1')); } /** @@ -364,9 +364,9 @@ public function testUnsetPathElement() */ public function testFlushPaths() { - $this->assertNotEmpty($this->_model->getPaths()); - $this->_model->flushPaths(); - $this->assertEmpty($this->_model->getPaths()); + $this->assertNotEmpty($this->model->getPaths()); + $this->model->flushPaths(); + $this->assertEmpty($this->model->getPaths()); } /** @@ -374,15 +374,15 @@ public function testFlushPaths() */ public function testFlushScheduledStructure() { - $this->assertNotEmpty($this->_model->getPaths()); - $this->assertNotEmpty($this->_model->getElements()); - $this->assertNotEmpty($this->_model->getStructure()); + $this->assertNotEmpty($this->model->getPaths()); + $this->assertNotEmpty($this->model->getElements()); + $this->assertNotEmpty($this->model->getStructure()); - $this->_model->flushScheduledStructure(); + $this->model->flushScheduledStructure(); - $this->assertEmpty($this->_model->getPaths()); - $this->assertEmpty($this->_model->getElements()); - $this->assertEmpty($this->_model->getStructure()); + $this->assertEmpty($this->model->getPaths()); + $this->assertEmpty($this->model->getElements()); + $this->assertEmpty($this->model->getStructure()); } /** @@ -393,13 +393,13 @@ public function testSetElementToBrokenParentList() { $element = 'element9'; $expectedToRemove = ['element2', 'element3']; - $expectedToRemoveWithBroken = ['element2', 'element3']; - $this->assertEquals($expectedToRemove, $this->_model->getListToRemove()); + $expectedToRemoveWithBroken = ['element2', 'element3', 'element9']; + $this->assertEquals($expectedToRemove, $this->model->getListToRemove()); - $this->_model->setElementToBrokenParentList($element); - $this->assertEquals($expectedToRemoveWithBroken, $this->_model->getListToRemove()); + $this->model->setElementToBrokenParentList($element); + $this->assertEquals($expectedToRemoveWithBroken, $this->model->getListToRemove()); - $this->_model->unsetElementFromBrokenParentList($element); - $this->assertEquals($expectedToRemove, $this->_model->getListToRemove()); + $this->model->unsetElementFromBrokenParentList($element); + $this->assertEquals($expectedToRemove, $this->model->getListToRemove()); } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php old mode 100644 new mode 100755 index 2e98cf8fd5d8c..b40aea316805c --- a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php @@ -831,4 +831,104 @@ public function testGetXml() $xml = ''; $this->assertSame($xml, \Magento\Framework\View\Layout::LAYOUT_NODE); } + + /** + * @param mixed $displayValue + * @dataProvider renderElementDisplayDataProvider + */ + public function testRenderElementDisplay($displayValue) + { + $name = 'test_container'; + $child = 'child_block'; + $children = [$child => true]; + $blockHtml = ''; + + $this->structureMock->expects($this->atLeastOnce()) + ->method('getAttribute') + ->willReturnMap( + [ + [$name, 'display', $displayValue], + [$child, 'display', $displayValue], + [$child, 'type', \Magento\Framework\View\Layout\Element::TYPE_BLOCK] + ] + ); + + $this->structureMock->expects($this->atLeastOnce())->method('hasElement') + ->willReturnMap( + [ + [$child, true] + ] + ); + + $this->structureMock->expects($this->once()) + ->method('getChildren') + ->with($name) + ->willReturn($children); + + $block = $this->getMock('Magento\Framework\View\Element\AbstractBlock', [], [], '', false); + $block->expects($this->once())->method('toHtml')->willReturn($blockHtml); + + $renderingOutput = new \Magento\Framework\DataObject(); + $renderingOutput->setData('output', $blockHtml); + + $this->eventManagerMock->expects($this->at(0)) + ->method('dispatch') + ->with( + 'core_layout_render_element', + ['element_name' => $child, 'layout' => $this->model, 'transport' => $renderingOutput] + ); + $this->eventManagerMock->expects($this->at(1)) + ->method('dispatch') + ->with( + 'core_layout_render_element', + ['element_name' => $name, 'layout' => $this->model, 'transport' => $renderingOutput] + ); + + $this->model->setBlock($child, $block); + $this->assertEquals($blockHtml, $this->model->renderElement($name, false)); + } + + /** + * @param mixed $displayValue + * @dataProvider renderElementDoNotDisplayDataProvider + */ + public function testRenderElementDoNotDisplay($displayValue) + { + $displayValue = 'false'; + $name = 'test_container'; + $blockHtml = ''; + + $this->structureMock->expects($this->atLeastOnce()) + ->method('getAttribute') + ->willReturnMap([[$name, 'display', $displayValue]]); + + $this->assertEquals($blockHtml, $this->model->renderElement($name, false)); + } + + /** + * @return array + */ + public function renderElementDoNotDisplayDataProvider() + { + return [ + ['false'], + ['0'], + [0] + ]; + } + + /** + * @return array + */ + public function renderElementDisplayDataProvider() + { + return [ + [true], + ['1'], + [1], + ['true'], + [false], + [null] + ]; + } }