CurrencyTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CurrencySymbol\Test\Unit\Block\Adminhtml\System;
  7. class CurrencyTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * Object manager helper
  11. *
  12. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  13. */
  14. protected $objectManagerHelper;
  15. protected function setUp()
  16. {
  17. $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  18. }
  19. protected function tearDown()
  20. {
  21. unset($this->objectManagerHelper);
  22. }
  23. public function testPrepareLayout()
  24. {
  25. $childBlockMock = $this->createPartialMock(
  26. \Magento\Framework\View\Element\BlockInterface::class,
  27. ['addChild', 'toHtml']
  28. );
  29. $blockMock = $this->createMock(\Magento\Framework\View\Element\BlockInterface::class);
  30. /** @var $layoutMock \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject */
  31. $layoutMock = $this->getMockForAbstractClass(
  32. \Magento\Framework\View\LayoutInterface::class,
  33. [],
  34. '',
  35. false,
  36. false,
  37. true,
  38. ['getBlock', 'createBlock']
  39. );
  40. $layoutMock->expects($this->any())->method('getBlock')->willReturn($childBlockMock);
  41. $layoutMock->expects($this->any())->method('createBlock')->willReturn($blockMock);
  42. $childBlockMock->expects($this->at(0))
  43. ->method('addChild')
  44. ->with(
  45. 'save_button',
  46. \Magento\Backend\Block\Widget\Button::class,
  47. [
  48. 'label' => __('Save Currency Rates'),
  49. 'class' => 'save primary save-currency-rates',
  50. 'data_attribute' => [
  51. 'mage-init' => ['button' => ['event' => 'save', 'target' => '#rate-form']],
  52. ]
  53. ]
  54. );
  55. $childBlockMock->expects($this->at(1))
  56. ->method('addChild')
  57. ->with(
  58. 'options_button',
  59. \Magento\Backend\Block\Widget\Button::class,
  60. ['label' => __('Options'), 'onclick' => 'setLocation(\'\')']
  61. );
  62. $childBlockMock->expects($this->at(2))
  63. ->method('addChild')
  64. ->with(
  65. 'reset_button',
  66. \Magento\Backend\Block\Widget\Button::class,
  67. ['label' => __('Reset'), 'onclick' => 'document.location.reload()', 'class' => 'reset']
  68. );
  69. /** @var $block \Magento\CurrencySymbol\Block\Adminhtml\System\Currency */
  70. $block = $this->objectManagerHelper->getObject(
  71. \Magento\CurrencySymbol\Block\Adminhtml\System\Currency::class,
  72. [
  73. 'layout' => $layoutMock
  74. ]
  75. );
  76. $block->setLayout($layoutMock);
  77. }
  78. }