Skip to content

Commit 077dbdc

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-5403
2 parents babf3bf + 2f09fad commit 077dbdc

File tree

50 files changed

+981
-527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+981
-527
lines changed

app/code/Magento/Backend/view/adminhtml/layout/default.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
<referenceContainer name="page.formkey">
4343
<block class="Magento\Backend\Block\Admin\Formkey" name="formkey" as="formkey" template="Magento_Backend::admin/formkey.phtml"/>
4444
</referenceContainer>
45-
<referenceContainer name="page.js.translate">
46-
<block class="Magento\Framework\View\Element\Template" name="js_translate" as="js_translate" template="Magento_Backend::page/js/translate.phtml"/>
47-
</referenceContainer>
4845
<referenceContainer name="main.top">
4946
<block class="Magento\Theme\Block\Html\Title" name="page.title" template="title.phtml"/>
5047
</referenceContainer>

app/code/Magento/Backend/view/adminhtml/templates/page/js/translate.phtml

Lines changed: 0 additions & 52 deletions
This file was deleted.

app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php

Lines changed: 104 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010

1111
class FormTest extends \PHPUnit_Framework_TestCase
1212
{
13+
/**
14+
* @var \PHPUnit_Framework_MockObject_MockBuilder
15+
*/
16+
protected $_objectBuilder;
17+
1318
/**
1419
* @var \Magento\Config\Block\System\Config\Form
1520
*/
16-
protected $_object;
21+
protected $object;
1722

1823
/**
1924
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -166,39 +171,93 @@ protected function setUp()
166171
'context' => $context,
167172
];
168173

169-
$this->_object = $helper->getObject('Magento\Config\Block\System\Config\Form', $data);
170-
$this->_object->setData('scope_id', 1);
174+
$objectArguments = $helper->getConstructArguments('Magento\Config\Block\System\Config\Form', $data);
175+
$this->_objectBuilder = $this->getMockBuilder('Magento\Config\Block\System\Config\Form')
176+
->setConstructorArgs($objectArguments)
177+
->setMethods(['something']);
178+
$this->object = $helper->getObject('Magento\Config\Block\System\Config\Form', $data);
179+
$this->object->setData('scope_id', 1);
171180
}
172181

173-
public function testInitFormWithoutSection()
182+
/**
183+
* @param bool $sectionIsVisible
184+
* @dataProvider initFormDataProvider
185+
*/
186+
public function testInitForm($sectionIsVisible)
174187
{
188+
/** @var \Magento\Config\Block\System\Config\Form | \PHPUnit_Framework_MockObject_MockObject $object */
189+
$object = $this->_objectBuilder->setMethods(['_initGroup'])->getMock();
190+
$object->setData('scope_id', 1);
175191
$this->_formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_formMock));
176-
$this->_formMock->expects($this->once())->method('setParent')->with($this->_object);
192+
$this->_formMock->expects($this->once())->method('setParent')->with($object);
177193
$this->_formMock->expects($this->once())->method('setBaseUrl')->with('base_url');
178194
$this->_urlModelMock->expects($this->any())->method('getBaseUrl')->will($this->returnValue('base_url'));
179195

196+
$sectionMock = $this->getMockBuilder('\Magento\Config\Model\Config\Structure\Element\Section')
197+
->disableOriginalConstructor()
198+
->getMock();
199+
if ($sectionIsVisible) {
200+
$sectionMock->expects($this->once())
201+
->method('isVisible')
202+
->willReturn(true);
203+
$sectionMock->expects($this->once())
204+
->method('getChildren')
205+
->willReturn([
206+
$this->getMock(
207+
'Magento\Config\Model\Config\Structure\Element\Group',
208+
[],
209+
[],
210+
'',
211+
false,
212+
false
213+
)
214+
]);
215+
}
216+
180217
$this->_systemConfigMock->expects(
181218
$this->once()
182219
)->method(
183220
'getElement'
184221
)->with(
185222
'section_code'
186223
)->will(
187-
$this->returnValue(null)
224+
$this->returnValue($sectionIsVisible ? $sectionMock : null)
188225
);
189226

190-
$this->_object->initForm();
191-
$this->assertEquals($this->_formMock, $this->_object->getForm());
227+
if ($sectionIsVisible) {
228+
$object->expects($this->once())
229+
->method('_initGroup');
230+
} else {
231+
$object->expects($this->never())
232+
->method('_initGroup');
233+
}
234+
235+
236+
$object->initForm();
237+
$this->assertEquals($this->_formMock, $object->getForm());
238+
}
239+
240+
public function initFormDataProvider()
241+
{
242+
return [
243+
[false],
244+
[true]
245+
];
192246
}
193247

194248
/**
195-
* @return void
249+
* @param bool $shouldCloneFields
250+
* @param array $prefixes
251+
* @param int $callNum
252+
* @dataProvider initGroupDataProvider
196253
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
197254
*/
198-
public function testInitGroup()
255+
public function testInitGroup($shouldCloneFields, $prefixes, $callNum)
199256
{
257+
/** @var \Magento\Config\Block\System\Config\Form | \PHPUnit_Framework_MockObject_MockObject $object */
258+
$object = $this->_objectBuilder->setMethods(['initFields'])->getMock();
200259
$this->_formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_formMock));
201-
$this->_formMock->expects($this->once())->method('setParent')->with($this->_object);
260+
$this->_formMock->expects($this->once())->method('setParent')->with($object);
202261
$this->_formMock->expects($this->once())->method('setBaseUrl')->with('base_url');
203262
$this->_urlModelMock->expects($this->any())->method('getBaseUrl')->will($this->returnValue('base_url'));
204263

@@ -227,8 +286,6 @@ public function testInitGroup()
227286
false
228287
);
229288

230-
$cloneModelMock->expects($this->once())->method('getPrefixes')->will($this->returnValue([]));
231-
232289
$groupMock = $this->getMock(
233290
'Magento\Config\Model\Config\Structure\Element\Group',
234291
[],
@@ -243,8 +300,7 @@ public function testInitGroup()
243300
$groupMock->expects($this->once())->method('getComment')->will($this->returnValue('comment'));
244301
$groupMock->expects($this->once())->method('isExpanded')->will($this->returnValue(false));
245302
$groupMock->expects($this->once())->method('populateFieldset');
246-
$groupMock->expects($this->once())->method('shouldCloneFields')->will($this->returnValue(true));
247-
$groupMock->expects($this->once())->method('getCloneModel')->will($this->returnValue($cloneModelMock));
303+
$groupMock->expects($this->once())->method('shouldCloneFields')->will($this->returnValue($shouldCloneFields));
248304
$groupMock->expects($this->once())->method('getData')->will($this->returnValue('some group data'));
249305
$groupMock->expects(
250306
$this->once()
@@ -300,9 +356,40 @@ public function testInitGroup()
300356
)->will(
301357
$this->returnValue($formFieldsetMock)
302358
);
303-
$this->_object->initForm();
359+
360+
if ($shouldCloneFields) {
361+
$cloneModelMock->expects($this->once())->method('getPrefixes')->will($this->returnValue($prefixes));
362+
363+
$groupMock->expects($this->once())->method('getCloneModel')->will($this->returnValue($cloneModelMock));
364+
}
365+
366+
if ($shouldCloneFields && $prefixes) {
367+
$object->expects($this->exactly($callNum))
368+
->method('initFields')
369+
->with(
370+
$formFieldsetMock,
371+
$groupMock,
372+
$sectionMock,
373+
$prefixes[0]['field'],
374+
$prefixes[0]['label']
375+
);
376+
} else {
377+
$object->expects($this->exactly($callNum))
378+
->method('initFields')
379+
->with($formFieldsetMock, $groupMock, $sectionMock);
380+
}
381+
382+
$object->initForm();
304383
}
305384

385+
public function initGroupDataProvider()
386+
{
387+
return [
388+
[true, [['field' => 'field', 'label' => 'label']], 1],
389+
[true, [], 0],
390+
[false, [['field' => 'field', 'label' => 'label']], 1],
391+
];
392+
}
306393
/**
307394
* @dataProvider initFieldsDataProvider
308395
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -460,7 +547,7 @@ public function testInitFields($backendConfigValue, $configValue, $configPath, $
460547

461548
$fieldMock->expects($this->once())->method('populateInput');
462549

463-
$this->_object->initFields($fieldsetMock, $groupMock, $sectionMock, $fieldPrefix, $labelPrefix);
550+
$this->object->initFields($fieldsetMock, $groupMock, $sectionMock, $fieldPrefix, $labelPrefix);
464551
}
465552

466553
/**

app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class DeveloperChain extends Chain
1515
* @param string $origContent
1616
* @param string $origContentType
1717
* @param null $origAssetPath
18+
* @codeCoverageIgnore
1819
*/
1920
public function __construct(
2021
LocalInterface $asset,

app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313

1414
class DeveloperChainFactory implements ChainFactoryInterface
1515
{
16+
/**
17+
* Name of entity to create
18+
*/
19+
const ENTITY_NAME = 'Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChain';
20+
1621
/**
1722
* Object manager
1823
*
1924
* @var ObjectManagerInterface
2025
*/
21-
private $_objectManager;
26+
private $objectManager;
2227

2328
/**
2429
* @var ChainFactory
@@ -40,7 +45,7 @@ public function __construct(
4045
ChainFactory $chainFactory,
4146
ScopeConfigInterface $scopeConfig
4247
) {
43-
$this->_objectManager = $objectManager;
48+
$this->objectManager = $objectManager;
4449
$this->chainFactory = $chainFactory;
4550
$this->scopeConfig = $scopeConfig;
4651
}
@@ -51,8 +56,8 @@ public function __construct(
5156
public function create(array $arguments = [])
5257
{
5358
if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) {
54-
return $this->_objectManager->create(
55-
'Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChain',
59+
return $this->objectManager->create(
60+
self::ENTITY_NAME,
5661
$arguments
5762
);
5863
}

app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
/**
1212
* Factory class for \Magento\Framework\View\Page\Config\RendererInterface
13-
*
14-
* todo work with interfaces instead of abstractions
1513
*/
1614
class RendererFactory extends \Magento\Framework\View\Page\Config\RendererFactory
1715
{
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Developer\Test\Unit\Model\View\Asset\PreProcessor;
7+
8+
use Magento\Developer\Model\Config\Source\WorkflowType;
9+
use Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChainFactory;
10+
11+
class DeveloperChainFactoryTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\ObjectManagerInterface */
14+
private $objectManagerMock;
15+
16+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Config\ScopeConfigInterface */
17+
private $configMock;
18+
19+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\View\Asset\PreProcessor\ChainFactory */
20+
private $chainFactoryMock;
21+
22+
/** @var \PHPUnit_Framework_MockObject_MockObject | DeveloperChainFactory */
23+
private $model;
24+
25+
public function setUp()
26+
{
27+
// Set up mocks
28+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
29+
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
30+
->disableOriginalConstructor()
31+
->getMock();
32+
$this->configMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
33+
->disableOriginalConstructor()
34+
->getMock();
35+
$this->chainFactoryMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\ChainFactory')
36+
->disableOriginalConstructor()
37+
->getMock();
38+
39+
// Set up System Under Test
40+
$sutArgs = [
41+
'objectManager' => $this->objectManagerMock,
42+
'chainFactory' => $this->chainFactoryMock,
43+
'scopeConfig' => $this->configMock
44+
];
45+
$this->model = $objectManager->getObject(
46+
'Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChainFactory',
47+
$sutArgs
48+
);
49+
}
50+
51+
public function testCreateClientCompilation()
52+
{
53+
$this->configMock->expects($this->once())
54+
->method('getValue')
55+
->with(WorkflowType::CONFIG_NAME_PATH)
56+
->willReturn(WorkflowType::CLIENT_SIDE_COMPILATION);
57+
$instanceMock = $this->getMockBuilder(DeveloperChainFactory::ENTITY_NAME)
58+
->disableOriginalConstructor()
59+
->getMock();
60+
$createArgs = [1, 2, 3];
61+
$this->objectManagerMock->expects($this->once())
62+
->method('create')
63+
->with(DeveloperChainFactory::ENTITY_NAME, $createArgs)
64+
->willReturn($instanceMock);
65+
$this->chainFactoryMock->expects($this->never())->method('create');
66+
67+
$this->assertSame($instanceMock, $this->model->create($createArgs));
68+
}
69+
70+
public function testCreateNoClientCompilation()
71+
{
72+
$this->configMock->expects($this->once())
73+
->method('getValue')
74+
->with(WorkflowType::CONFIG_NAME_PATH)
75+
->willReturn('');
76+
$instanceMock = $this->getMockBuilder(DeveloperChainFactory::ENTITY_NAME)
77+
->disableOriginalConstructor()
78+
->getMock();
79+
$createArgs = [1, 2, 3];
80+
$this->chainFactoryMock->expects($this->once())
81+
->method('create')
82+
->with($createArgs)
83+
->willReturn($instanceMock);
84+
$this->objectManagerMock->expects($this->never())->method('create');
85+
86+
$this->assertSame($instanceMock, $this->model->create($createArgs));
87+
}
88+
}

0 commit comments

Comments
 (0)