TabsTest.php 3.1 KB

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