ColumnFactoryTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Ui\Component;
  7. use Magento\Customer\Ui\Component\ColumnFactory;
  8. class ColumnFactoryTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Customer\Api\Data\OptionInterface|\PHPUnit_Framework_MockObject_MockObject */
  11. protected $attributeOption;
  12. /** @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject */
  13. protected $context;
  14. /** @var \Magento\Framework\View\Element\UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject */
  15. protected $componentFactory;
  16. /** @var \Magento\Customer\Api\Data\AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $attributeMetadata;
  18. /** @var \Magento\Ui\Component\Listing\Columns\ColumnInterface|\PHPUnit_Framework_MockObject_MockObject */
  19. protected $column;
  20. /** @var \Magento\Customer\Ui\Component\Listing\Column\InlineEditUpdater|\PHPUnit_Framework_MockObject_MockObject */
  21. protected $inlineEditUpdater;
  22. /** @var ColumnFactory */
  23. protected $columnFactory;
  24. protected function setUp()
  25. {
  26. $this->context = $this->getMockForAbstractClass(
  27. \Magento\Framework\View\Element\UiComponent\ContextInterface::class,
  28. [],
  29. '',
  30. false
  31. );
  32. $this->componentFactory = $this->createPartialMock(
  33. \Magento\Framework\View\Element\UiComponentFactory::class,
  34. ['create']
  35. );
  36. $this->attributeMetadata = $this->getMockForAbstractClass(
  37. \Magento\Customer\Api\Data\AttributeMetadataInterface::class,
  38. [],
  39. '',
  40. false
  41. );
  42. $this->column = $this->getMockForAbstractClass(
  43. \Magento\Ui\Component\Listing\Columns\ColumnInterface::class,
  44. [],
  45. '',
  46. false
  47. );
  48. $this->attributeOption = $this->getMockForAbstractClass(
  49. \Magento\Customer\Api\Data\OptionInterface::class,
  50. [],
  51. '',
  52. false
  53. );
  54. $this->inlineEditUpdater = $this->getMockBuilder(
  55. \Magento\Customer\Ui\Component\Listing\Column\InlineEditUpdater::class
  56. )
  57. ->disableOriginalConstructor()
  58. ->getMock();
  59. $this->columnFactory = new ColumnFactory($this->componentFactory, $this->inlineEditUpdater);
  60. }
  61. public function testCreate()
  62. {
  63. $columnName = 'created_at';
  64. $config = [
  65. 'data' => [
  66. 'js_config' => [
  67. 'component' => 'Magento_Ui/js/grid/columns/column',
  68. ],
  69. 'config' => [
  70. 'label' => __('Label'),
  71. 'dataType' => 'text',
  72. 'align' => 'left',
  73. 'visible' => true,
  74. 'options' => [
  75. [
  76. 'label' => 'Label',
  77. 'value' => 'Value'
  78. ]
  79. ],
  80. 'component' => 'Magento_Ui/js/grid/columns/column',
  81. ],
  82. ],
  83. 'context' => $this->context,
  84. ];
  85. $attributeData = [
  86. 'attribute_code' => 'billing_attribute_code',
  87. 'frontend_input' => 'text',
  88. 'frontend_label' => 'Label',
  89. 'backend_type' => 'backend-type',
  90. 'options' => [
  91. [
  92. 'label' => 'Label',
  93. 'value' => 'Value'
  94. ]
  95. ],
  96. 'is_used_in_grid' => true,
  97. 'is_visible_in_grid' => true,
  98. 'is_filterable_in_grid' => true,
  99. 'is_searchable_in_grid' => true,
  100. 'entity_type_code' => 'customer',
  101. 'validation_rules' => [],
  102. 'required' => false,
  103. ];
  104. $this->inlineEditUpdater->expects($this->once())
  105. ->method('applyEditing')
  106. ->with($this->column, 'text', []);
  107. $this->componentFactory->expects($this->once())
  108. ->method('create')
  109. ->with($columnName, 'column', $config)
  110. ->willReturn($this->column);
  111. $this->assertSame(
  112. $this->column,
  113. $this->columnFactory->create($attributeData, $columnName, $this->context)
  114. );
  115. }
  116. }