ListingTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Test\Unit\Component;
  7. use Magento\Ui\Component\Listing;
  8. use Magento\Ui\Component\Listing\Columns;
  9. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  10. use Magento\Framework\View\Element\UiComponent\ContextInterface;
  11. /**
  12. * Class ListingTest
  13. */
  14. class ListingTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var ContextInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $contextMock;
  20. /**
  21. * @var ObjectManager
  22. */
  23. protected $objectManager;
  24. /**
  25. * Set up
  26. */
  27. protected function setUp()
  28. {
  29. $this->objectManager = new ObjectManager($this);
  30. $this->contextMock = $this->getMockForAbstractClass(
  31. \Magento\Framework\View\Element\UiComponent\ContextInterface::class,
  32. [],
  33. '',
  34. false
  35. );
  36. }
  37. /**
  38. * Run test getComponentName method
  39. *
  40. * @return void
  41. */
  42. public function testGetComponentName()
  43. {
  44. $this->contextMock->expects($this->never())->method('getProcessor');
  45. /** @var Listing $listing */
  46. $listing = $this->objectManager->getObject(
  47. \Magento\Ui\Component\Listing::class,
  48. [
  49. 'context' => $this->contextMock,
  50. 'data' => []
  51. ]
  52. );
  53. $this->assertTrue($listing->getComponentName() === Listing::NAME);
  54. }
  55. /**
  56. * Run test prepare method
  57. *
  58. * @return void
  59. */
  60. public function testPrepare()
  61. {
  62. $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
  63. ->disableOriginalConstructor()
  64. ->getMock();
  65. $this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($processor);
  66. $buttons = [
  67. 'button1' => 'button1',
  68. 'button2' => 'button2'
  69. ];
  70. /** @var Listing $listing */
  71. $listing = $this->objectManager->getObject(
  72. \Magento\Ui\Component\Listing::class,
  73. [
  74. 'context' => $this->contextMock,
  75. 'data' => [
  76. 'js_config' => [
  77. 'extends' => 'test_config_extends',
  78. 'testData' => 'testValue',
  79. ],
  80. 'buttons' => $buttons
  81. ]
  82. ]
  83. );
  84. $this->contextMock->expects($this->at(0))
  85. ->method('getNamespace')
  86. ->willReturn(Listing::NAME);
  87. $this->contextMock->expects($this->once())
  88. ->method('addComponentDefinition')
  89. ->with($listing->getComponentName(), ['extends' => 'test_config_extends', 'testData' => 'testValue']);
  90. $this->contextMock->expects($this->once())
  91. ->method('addButtons')
  92. ->with($buttons, $listing);
  93. $listing->prepare();
  94. }
  95. }