Skip to content

Commit 7724d55

Browse files
MAGETWO-63231: Implementation
1 parent 64d2c5c commit 7724d55

File tree

2 files changed

+76
-40
lines changed

2 files changed

+76
-40
lines changed

app/code/Magento/Theme/Model/Source/InitialThemeSource.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
use Magento\Framework\App\Config\ConfigSourceInterface;
99
use Magento\Framework\App\DeploymentConfig;
10-
use Magento\Framework\DataObject;
1110
use Magento\Theme\Model\ResourceModel\Theme;
1211
use Magento\Theme\Model\ResourceModel\ThemeFactory;
12+
use Magento\Framework\DataObject\Factory as DataObjectFactory;
1313

1414
/**
1515
* Class InitialThemeSource.
@@ -32,6 +32,13 @@ class InitialThemeSource implements ConfigSourceInterface
3232
*/
3333
private $themeFactory;
3434

35+
/**
36+
* A data object factory.
37+
*
38+
* @var DataObjectFactory
39+
*/
40+
private $dataObjectFactory;
41+
3542
/**
3643
* Array with theme data.
3744
*
@@ -42,11 +49,16 @@ class InitialThemeSource implements ConfigSourceInterface
4249
/**
4350
* @param DeploymentConfig $deploymentConfig A deployment config
4451
* @param ThemeFactory $themeFactory A theme factory
52+
* @param DataObjectFactory $dataObjectFactory A data object factory
4553
*/
46-
public function __construct(DeploymentConfig $deploymentConfig, ThemeFactory $themeFactory)
47-
{
54+
public function __construct(
55+
DeploymentConfig $deploymentConfig,
56+
ThemeFactory $themeFactory,
57+
DataObjectFactory $dataObjectFactory
58+
) {
4859
$this->deploymentConfig = $deploymentConfig;
4960
$this->themeFactory = $themeFactory;
61+
$this->dataObjectFactory = $dataObjectFactory;
5062
}
5163

5264
/**
@@ -75,7 +87,7 @@ public function get($path = '')
7587
}
7688
}
7789

78-
$this->data = new DataObject($themes);
90+
$this->data = $this->dataObjectFactory->create($themes);
7991
}
8092

8193
return $this->data->getData($path) ?: [];

app/code/Magento/Theme/Test/Unit/Model/Source/InitialThemeSourceTest.php

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
namespace Magento\Theme\Test\Unit\Model\Source;
77

88
use Magento\Framework\App\DeploymentConfig;
9+
use Magento\Framework\DataObject;
910
use Magento\Theme\Model\ResourceModel\Theme;
1011
use Magento\Theme\Model\ResourceModel\ThemeFactory;
1112
use Magento\Theme\Model\Source\InitialThemeSource;
1213
use Magento\Framework\DB\Adapter\AdapterInterface;
1314
use PHPUnit_Framework_MockObject_MockObject as Mock;
1415
use Magento\Framework\DB\Select;
16+
use Magento\Framework\DataObject\Factory as DataObjectFactory;
1517

1618
class InitialThemeSourceTest extends \PHPUnit_Framework_TestCase
1719
{
@@ -30,6 +32,16 @@ class InitialThemeSourceTest extends \PHPUnit_Framework_TestCase
3032
*/
3133
private $themeFactoryMock;
3234

35+
/**
36+
* @var DataObjectFactory|Mock
37+
*/
38+
private $dataObjectFactoryMock;
39+
40+
/**
41+
* @var DataObject|Mock
42+
*/
43+
private $dataObjectMock;
44+
3345
/**
3446
* @var Theme|Mock
3547
*/
@@ -62,6 +74,12 @@ protected function setUp()
6274
->getMock();
6375
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
6476
->getMockForAbstractClass();
77+
$this->dataObjectFactoryMock = $this->getMockBuilder(DataObjectFactory::class)
78+
->disableOriginalConstructor()
79+
->getMock();
80+
$this->dataObjectMock = $this->getMockBuilder(DataObject::class)
81+
->disableOriginalConstructor()
82+
->getMock();
6583

6684
$this->themeMock->expects($this->any())
6785
->method('getConnection')
@@ -81,7 +99,8 @@ protected function setUp()
8199

82100
$this->model = new InitialThemeSource(
83101
$this->deploymentConfigMock,
84-
$this->themeFactoryMock
102+
$this->themeFactoryMock,
103+
$this->dataObjectFactoryMock
85104
);
86105
}
87106

@@ -138,41 +157,46 @@ public function testGet()
138157
],
139158
]
140159
);
160+
$this->dataObjectFactoryMock->expects($this->once())
161+
->method('create')
162+
->with(
163+
[
164+
'Magento/backend' => [
165+
'parent_id' => null,
166+
'theme_path' => 'Magento/backend',
167+
'theme_title' => 'Magento 2 backend',
168+
'preview_image' => null,
169+
'is_featured' => '0',
170+
'area' => 'adminhtml',
171+
'type' => '0',
172+
'code' => 'Magento/backend',
173+
],
174+
'Magento/blank' => [
175+
'parent_id' => null,
176+
'theme_path' => 'Magento/blank',
177+
'theme_title' => 'Magento Blank',
178+
'preview_image' => 'preview_image_587df6c4cc9c2.jpeg',
179+
'is_featured' => '0',
180+
'area' => 'frontend',
181+
'type' => '0',
182+
'code' => 'Magento/blank',
183+
],
184+
'Magento/luma' => [
185+
'parent_id' => 'Magento/blank',
186+
'theme_path' => 'Magento/luma',
187+
'theme_title' => 'Magento Luma',
188+
'preview_image' => 'preview_image_587df6c4e073d.jpeg',
189+
'is_featured' => '0',
190+
'area' => 'frontend',
191+
'type' => '0',
192+
'code' => 'Magento/luma',
193+
],
194+
]
195+
)
196+
->willReturn($this->dataObjectMock);
197+
$this->dataObjectMock->expects($this->once())
198+
->method('getData');
141199

142-
$this->assertSame(
143-
[
144-
'Magento/backend' => [
145-
'parent_id' => null,
146-
'theme_path' => 'Magento/backend',
147-
'theme_title' => 'Magento 2 backend',
148-
'preview_image' => null,
149-
'is_featured' => '0',
150-
'area' => 'adminhtml',
151-
'type' => '0',
152-
'code' => 'Magento/backend',
153-
],
154-
'Magento/blank' => [
155-
'parent_id' => null,
156-
'theme_path' => 'Magento/blank',
157-
'theme_title' => 'Magento Blank',
158-
'preview_image' => 'preview_image_587df6c4cc9c2.jpeg',
159-
'is_featured' => '0',
160-
'area' => 'frontend',
161-
'type' => '0',
162-
'code' => 'Magento/blank',
163-
],
164-
'Magento/luma' => [
165-
'parent_id' => 'Magento/blank',
166-
'theme_path' => 'Magento/luma',
167-
'theme_title' => 'Magento Luma',
168-
'preview_image' => 'preview_image_587df6c4e073d.jpeg',
169-
'is_featured' => '0',
170-
'area' => 'frontend',
171-
'type' => '0',
172-
'code' => 'Magento/luma',
173-
],
174-
],
175-
$this->model->get()
176-
);
200+
$this->model->get();
177201
}
178202
}

0 commit comments

Comments
 (0)