1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Test\Unit\Block\System\Config;
class TabsTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Config\Block\System\Config\Tabs
*/
protected $_object;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $_structureMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $_requestMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $_urlBuilderMock;
protected function setUp()
{
$this->_requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
$this->_requestMock->expects(
$this->any()
)->method(
'getParam'
)->with(
'section'
)->will(
$this->returnValue('currentSectionId')
);
$this->_structureMock = $this->createMock(\Magento\Config\Model\Config\Structure::class);
$this->_structureMock->expects($this->once())->method('getTabs')->will($this->returnValue([]));
$this->_urlBuilderMock = $this->createMock(\Magento\Backend\Model\Url::class);
$data = [
'configStructure' => $this->_structureMock,
'request' => $this->_requestMock,
'urlBuilder' => $this->_urlBuilderMock,
];
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_object = $helper->getObject(\Magento\Config\Block\System\Config\Tabs::class, $data);
}
protected function tearDown()
{
unset($this->_object);
unset($this->_requestMock);
unset($this->_structureMock);
unset($this->_urlBuilderMock);
}
public function testGetSectionUrl()
{
$this->_urlBuilderMock->expects(
$this->once()
)->method(
'getUrl'
)->with(
'*/*/*',
['_current' => true, 'section' => 'testSectionId']
)->will(
$this->returnValue('testSectionUrl')
);
$sectionMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Section::class);
$sectionMock->expects($this->once())->method('getId')->will($this->returnValue('testSectionId'));
$this->assertEquals('testSectionUrl', $this->_object->getSectionUrl($sectionMock));
}
public function testIsSectionActiveReturnsTrueForActiveSection()
{
$sectionMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Section::class);
$sectionMock->expects($this->once())->method('getId')->will($this->returnValue('currentSectionId'));
$this->assertTrue($this->_object->isSectionActive($sectionMock));
}
public function testIsSectionActiveReturnsFalseForNonActiveSection()
{
$sectionMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Section::class);
$sectionMock->expects($this->once())->method('getId')->will($this->returnValue('nonCurrentSectionId'));
$this->assertFalse($this->_object->isSectionActive($sectionMock));
}
}