Skip to content

Commit 5c5df5f

Browse files
author
He, Joan(johe)
committed
Merge pull request #387 from magento-extensibility/MAGETWO-36838-filter
[Extensibility] MAGETWO-36838 and Unit Test Coverage
2 parents 87f0ada + 6912a12 commit 5c5df5f

File tree

10 files changed

+667
-233
lines changed

10 files changed

+667
-233
lines changed

app/code/Magento/Config/Block/System/Config/Form/Fieldset/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Config\Block\System\Config\Form\Fieldset;
88

99
/**
10-
* Magento\Config\Block\System\Config\Form\Fieldset object factory
10+
* Magento\Config\Block\System\Config\Form\Fieldset Class Factory
1111
*
1212
* @codeCoverageIgnore
1313
*/
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Block\System\Config;
7+
8+
class DwstreeTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Config\Block\System\Config\Dwstree
12+
*/
13+
protected $object;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $requestMock;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $storeManagerMock;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $websiteMock;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $storeMock;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $context;
39+
40+
protected function setUp()
41+
{
42+
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
46+
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$this->websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
51+
->disableOriginalConstructor()
52+
->getMock();
53+
54+
$this->storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
55+
->disableOriginalConstructor()
56+
->getMock();
57+
58+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
59+
60+
$this->context = $objectManager->getObject(
61+
'Magento\Backend\Block\Template\Context',
62+
[
63+
'request' => $this->requestMock,
64+
'storeManager' => $this->storeManagerMock,
65+
]
66+
);
67+
68+
$this->object = $objectManager->getObject(
69+
'Magento\Config\Block\System\Config\Dwstree',
70+
['context' => $this->context]
71+
);
72+
}
73+
74+
/**
75+
* @param $section
76+
* @param $website
77+
* @param $store
78+
* @dataProvider initTabsDataProvider
79+
*/
80+
public function testInitTabs($section, $website, $store)
81+
{
82+
$this->requestMock->expects($this->any())
83+
->method('getParam')
84+
->will(
85+
$this->returnValueMap(
86+
[
87+
['section', $section],
88+
['website', $website['expected']['code']],
89+
['store', $store['expected']['code']],
90+
]
91+
)
92+
);
93+
$this->storeManagerMock->expects($this->once())
94+
->method('getWebsites')
95+
->willReturn([$this->websiteMock]);
96+
$this->websiteMock->expects($this->any())
97+
->method('getCode')
98+
->willReturn($website['actual']['code']);
99+
$this->websiteMock->expects($this->any())
100+
->method('getName')
101+
->willReturn($website['expected']['name']);
102+
$this->websiteMock->expects($this->once())
103+
->method('getStores')
104+
->willReturn([$this->storeMock]);
105+
$this->storeMock->expects($this->any())
106+
->method('getCode')
107+
->willReturn($store['actual']['code']);
108+
$this->storeMock->expects($this->any())
109+
->method('getName')
110+
->willReturn($store['actual']['name']);
111+
112+
$this->assertEquals($this->object, $this->object->initTabs());
113+
114+
$this->assertEquals(
115+
[
116+
'default',
117+
'website_' . $website['actual']['code'],
118+
'store_' . $store['actual']['code']
119+
],
120+
$this->object->getTabsIds()
121+
);
122+
}
123+
124+
public function initTabsDataProvider()
125+
{
126+
return [
127+
'matchAll' => [
128+
'scope' => 'Test Scope',
129+
'website' => [
130+
'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
131+
'actual' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
132+
],
133+
'store' => [
134+
'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
135+
'actual' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
136+
],
137+
],
138+
'matchStore' => [
139+
'scope' => 'Test Scope',
140+
'website' => [
141+
'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
142+
'actual' => ['name' => false, 'code' => false],
143+
],
144+
'store' => [
145+
'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
146+
'actual' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
147+
],
148+
],
149+
'matchWebsite' => [
150+
'scope' => 'Test Scope',
151+
'website' => [
152+
'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
153+
'actual' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
154+
],
155+
'store' => [
156+
'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
157+
'actual' => ['name' => false, 'code' => false],
158+
],
159+
],
160+
'noMatch' => [
161+
'scope' => 'Test Scope',
162+
'website' => [
163+
'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
164+
'actual' => ['name' => false, 'code' => false],
165+
],
166+
'store' => [
167+
'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
168+
'actual' => ['name' => false, 'code' => false],
169+
],
170+
],
171+
];
172+
}
173+
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,43 @@ public function testGetSaveUrl()
145145

146146
$this->assertEquals($expectedUrl, $this->_object->getSaveUrl());
147147
}
148+
149+
public function testPrepareLayout()
150+
{
151+
$expectedHeader = 'Test Header';
152+
$expectedLabel = 'Test Label';
153+
$expectedBlock = 'Test Block';
154+
155+
$blockMock = $this->getMockBuilder('Magento\Framework\View\Element\Template')
156+
->disableOriginalConstructor()
157+
->getMock();
158+
159+
$this->_sectionMock->expects($this->once())
160+
->method('getFrontendModel')
161+
->willReturn($expectedBlock);
162+
$this->_sectionMock->expects($this->once())
163+
->method('getLabel')
164+
->willReturn($expectedLabel);
165+
$this->_sectionMock->expects($this->once())
166+
->method('getHeaderCss')
167+
->willReturn($expectedHeader);
168+
$this->_layoutMock->expects($this->once())
169+
->method('getBlock')
170+
->with('page.actions.toolbar')
171+
->willReturn($blockMock);
172+
$this->_layoutMock->expects($this->once())
173+
->method('createBlock')
174+
->with($expectedBlock)
175+
->willReturn($blockMock);
176+
$blockMock->expects($this->once())
177+
->method('getNameInLayout')
178+
->willReturn($expectedBlock);
179+
$this->_layoutMock->expects($this->once())
180+
->method('setChild')
181+
->with($expectedBlock, $expectedBlock, 'form')
182+
->willReturn($this->_layoutMock);
183+
184+
$this->_object->setNameInLayout($expectedBlock);
185+
$this->_object->setLayout($this->_layoutMock);
186+
}
148187
}

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/FieldTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ protected function setUp()
7171
'getInherit',
7272
'getCanUseWebsiteValue',
7373
'getCanUseDefaultValue',
74-
'setDisabled'
74+
'setDisabled',
75+
'getTooltip',
7576
],
7677
[],
7778
'',
@@ -140,6 +141,19 @@ public function testRenderValueWithCommentBlock()
140141
$this->assertContains($expected, $actual);
141142
}
142143

144+
public function testRenderValueWithTooltipBlock()
145+
{
146+
$testTooltip = 'test_tooltip';
147+
$this->_elementMock->expects($this->any())->method('getTooltip')->will($this->returnValue($testTooltip));
148+
$expected = '<td class="value with-tooltip">' .
149+
$this->_testData['elementHTML'] .
150+
'<div class="tooltip"><span class="help"><span></span></span><div class="tooltip-content">' .
151+
$testTooltip .
152+
'</div></div></td>';
153+
$actual = $this->_object->render($this->_elementMock);
154+
$this->assertContains($expected, $actual);
155+
}
156+
143157
public function testRenderHint()
144158
{
145159
$testHint = 'test_hint';

0 commit comments

Comments
 (0)