Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ColumnFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ColumnFactoryTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $attributeOption;
14 
16  protected $context;
17 
19  protected $componentFactory;
20 
22  protected $attributeMetadata;
23 
25  protected $column;
26 
28  protected $inlineEditUpdater;
29 
31  protected $columnFactory;
32 
33  protected function setUp()
34  {
35  $this->context = $this->getMockForAbstractClass(
36  \Magento\Framework\View\Element\UiComponent\ContextInterface::class,
37  [],
38  '',
39  false
40  );
41  $this->componentFactory = $this->createPartialMock(
42  \Magento\Framework\View\Element\UiComponentFactory::class,
43  ['create']
44  );
45  $this->attributeMetadata = $this->getMockForAbstractClass(
46  \Magento\Customer\Api\Data\AttributeMetadataInterface::class,
47  [],
48  '',
49  false
50  );
51  $this->column = $this->getMockForAbstractClass(
52  \Magento\Ui\Component\Listing\Columns\ColumnInterface::class,
53  [],
54  '',
55  false
56  );
57  $this->attributeOption = $this->getMockForAbstractClass(
58  \Magento\Customer\Api\Data\OptionInterface::class,
59  [],
60  '',
61  false
62  );
63 
64  $this->inlineEditUpdater = $this->getMockBuilder(
65  \Magento\Customer\Ui\Component\Listing\Column\InlineEditUpdater::class
66  )
67  ->disableOriginalConstructor()
68  ->getMock();
69 
70  $this->columnFactory = new ColumnFactory($this->componentFactory, $this->inlineEditUpdater);
71  }
72 
73  public function testCreate()
74  {
75  $columnName = 'created_at';
76  $config = [
77  'data' => [
78  'js_config' => [
79  'component' => 'Magento_Ui/js/grid/columns/column',
80  ],
81  'config' => [
82  'label' => __('Label'),
83  'dataType' => 'text',
84  'align' => 'left',
85  'visible' => true,
86  'options' => [
87  [
88  'label' => 'Label',
89  'value' => 'Value'
90  ]
91  ],
92  'component' => 'Magento_Ui/js/grid/columns/column',
93  ],
94  ],
95  'context' => $this->context,
96  ];
97  $attributeData = [
98  'attribute_code' => 'billing_attribute_code',
99  'frontend_input' => 'text',
100  'frontend_label' => 'Label',
101  'backend_type' => 'backend-type',
102  'options' => [
103  [
104  'label' => 'Label',
105  'value' => 'Value'
106  ]
107  ],
108  'is_used_in_grid' => true,
109  'is_visible_in_grid' => true,
110  'is_filterable_in_grid' => true,
111  'is_searchable_in_grid' => true,
112  'entity_type_code' => 'customer',
113  'validation_rules' => [],
114  'required' => false,
115  ];
116  $this->inlineEditUpdater->expects($this->once())
117  ->method('applyEditing')
118  ->with($this->column, 'text', []);
119  $this->componentFactory->expects($this->once())
120  ->method('create')
121  ->with($columnName, 'column', $config)
122  ->willReturn($this->column);
123 
124  $this->assertSame(
125  $this->column,
126  $this->columnFactory->create($attributeData, $columnName, $this->context)
127  );
128  }
129 }
$config
Definition: fraud_order.php:17
__()
Definition: __.php:13