Skip to content

Commit 2990ece

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'api/MAGETWO-48240-Single-Store-Mode-On-UiComponents' into cart-price-rules
2 parents 8bd1166 + daa4d63 commit 2990ece

File tree

3 files changed

+92
-4
lines changed

3 files changed

+92
-4
lines changed

app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,30 @@ public function __construct(
4141
$this->storeManager = $storeManager;
4242
}
4343

44+
/**
45+
* {@inheritdoc}
46+
* @deprecated
47+
*/
48+
public function prepareDataSource(array $dataSource)
49+
{
50+
$websiteNames = [];
51+
foreach ($this->getData('options') as $website) {
52+
$websiteNames[$website->getWebsiteId()] = $website->getName();
53+
}
54+
if (isset($dataSource['data']['items'])) {
55+
$fieldName = $this->getData('name');
56+
foreach ($dataSource['data']['items'] as & $item) {
57+
$websites = [];
58+
foreach ($item[$fieldName] as $websiteId) {
59+
$websites[] = $websiteNames[$websiteId];
60+
}
61+
$item[$fieldName] = implode(', ', $websites);
62+
}
63+
}
64+
65+
return $dataSource;
66+
}
67+
4468
/**
4569
* Prepare component configuration
4670
* @return void

app/code/Magento/Store/Test/Unit/Ui/Component/Listing/Column/StoreTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class StoreTest extends \PHPUnit_Framework_TestCase
3838
*/
3939
protected $escaperMock;
4040

41+
/**
42+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
protected $storeManagerMock;
45+
4146
/**
4247
* @var string
4348
*/
@@ -68,6 +73,10 @@ protected function setUp()
6873
->getMock();
6974
$this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($this->processorMock);
7075
$this->processorMock->expects($this->atLeastOnce())->method('register');
76+
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
77+
->disableOriginalConstructor()
78+
->setMethods([])
79+
->getMock();
7180
$this->model = $objectManager->getObject(
7281
'Magento\Store\Ui\Component\Listing\Column\Store',
7382
[
@@ -79,10 +88,48 @@ protected function setUp()
7988
'data' => ['name' => $this->name]
8089
]
8190
);
91+
92+
$this->injectMockedDependency($this->storeManagerMock, 'storeManager');
93+
}
94+
95+
/**
96+
* Inject mocked object dependency
97+
*
98+
* @param \PHPUnit_Framework_MockObject_MockObject $mockObject
99+
* @param string $propertyName
100+
* @return void
101+
*
102+
* @deprecated
103+
*/
104+
private function injectMockedDependency($mockObject, $propertyName)
105+
{
106+
$reflection = new \ReflectionClass(get_class($this->model));
107+
$reflectionProperty = $reflection->getProperty($propertyName);
108+
$reflectionProperty->setAccessible(true);
109+
$reflectionProperty->setValue($this->model, $mockObject);
110+
}
111+
112+
public function testPrepare()
113+
{
114+
$this->storeManagerMock->expects($this->atLeastOnce())->method('isSingleStoreMode')->willReturn(false);
115+
$this->model->prepare();
116+
$config = $this->model->getDataByKey('config');
117+
$this->assertEmpty($config);
118+
}
119+
120+
public function testPrepareWithSingleStore()
121+
{
122+
$this->storeManagerMock->expects($this->atLeastOnce())->method('isSingleStoreMode')->willReturn(true);
123+
$this->model->prepare();
124+
$config = $this->model->getDataByKey('config');
125+
$this->assertNotEmpty($config);
126+
$this->assertArrayHasKey('componentDisabled', $config);
127+
$this->assertTrue($config['componentDisabled']);
82128
}
83129

84130
/**
85131
* @dataProvider prepareDataSourceDataProvider
132+
* @deprecated
86133
*/
87134
public function testPrepareDataSource($dataSource, $expectedResult)
88135
{
@@ -112,6 +159,9 @@ public function testPrepareDataSource($dataSource, $expectedResult)
112159
$this->assertEquals($this->model->prepareDataSource($dataSource), $expectedResult);
113160
}
114161

162+
/**
163+
* @deprecated
164+
*/
115165
public function prepareDataSourceDataProvider()
116166
{
117167
$content = "website<br/>&nbsp;&nbsp;&nbsp;group<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store<br/>";

app/code/Magento/Store/Ui/Component/Listing/Column/Store.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class Store extends Column
4848
* @param UiComponentFactory $uiComponentFactory
4949
* @param SystemStore $systemStore
5050
* @param Escaper $escaper
51-
* @param StoreManager $storeManager
5251
* @param array $components
5352
* @param array $data
5453
* @param string $storeKey
@@ -58,15 +57,13 @@ public function __construct(
5857
UiComponentFactory $uiComponentFactory,
5958
SystemStore $systemStore,
6059
Escaper $escaper,
61-
StoreManager $storeManager,
6260
array $components = [],
6361
array $data = [],
6462
$storeKey = 'store_id'
6563
) {
6664
$this->systemStore = $systemStore;
6765
$this->escaper = $escaper;
6866
$this->storeKey = $storeKey;
69-
$this->storeManager = $storeManager;
7067
parent::__construct($context, $uiComponentFactory, $components, $data);
7168
}
7269

@@ -125,13 +122,30 @@ protected function prepareItem(array $item)
125122

126123
/**
127124
* Prepare component configuration
125+
*
128126
* @return void
129127
*/
130128
public function prepare()
131129
{
132130
parent::prepare();
133-
if ($this->storeManager->isSingleStoreMode()) {
131+
if ($this->getStoreManager()->isSingleStoreMode()) {
134132
$this->_data['config']['componentDisabled'] = true;
135133
}
136134
}
135+
136+
/**
137+
* Get StoreManager dependency
138+
*
139+
* @return StoreManager
140+
*
141+
* @deprecated
142+
*/
143+
private function getStoreManager()
144+
{
145+
if ($this->storeManager === null) {
146+
$this->storeManager = \Magento\Framework\App\ObjectManager::getInstance()
147+
->get('Magento\Store\Model\StoreManagerInterface');
148+
}
149+
return $this->storeManager;
150+
}
137151
}

0 commit comments

Comments
 (0)