AbstractTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Block\Adminhtml\Items;
  7. class AbstractTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
  10. protected $_objectManager;
  11. protected function setUp()
  12. {
  13. $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  14. }
  15. public function testGetItemRenderer()
  16. {
  17. $renderer = $this->createMock(\Magento\Framework\View\Element\AbstractBlock::class);
  18. $layout = $this->createPartialMock(
  19. \Magento\Framework\View\Layout::class,
  20. ['getChildName', 'getBlock', 'getGroupChildNames', '__wakeup']
  21. );
  22. $layout->expects(
  23. $this->at(0)
  24. )->method(
  25. 'getChildName'
  26. )->with(
  27. null,
  28. 'some-type'
  29. )->will(
  30. $this->returnValue('some-block-name')
  31. );
  32. $layout->expects(
  33. $this->at(1)
  34. )->method(
  35. 'getBlock'
  36. )->with(
  37. 'some-block-name'
  38. )->will(
  39. $this->returnValue($renderer)
  40. );
  41. /** @var $block \Magento\Sales\Block\Adminhtml\Items\AbstractItems */
  42. $block = $this->_objectManager->getObject(
  43. \Magento\Sales\Block\Adminhtml\Items\AbstractItems::class,
  44. [
  45. 'context' => $this->_objectManager->getObject(
  46. \Magento\Backend\Block\Template\Context::class,
  47. ['layout' => $layout]
  48. )
  49. ]
  50. );
  51. $this->assertSame($renderer, $block->getItemRenderer('some-type'));
  52. }
  53. /**
  54. * @expectedException \RuntimeException
  55. * @expectedExceptionMessage Renderer for type "some-type" does not exist.
  56. */
  57. public function testGetItemRendererThrowsExceptionForNonexistentRenderer()
  58. {
  59. $renderer = $this->createMock(\stdClass::class);
  60. $layout = $this->createPartialMock(
  61. \Magento\Framework\View\Layout::class,
  62. ['getChildName', 'getBlock', '__wakeup']
  63. );
  64. $layout->expects(
  65. $this->at(0)
  66. )->method(
  67. 'getChildName'
  68. )->with(
  69. null,
  70. 'some-type'
  71. )->will(
  72. $this->returnValue('some-block-name')
  73. );
  74. $layout->expects(
  75. $this->at(1)
  76. )->method(
  77. 'getBlock'
  78. )->with(
  79. 'some-block-name'
  80. )->will(
  81. $this->returnValue($renderer)
  82. );
  83. /** @var $block \Magento\Sales\Block\Adminhtml\Items\AbstractItems */
  84. $block = $this->_objectManager->getObject(
  85. \Magento\Sales\Block\Adminhtml\Items\AbstractItems::class,
  86. [
  87. 'context' => $this->_objectManager->getObject(
  88. \Magento\Backend\Block\Template\Context::class,
  89. ['layout' => $layout]
  90. )
  91. ]
  92. );
  93. $block->getItemRenderer('some-type');
  94. }
  95. }