Skip to content

Migrating Store Grid to UI Components #17371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
* Store render group
*
* @author Magento Core Team <core@magentocommerce.com>
* @deprecated since Store Grid is refactored with UI Components
*/
class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
/**
* {@inheritdoc}
* @inheritdoc
*/
public function render(\Magento\Framework\DataObject $row)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
* Store render store
*
* @author Magento Core Team <core@magentocommerce.com>
* @deprecated since Store Grid is refactored with UI Components
*/
class Store extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
/**
* {@inheritdoc}
* @inheritdoc
*/
public function render(\Magento\Framework\DataObject $row)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
* Store render website
*
* @author Magento Core Team <core@magentocommerce.com>
* @deprecated since Store Grid is refactored with UI Components
*/
class Website extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
/**
* {@inheritdoc}
* @inheritdoc
*/
public function render(\Magento\Framework\DataObject $row)
{
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Backend/Block/System/Store/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @author Magento Core Team <core@magentocommerce.com>
* @api
* @since 100.0.2
* @deprecated since Store Grid is refactored with UI Components
*/
class Store extends \Magento\Backend\Block\Widget\Grid\Container
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="formkey"/>
<update handle="adminhtml_system_store_grid_block"/>
<update handle="styles"/>
<body>
<referenceContainer name="content">
<block class="Magento\Backend\Block\System\Store\Store" name="adminhtml.system.store.container"/>
<uiComponent name="store_listing"/>
</referenceContainer>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
*/
class Collection extends \Magento\Store\Model\ResourceModel\Website\Collection
{
/**
* @inheritdoc
*/
protected function _construct()
{
parent::_construct();

$this->_map['fields']['store_title'] = 'store_table.name';
$this->_map['fields']['group_title'] = 'group_table.name';
$this->_map['fields']['name'] = 'main_table.name';
}

/**
* Join website and store names
*
Expand All @@ -21,4 +33,37 @@ protected function _initSelect()
$this->joinGroupAndStore();
return $this;
}

/**
* @inheritdoc
*/
public function load($printQuery = false, $logQuery = false)
{
if ($this->isLoaded()) {
return $this;
}

return $this->loadWithFilter($printQuery, $logQuery);
}

/**
* @inheritdoc
*/
public function joinGroupAndStore()
{
if (!$this->getFlag('groups_and_stores_joined')) {
$this->_idFieldName = 'website_group_store';
$this->getSelect()->joinLeft(
['group_table' => $this->getTable('store_group')],
'main_table.website_id = group_table.website_id',
['group_id' => 'group_id', 'group_title' => 'name', 'group_code' => 'code']
)->joinLeft(
['store_table' => $this->getTable('store')],
'group_table.group_id = store_table.group_id',
['store_id' => 'store_id', 'store_title' => 'name', 'store_code' => 'code']
);
}

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Store\Test\Unit\Ui\Component\Listing\Column;

use Magento\Store\Ui\Component\Listing\Column\GroupTitle;

/**
* GroupTitleTest contains unit test for \Magento\Store\Ui\Component\Listing\Column\GroupTitle
*/
class GroupTitleTest extends \PHPUnit\Framework\TestCase
{
/**
* @var GroupTitle
*/
private $component;

/**
* @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $context;

/**
* @var \Magento\Framework\View\Element\UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $uiComponentFactory;

public function setUp()
{
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
->getMockForAbstractClass();
$processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
->disableOriginalConstructor()
->getMock();
$this->context->expects($this->never())->method('getProcessor')->willReturn($processor);
$this->uiComponentFactory = $this->createMock(\Magento\Framework\View\Element\UiComponentFactory::class);
$this->component = new GroupTitle(
$this->context,
$this->uiComponentFactory
);

$this->component->setData('name', 'name');
}

/**
* @covers \Magento\Store\Ui\Component\Listing\Column\GroupTitle::prepareDataSource
*/
public function testPrepareDataSource()
{
$dataSource = [
'data' => [
'items' => [
[
'name' => 'Main Website Store',
'group_id' => 1,
'group_code' => 'main_website_store',
]
]
]
];

$title = sprintf(
'<a title="Edit Store" href="%s">Main Website Store</a><br />(Code: main_website_store)',
'http://magento-2-1.dev/admin/system_store/editGroup'
);

$expectedDataSource = [
'data' => [
'items' => [
[
'name' => $title,
'group_id' => 1,
'group_code' => 'main_website_store',
]
]
]
];

$this->context->expects($this->once())
->method('getUrl')
->with(
'adminhtml/system_store/editGroup',
['group_id' => 1]
)
->willReturn('http://magento-2-1.dev/admin/system_store/editGroup');

$dataSource = $this->component->prepareDataSource($dataSource);
$this->assertEquals($expectedDataSource, $dataSource);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Store\Test\Unit\Ui\Component\Listing\Column;

use Magento\Store\Ui\Component\Listing\Column\StoreTitle;

/**
* Class StoreTitleTest contains unit test for \Magento\Store\Ui\Component\Listing\Column\StoreTitle
*/
class StoreTitleTest extends \PHPUnit\Framework\TestCase
{
/**
* @var StoreTitle
*/
private $component;

/**
* @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $context;

/**
* @var \Magento\Framework\View\Element\UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $uiComponentFactory;

public function setUp()
{
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
->getMockForAbstractClass();
$processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
->disableOriginalConstructor()
->getMock();
$this->context->expects($this->never())->method('getProcessor')->willReturn($processor);
$this->uiComponentFactory = $this->createMock(\Magento\Framework\View\Element\UiComponentFactory::class);
$this->component = new StoreTitle(
$this->context,
$this->uiComponentFactory
);

$this->component->setData('name', 'name');
}

/**
* @covers \Magento\Store\Ui\Component\Listing\Column\StoreTitle::prepareDataSource
*/
public function testPrepareDataSource()
{
$dataSource = [
'data' => [
'items' => [
[
'name' => 'Default Store View',
'store_id' => 1,
'store_code' => 'default',
]
]
]
];

$title = sprintf(
'<a title="Edit Store View" href="%s">Default Store View</a><br />(Code: default)',
'http://magento-2-1.dev/admin/system_store/editStore'
);

$expectedDataSource = [
'data' => [
'items' => [
[
'name' => $title,
'store_id' => 1,
'store_code' => 'default',
]
]
]
];

$this->context->expects($this->once())
->method('getUrl')
->with(
'adminhtml/system_store/editStore',
['store_id' => 1]
)
->willReturn('http://magento-2-1.dev/admin/system_store/editStore');

$dataSource = $this->component->prepareDataSource($dataSource);
$this->assertEquals($expectedDataSource, $dataSource);
}
}
Loading