Skip to content

Commit b6badfe

Browse files
committed
Merge branch 'develop' of github.corp.ebay.com:magento2/magento2ce into MAGETWO-38540
2 parents 2ce68ef + 108dec0 commit b6badfe

File tree

48 files changed

+1403
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1403
-138
lines changed

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

Lines changed: 10 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;
@@ -223,6 +223,7 @@ public function addFilter($field, $condition = null)
223223
* @param string|array $field
224224
* @param string|null $alias
225225
* @return void
226+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
226227
*/
227228
public function addField($field, $alias = null)
228229
{
@@ -260,6 +261,7 @@ public function setLimit($offset, $size)
260261
* @param string|null $field
261262
* @param bool $isAlias Alias identifier
262263
* @return void
264+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
263265
*/
264266
public function removeField($field, $isAlias = false)
265267
{
@@ -369,7 +371,7 @@ protected function getAttributesMeta(Type $entityType)
369371
}
370372
}
371373

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

app/code/Magento/Payment/Gateway/Command/GatewayCommand.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public function __construct(
5252
BuilderInterface $requestBuilder,
5353
TransferFactoryInterface $transferFactory,
5454
ClientInterface $client,
55-
HandlerInterface $handler,
56-
ValidatorInterface $validator
55+
HandlerInterface $handler = null,
56+
ValidatorInterface $validator = null
5757
) {
5858
$this->requestBuilder = $requestBuilder;
5959
$this->transferFactory = $transferFactory;
@@ -67,6 +67,7 @@ public function __construct(
6767
*
6868
* @param array $commandSubject
6969
* @return null
70+
* @throws \Exception
7071
*/
7172
public function execute(array $commandSubject)
7273
{
@@ -76,16 +77,22 @@ public function execute(array $commandSubject)
7677
);
7778

7879
$response = $this->client->placeRequest($transferO);
79-
80-
$result = $this->validator->validate(array_merge($commandSubject, ['response' => $response]));
81-
if ($result !== null && !$result->isValid()) {
82-
$commandSubject['payment']->getPayment()->setIsTransactionPending(true);
83-
return;
80+
if ($this->validator) {
81+
$result = $this->validator->validate(
82+
array_merge($commandSubject, ['response' => $response])
83+
);
84+
if (!$result->isValid()) {
85+
throw new CommandException(
86+
__(implode("\n", $result->getFailsDescription()))
87+
);
88+
}
8489
}
8590

86-
$this->handler->handle(
87-
$commandSubject,
88-
$response
89-
);
91+
if ($this->handler) {
92+
$this->handler->handle(
93+
$commandSubject,
94+
$response
95+
);
96+
}
9097
}
9198
}

0 commit comments

Comments
 (0)