15 class FormTest extends \PHPUnit\Framework\TestCase
28 $this->contextMock = $this->getMockBuilder(\
Magento\Framework\View\Element\UiComponent\ContextInterface::class)
29 ->getMockForAbstractClass();
30 $this->filterBuilderMock = $this->getMockBuilder(\
Magento\Framework\Api\FilterBuilder::class)
31 ->disableOriginalConstructor()
34 $this->contextMock->expects($this->never())->method(
'getProcessor');
36 $this->model =
new Form(
38 $this->filterBuilderMock
44 $this->assertEquals(
Form::NAME, $this->model->getComponentName());
47 public function testGetDataSourceData()
49 $requestFieldName =
'request_id';
50 $primaryFieldName =
'primary_id';
52 $row = [
'key' =>
'value'];
62 $this->getMockBuilder(\
Magento\Framework\View\Element\UiComponent\
DataProvider\DataProviderInterface::class)
64 $dataProviderMock->expects($this->once())
65 ->method(
'getRequestFieldName')
66 ->willReturn($requestFieldName);
67 $dataProviderMock->expects($this->once())
68 ->method(
'getPrimaryFieldName')
69 ->willReturn($primaryFieldName);
71 $this->contextMock->expects($this->any())
72 ->method(
'getDataProvider')
73 ->willReturn($dataProviderMock);
74 $this->contextMock->expects($this->once())
75 ->method(
'getRequestParam')
76 ->with($requestFieldName)
80 $filterMock = $this->getMockBuilder(\
Magento\Framework\Api\Filter::class)
81 ->disableOriginalConstructor()
84 $this->filterBuilderMock->expects($this->once())
86 ->with($primaryFieldName)
88 $this->filterBuilderMock->expects($this->once())
92 $this->filterBuilderMock->expects($this->once())
94 ->willReturn($filterMock);
96 $dataProviderMock->expects($this->once())
99 $dataProviderMock->expects($this->once())
103 $this->assertEquals($dataSource, $this->model->getDataSourceData());
106 public function testGetDataSourceDataWithoutData()
108 $requestFieldName =
'request_id';
109 $primaryFieldName =
'primary_id';
116 $this->getMockBuilder(\
Magento\Framework\View\Element\UiComponent\
DataProvider\DataProviderInterface::class)
118 $dataProviderMock->expects($this->once())
119 ->method(
'getRequestFieldName')
120 ->willReturn($requestFieldName);
121 $dataProviderMock->expects($this->once())
122 ->method(
'getPrimaryFieldName')
123 ->willReturn($primaryFieldName);
125 $this->contextMock->expects($this->any())
126 ->method(
'getDataProvider')
127 ->willReturn($dataProviderMock);
128 $this->contextMock->expects($this->once())
129 ->method(
'getRequestParam')
130 ->with($requestFieldName)
134 $filterMock = $this->getMockBuilder(\
Magento\Framework\Api\Filter::class)
135 ->disableOriginalConstructor()
138 $this->filterBuilderMock->expects($this->once())
140 ->with($primaryFieldName)
142 $this->filterBuilderMock->expects($this->once())
146 $this->filterBuilderMock->expects($this->once())
148 ->willReturn($filterMock);
150 $dataProviderMock->expects($this->once())
151 ->method(
'addFilter')
153 $dataProviderMock->expects($this->once())
157 $this->assertEquals($dataSource, $this->model->getDataSourceData());
160 public function testGetDataSourceDataWithoutId()
162 $requestFieldName =
'request_id';
163 $primaryFieldName =
'primary_id';
165 $row = [
'key' =>
'value'];
175 $this->getMockBuilder(\
Magento\Framework\View\Element\UiComponent\
DataProvider\DataProviderInterface::class)
177 $dataProviderMock->expects($this->once())
178 ->method(
'getRequestFieldName')
179 ->willReturn($requestFieldName);
180 $dataProviderMock->expects($this->once())
181 ->method(
'getPrimaryFieldName')
182 ->willReturn($primaryFieldName);
184 $this->contextMock->expects($this->any())
185 ->method(
'getDataProvider')
186 ->willReturn($dataProviderMock);
187 $this->contextMock->expects($this->once())
188 ->method(
'getRequestParam')
189 ->with($requestFieldName)
193 $filterMock = $this->getMockBuilder(\
Magento\Framework\Api\Filter::class)
194 ->disableOriginalConstructor()
197 $this->filterBuilderMock->expects($this->once())
199 ->with($primaryFieldName)
201 $this->filterBuilderMock->expects($this->once())
205 $this->filterBuilderMock->expects($this->once())
207 ->willReturn($filterMock);
209 $dataProviderMock->expects($this->once())
210 ->method(
'addFilter')
212 $dataProviderMock->expects($this->once())
216 $this->assertEquals($dataSource, $this->model->getDataSourceData());