123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Config\Test\Unit\Block\System\Config;
- class EditTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Config\Block\System\Config\Edit
- */
- protected $_object;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $_systemConfigMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $_requestMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $_layoutMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $_urlModelMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $_sectionMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $_jsonMock;
- protected function setUp()
- {
- $this->_systemConfigMock = $this->createMock(\Magento\Config\Model\Config\Structure::class);
- $this->_requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
- $this->_requestMock->expects(
- $this->any()
- )->method(
- 'getParam'
- )->with(
- 'section'
- )->will(
- $this->returnValue('test_section')
- );
- $this->_layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
- $this->_urlModelMock = $this->createMock(\Magento\Backend\Model\Url::class);
- $this->_sectionMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Section::class);
- $this->_systemConfigMock->expects(
- $this->any()
- )->method(
- 'getElement'
- )->with(
- 'test_section'
- )->will(
- $this->returnValue($this->_sectionMock)
- );
- $this->_jsonMock = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
- $data = [
- 'data' => ['systemConfig' => $this->_systemConfigMock],
- 'request' => $this->_requestMock,
- 'layout' => $this->_layoutMock,
- 'urlBuilder' => $this->_urlModelMock,
- 'configStructure' => $this->_systemConfigMock,
- 'jsonSerializer' => $this->_jsonMock,
- ];
- $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->_object = $helper->getObject(\Magento\Config\Block\System\Config\Edit::class, $data);
- }
- public function testGetSaveButtonHtml()
- {
- $expected = 'element_html_code';
- $this->_layoutMock->expects(
- $this->once()
- )->method(
- 'getChildName'
- )->with(
- null,
- 'save_button'
- )->will(
- $this->returnValue('test_child_name')
- );
- $this->_layoutMock->expects(
- $this->once()
- )->method(
- 'renderElement'
- )->with(
- 'test_child_name'
- )->will(
- $this->returnValue('element_html_code')
- );
- $this->assertEquals($expected, $this->_object->getSaveButtonHtml());
- }
- public function testGetSaveUrl()
- {
- $expectedUrl = '*/system_config/save';
- $expectedParams = ['_current' => true];
- $this->_urlModelMock->expects(
- $this->once()
- )->method(
- 'getUrl'
- )->with(
- $expectedUrl,
- $expectedParams
- )->will(
- $this->returnArgument(0)
- );
- $this->assertEquals($expectedUrl, $this->_object->getSaveUrl());
- }
- public function testPrepareLayout()
- {
- $expectedHeader = 'Test Header';
- $expectedLabel = 'Test Label';
- $expectedBlock = 'Test Block';
- $blockMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->_sectionMock->expects($this->once())
- ->method('getFrontendModel')
- ->willReturn($expectedBlock);
- $this->_sectionMock->expects($this->once())
- ->method('getLabel')
- ->willReturn($expectedLabel);
- $this->_sectionMock->expects($this->once())
- ->method('getHeaderCss')
- ->willReturn($expectedHeader);
- $this->_layoutMock->expects($this->once())
- ->method('getBlock')
- ->with('page.actions.toolbar')
- ->willReturn($blockMock);
- $this->_layoutMock->expects($this->once())
- ->method('createBlock')
- ->with($expectedBlock)
- ->willReturn($blockMock);
- $blockMock->expects($this->once())
- ->method('getNameInLayout')
- ->willReturn($expectedBlock);
- $this->_layoutMock->expects($this->once())
- ->method('setChild')
- ->with($expectedBlock, $expectedBlock, 'form')
- ->willReturn($this->_layoutMock);
- $this->_object->setNameInLayout($expectedBlock);
- $this->_object->setLayout($this->_layoutMock);
- }
- /**
- * @param array $requestData
- * @param array $expected
- * @dataProvider getConfigSearchParamsJsonData
- */
- public function testGetConfigSearchParamsJson(array $requestData, array $expected)
- {
- $requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
- $requestMock->expects($this->any())
- ->method('getParam')
- ->will($this->returnValueMap($requestData));
- $this->_jsonMock->expects($this->once())
- ->method('serialize')
- ->with($expected);
- $data = [
- 'data' => ['systemConfig' => $this->_systemConfigMock],
- 'request' => $requestMock,
- 'layout' => $this->_layoutMock,
- 'urlBuilder' => $this->_urlModelMock,
- 'configStructure' => $this->_systemConfigMock,
- 'jsonSerializer' => $this->_jsonMock,
- ];
- $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $object = $helper->getObject(\Magento\Config\Block\System\Config\Edit::class, $data);
- $object->getConfigSearchParamsJson();
- }
- /**
- * @return array
- */
- public function getConfigSearchParamsJsonData()
- {
- return [
- [
- [
- ['section', null, null],
- ['group', null, null],
- ['field', null, null],
- ],
- [],
- ],
- [
- [
- ['section', null, 'section_code'],
- ['group', null, null],
- ['field', null, null],
- ],
- [
- 'section' => 'section_code',
- ],
- ],
- [
- [
- ['section', null, 'section_code'],
- ['group', null, 'group_code'],
- ['field', null, null],
- ],
- [
- 'section' => 'section_code',
- 'group' => 'group_code',
- ],
- ],
- [
- [
- ['section', null, 'section_code'],
- ['group', null, 'group_code'],
- ['field', null, 'field_code'],
- ],
- [
- 'section' => 'section_code',
- 'group' => 'group_code',
- 'field' => 'field_code',
- ],
- ],
- ];
- }
- }
|