Skip to content

Commit db90fdf

Browse files
committed
MAGETWO-37956: It's unable to create Customer from Backend if there is multiline form element
1 parent 86646fc commit db90fdf

File tree

19 files changed

+677
-37
lines changed

19 files changed

+677
-37
lines changed

app/code/Magento/Customer/Model/Customer/DataProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Eav\Model\Entity\Type;
1010
use Magento\Customer\Model\Address;
1111
use Magento\Customer\Model\Customer;
12-
use Magento\Ui\DataProvider\EavValidationRul;
12+
use Magento\Ui\DataProvider\EavValidationRules;
1313
use Magento\Customer\Model\Resource\Customer\Collection;
1414
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;
1515
use Magento\Customer\Model\Resource\Customer\CollectionFactory as CustomerCollectionFactory;
@@ -75,7 +75,7 @@ class DataProvider implements DataProviderInterface
7575
'sortOrder' => 'sort_order',
7676
'notice' => 'note',
7777
'default' => 'default_value',
78-
'size' => 'scope_multiline_count'
78+
'size' => 'multiline_count'
7979
];
8080

8181
/**
@@ -90,17 +90,17 @@ class DataProvider implements DataProviderInterface
9090
];
9191

9292
/**
93-
* @var EavValidationRul
93+
* @var EavValidationRules
9494
*/
95-
protected $eavValidationRul;
95+
protected $eavValidationRules;
9696

9797
/**
9898
* Constructor
9999
*
100100
* @param string $name
101101
* @param string $primaryFieldName
102102
* @param string $requestFieldName
103-
* @param EavValidationRul $eavValidationRul
103+
* @param EavValidationRules $eavValidationRules
104104
* @param CustomerCollectionFactory $customerCollectionFactory
105105
* @param Config $eavConfig
106106
* @param array $meta
@@ -110,7 +110,7 @@ public function __construct(
110110
$name,
111111
$primaryFieldName,
112112
$requestFieldName,
113-
EavValidationRul $eavValidationRul,
113+
EavValidationRules $eavValidationRules,
114114
CustomerCollectionFactory $customerCollectionFactory,
115115
Config $eavConfig,
116116
array $meta = [],
@@ -119,7 +119,7 @@ public function __construct(
119119
$this->name = $name;
120120
$this->primaryFieldName = $primaryFieldName;
121121
$this->requestFieldName = $requestFieldName;
122-
$this->eavValidationRul = $eavValidationRul;
122+
$this->eavValidationRules = $eavValidationRules;
123123
$this->collection = $customerCollectionFactory->create();
124124
$this->collection->addAttributeToSelect('*');
125125
$this->eavConfig = $eavConfig;
@@ -369,7 +369,7 @@ protected function getAttributesMeta(Type $entityType)
369369
}
370370
}
371371

372-
$rules = $this->eavValidationRul->build($attribute, $meta[$code]);
372+
$rules = $this->eavValidationRules->build($attribute, $meta[$code]);
373373
if (!empty($rules)) {
374374
$meta[$code]['validation'] = $rules;
375375
}
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Model\Customer;
7+
8+
use Magento\Eav\Model\Config;
9+
use Magento\Eav\Model\Entity\Type;
10+
use Magento\Ui\DataProvider\EavValidationRules;
11+
use Magento\Customer\Model\Customer\DataProvider;
12+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13+
use Magento\Customer\Model\Resource\Customer\CollectionFactory;
14+
15+
/**
16+
* Class DataProviderTest
17+
*
18+
* Test for class \Magento\Customer\Model\Customer\DataProvider
19+
*/
20+
class DataProviderTest extends \PHPUnit_Framework_TestCase
21+
{
22+
const ATTRIBUTE_CODE = 'test-code';
23+
const OPTIONS_RESULT = 'test-options';
24+
25+
/**
26+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $eavConfigMock;
29+
30+
/**
31+
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $customerCollectionFactoryMock;
34+
35+
/**
36+
* @var EavValidationRules|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $eavValidationRulesMock;
39+
40+
/**
41+
* Set up
42+
*
43+
* @return void
44+
*/
45+
protected function setUp()
46+
{
47+
$this->eavConfigMock = $this->getMockBuilder('Magento\Eav\Model\Config')
48+
->disableOriginalConstructor()
49+
->getMock();
50+
$this->customerCollectionFactoryMock = $this->getMockBuilder(
51+
'Magento\Customer\Model\Resource\Customer\CollectionFactory'
52+
)->setMethods(['create'])
53+
->disableOriginalConstructor()
54+
->getMockForAbstractClass();
55+
$this->eavValidationRulesMock = $this->getMockBuilder('Magento\Ui\DataProvider\EavValidationRules')
56+
->disableOriginalConstructor()
57+
->getMock();
58+
}
59+
60+
/**
61+
* Run test getAttributesMeta method
62+
*
63+
* @param array $expected
64+
* @return void
65+
*
66+
* @dataProvider getAttributesMetaDataProvider
67+
*/
68+
public function testGetAttributesMetaWithOptions(array $expected)
69+
{
70+
$dataProvider = new DataProvider(
71+
'test-name',
72+
'primary-field-name',
73+
'request-field-name',
74+
$this->eavValidationRulesMock,
75+
$this->getCustomerCollectionFactoryMock(),
76+
$this->getEavConfigMock()
77+
);
78+
79+
$meta = $dataProvider->getMeta();
80+
$this->assertNotEmpty($meta);
81+
$this->assertEquals($expected, $meta);
82+
}
83+
84+
/**
85+
* Data provider for testGetAttributesMeta
86+
*
87+
* @return array
88+
*/
89+
public function getAttributesMetaDataProvider()
90+
{
91+
return [
92+
[
93+
'expected' => [
94+
'customer' => [
95+
'fields' => [
96+
self::ATTRIBUTE_CODE => [
97+
'dataType' => 'frontend_input',
98+
'formElement' => 'frontend_input',
99+
'options' => 'test-options',
100+
'visible' => 'is_visible',
101+
'required' => 'is_required',
102+
'label' => 'frontend_label',
103+
'sortOrder' => 'sort_order',
104+
'notice' => 'note',
105+
'default' => 'default_value',
106+
'size' => 'multiline_count',
107+
]
108+
]
109+
],
110+
'address' => [
111+
'fields' => [
112+
self::ATTRIBUTE_CODE => [
113+
'dataType' => 'frontend_input',
114+
'formElement' => 'frontend_input',
115+
'options' => 'test-options',
116+
'visible' => 'is_visible',
117+
'required' => 'is_required',
118+
'label' => 'frontend_label',
119+
'sortOrder' => 'sort_order',
120+
'notice' => 'note',
121+
'default' => 'default_value',
122+
'size' => 'multiline_count',
123+
]
124+
]
125+
]
126+
]
127+
]
128+
];
129+
}
130+
131+
/**
132+
* @return CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
133+
*/
134+
protected function getCustomerCollectionFactoryMock()
135+
{
136+
$collectionMock = $this->getMockBuilder('Magento\Customer\Model\Resource\Customer\Collection')
137+
->disableOriginalConstructor()
138+
->getMock();
139+
140+
$collectionMock->expects($this->once())
141+
->method('addAttributeToSelect')
142+
->with('*');
143+
144+
$this->customerCollectionFactoryMock->expects($this->once())
145+
->method('create')
146+
->willReturn($collectionMock);
147+
148+
return $this->customerCollectionFactoryMock;
149+
}
150+
151+
/**
152+
* @return Config|\PHPUnit_Framework_MockObject_MockObject
153+
*/
154+
protected function getEavConfigMock()
155+
{
156+
$this->eavConfigMock->expects($this->at(0))
157+
->method('getEntityType')
158+
->with('customer')
159+
->willReturn($this->getTypeCustomerMock());
160+
$this->eavConfigMock->expects($this->at(1))
161+
->method('getEntityType')
162+
->with('customer_address')
163+
->willReturn($this->getTypeAddressMock());
164+
165+
return $this->eavConfigMock;
166+
}
167+
168+
/**
169+
* @return Type|\PHPUnit_Framework_MockObject_MockObject
170+
*/
171+
protected function getTypeCustomerMock()
172+
{
173+
$typeCustomerMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Type')
174+
->disableOriginalConstructor()
175+
->getMock();
176+
177+
$typeCustomerMock->expects($this->once())
178+
->method('getAttributeCollection')
179+
->willReturn($this->getAttributeMock());
180+
181+
return $typeCustomerMock;
182+
}
183+
184+
/**
185+
* @return Type|\PHPUnit_Framework_MockObject_MockObject
186+
*/
187+
protected function getTypeAddressMock()
188+
{
189+
$typeAddressMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Type')
190+
->disableOriginalConstructor()
191+
->getMock();
192+
193+
$typeAddressMock->expects($this->once())
194+
->method('getAttributeCollection')
195+
->willReturn($this->getAttributeMock());
196+
197+
return $typeAddressMock;
198+
}
199+
200+
/**
201+
* @return AbstractAttribute[]|\PHPUnit_Framework_MockObject_MockObject[]
202+
*/
203+
protected function getAttributeMock()
204+
{
205+
$attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\AbstractAttribute')
206+
->setMethods(['getAttributeCode', 'getDataUsingMethod', 'usesSource', 'getSource'])
207+
->disableOriginalConstructor()
208+
->getMockForAbstractClass();
209+
$sourceMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Source\AbstractSource')
210+
->disableOriginalConstructor()
211+
->getMockForAbstractClass();
212+
213+
$sourceMock->expects($this->any())
214+
->method('getAllOptions')
215+
->willReturn(self::OPTIONS_RESULT);
216+
217+
$attributeMock->expects($this->once())
218+
->method('getAttributeCode')
219+
->willReturn(self::ATTRIBUTE_CODE);
220+
221+
$attributeMock->expects($this->any())
222+
->method('getDataUsingMethod')
223+
->willReturnCallback(
224+
function ($origName) {
225+
return $origName;
226+
}
227+
);
228+
$attributeMock->expects($this->any())
229+
->method('usesSource')
230+
->willReturn(true);
231+
$attributeMock->expects($this->any())
232+
->method('getSource')
233+
->willReturn($sourceMock);
234+
235+
$this->eavValidationRulesMock->expects($this->any())
236+
->method('build')
237+
->with($attributeMock, $this->logicalNot($this->isEmpty()));
238+
239+
return [$attributeMock];
240+
}
241+
}

app/code/Magento/Ui/Component/AbstractComponent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
use Magento\Framework\Object;
99
use Magento\Framework\View\Element\UiComponentInterface;
1010
use Magento\Framework\View\Element\UiComponent\ContextInterface;
11-
use Magento\Framework\View\Element\UiComponent\JsConfigInterface;
1211
use Magento\Framework\View\Element\UiComponent\DataSourceInterface;
1312

1413
/**
1514
* Abstract class AbstractComponent
1615
* @SuppressWarnings(PHPMD.NumberOfChildren)
1716
*/
18-
abstract class AbstractComponent extends Object implements UiComponentInterface, JsConfigInterface
17+
abstract class AbstractComponent extends Object implements UiComponentInterface
1918
{
2019
/**
2120
* Render context

app/code/Magento/Ui/Component/Container.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Ui\Component;
77

8-
use Magento\Framework\View\Element\UiComponent\DataSourceInterface;
9-
108
/**
119
* Class Container
1210
*/

app/code/Magento/Ui/Component/Form.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Ui\Component;
77

8-
use Magento\Framework\View\Element\UiComponent\DataSourceInterface;
9-
108
/**
119
* Class Form
1210
*/

0 commit comments

Comments
 (0)