Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeColumnTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class AttributeColumnTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $component;
14 
16  protected $context;
17 
20 
23 
25  protected $attributeMetadata;
26 
27  public function setup()
28  {
29  $this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
30  ->getMockForAbstractClass();
31  $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
32  ->disableOriginalConstructor()
33  ->getMock();
34  $this->context->expects($this->never())->method('getProcessor')->willReturn($processor);
35  $this->uiComponentFactory = $this->createMock(\Magento\Framework\View\Element\UiComponentFactory::class);
36  $this->attributeRepository = $this->createMock(
37  \Magento\Customer\Ui\Component\Listing\AttributeRepository::class
38  );
39  $this->attributeMetadata = $this->getMockForAbstractClass(
40  \Magento\Customer\Api\Data\AttributeMetadataInterface::class,
41  [],
42  '',
43  false
44  );
45 
46  $this->component = new AttributeColumn(
47  $this->context,
48  $this->uiComponentFactory,
49  $this->attributeRepository
50  );
51  $this->component->setData('name', 'gender');
52  }
53 
54  public function testPrepareDataSource()
55  {
56  $genderOptionId = 1;
57  $genderOptionLabel = 'Male';
58 
59  $dataSource = [
60  'data' => [
61  'items' => [
62  [
63  'name' => 'testName'
64  ],
65  [
66  'gender' => $genderOptionId
67  ]
68  ]
69  ]
70  ];
71  $expectedSource = [
72  'data' => [
73  'items' => [
74  [
75  'name' => 'testName'
76  ],
77  [
78  'gender' => $genderOptionLabel
79  ]
80  ]
81  ]
82  ];
83 
84  $this->attributeRepository->expects($this->once())
85  ->method('getMetadataByCode')
86  ->with('gender')
87  ->willReturn([
88  'attribute_code' => 'billing_attribute_code',
89  'frontend_input' => 'frontend-input',
90  'frontend_label' => 'frontend-label',
91  'backend_type' => 'backend-type',
92  'options' => [
93  [
94  'label' => $genderOptionLabel,
95  'value' => $genderOptionId
96  ]
97  ],
98  'is_used_in_grid' => true,
99  'is_visible_in_grid' => true,
100  'is_filterable_in_grid' => true,
101  'is_searchable_in_grid' => true,
102  ]);
103 
104  $dataSource = $this->component->prepareDataSource($dataSource);
105 
106  $this->assertEquals($expectedSource, $dataSource);
107  }
108 }
$processor
Definition: 404.php:10