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