Skip to content

Commit 736c768

Browse files
author
Sergey Shvets
committed
MAGETWO-91737: Customer Address attribute value length is still validated when min/max length fields are not displayed at the backend
1 parent 46562d3 commit 736c768

File tree

8 files changed

+90
-22
lines changed

8 files changed

+90
-22
lines changed

app/code/Magento/Customer/Model/Metadata/Form/Text.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public function __construct(
4343
}
4444

4545
/**
46-
* {@inheritdoc}
46+
* @inheritdoc
4747
*/
4848
public function extractValue(\Magento\Framework\App\RequestInterface $request)
4949
{
5050
return $this->_applyInputFilter($this->_getRequestValue($request));
5151
}
5252

5353
/**
54-
* {@inheritdoc}
54+
* @inheritdoc
5555
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5656
* @SuppressWarnings(PHPMD.NPathComplexity)
5757
*/
@@ -88,23 +88,23 @@ public function validateValue($value)
8888
}
8989

9090
/**
91-
* {@inheritdoc}
91+
* @inheritdoc
9292
*/
9393
public function compactValue($value)
9494
{
9595
return $value;
9696
}
9797

9898
/**
99-
* {@inheritdoc}
99+
* @inheritdoc
100100
*/
101101
public function restoreValue($value)
102102
{
103103
return $this->compactValue($value);
104104
}
105105

106106
/**
107-
* {@inheritdoc}
107+
* @inheritdoc
108108
*/
109109
public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT)
110110
{

app/code/Magento/Customer/Test/Unit/Controller/Address/FormPostTest.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Customer\Test\Unit\Controller\Address;
78

89
use Magento\Customer\Api\AddressRepositoryInterface;
@@ -162,6 +163,9 @@ class FormPostTest extends \PHPUnit\Framework\TestCase
162163
*/
163164
private $customerAddressMapper;
164165

166+
/**
167+
* {@inheritDoc}
168+
*/
165169
protected function setUp()
166170
{
167171
$this->prepareContext();
@@ -230,7 +234,10 @@ protected function setUp()
230234
);
231235
}
232236

233-
protected function prepareContext()
237+
/**
238+
* Prepares context
239+
*/
240+
protected function prepareContext(): void
234241
{
235242
$this->context = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class)
236243
->disableOriginalConstructor()
@@ -284,7 +291,10 @@ protected function prepareContext()
284291
->willReturn($this->messageManager);
285292
}
286293

287-
protected function prepareAddress()
294+
/**
295+
* Prepare address
296+
*/
297+
protected function prepareAddress(): void
288298
{
289299
$this->addressRepository = $this->getMockBuilder(\Magento\Customer\Api\AddressRepositoryInterface::class)
290300
->getMockForAbstractClass();
@@ -303,7 +313,10 @@ protected function prepareAddress()
303313
->willReturn($this->addressData);
304314
}
305315

306-
protected function prepareRegion()
316+
/**
317+
* Prepare region
318+
*/
319+
protected function prepareRegion(): void
307320
{
308321
$this->region = $this->getMockBuilder(\Magento\Directory\Model\Region::class)
309322
->disableOriginalConstructor()
@@ -335,7 +348,10 @@ protected function prepareRegion()
335348
->willReturn($this->regionData);
336349
}
337350

338-
protected function prepareForm()
351+
/**
352+
* Prepare form
353+
*/
354+
protected function prepareForm(): void
339355
{
340356
$this->form = $this->getMockBuilder(\Magento\Customer\Model\Metadata\Form::class)
341357
->disableOriginalConstructor()
@@ -346,7 +362,10 @@ protected function prepareForm()
346362
->getMock();
347363
}
348364

349-
public function testExecuteNoFormKey()
365+
/**
366+
* Test form without formKey
367+
*/
368+
public function testExecuteNoFormKey(): void
350369
{
351370
$this->formKeyValidator->expects($this->once())
352371
->method('validate')
@@ -361,7 +380,10 @@ public function testExecuteNoFormKey()
361380
$this->assertEquals($this->resultRedirect, $this->model->execute());
362381
}
363382

364-
public function testExecuteNoPostData()
383+
/**
384+
* Test executing without post data
385+
*/
386+
public function testExecuteNoPostData(): void
365387
{
366388
$postValue = 'post_value';
367389
$url = 'url';
@@ -409,10 +431,11 @@ public function testExecuteNoPostData()
409431
}
410432

411433
/**
434+
* Tests executing
435+
*
412436
* @param int $addressId
413437
* @param int $countryId
414438
* @param int $customerId
415-
* @param bool $isRegionRequired
416439
* @param int $regionId
417440
* @param string $region
418441
* @param string $regionCode
@@ -433,7 +456,7 @@ public function testExecute(
433456
$newRegionId,
434457
$newRegion,
435458
$newRegionCode
436-
) {
459+
): void {
437460
$existingAddressData = [
438461
'country_id' => $countryId,
439462
'region_id' => $regionId,
@@ -517,7 +540,8 @@ public function testExecute(
517540
->willReturnMap([
518541
[
519542
$this->regionData,
520-
$regionData, \Magento\Customer\Api\Data\RegionInterface::class,
543+
$regionData,
544+
\Magento\Customer\Api\Data\RegionInterface::class,
521545
$this->dataObjectHelper,
522546
],
523547
[
@@ -581,7 +605,7 @@ public function testExecute(
581605
/**
582606
* @return array
583607
*/
584-
public function dataProviderTestExecute()
608+
public function dataProviderTestExecute(): array
585609
{
586610
return [
587611
[1, 1, 1, null, '', null, '', null, ''],
@@ -612,7 +636,10 @@ public function dataProviderTestExecute()
612636
];
613637
}
614638

615-
public function testExecuteInputException()
639+
/**
640+
* Tests input exception
641+
*/
642+
public function testExecuteInputException(): void
616643
{
617644
$addressId = 1;
618645
$postValue = 'post_value';
@@ -674,7 +701,10 @@ public function testExecuteInputException()
674701
$this->assertEquals($this->resultRedirect, $this->model->execute());
675702
}
676703

677-
public function testExecuteException()
704+
/**
705+
* Tests exception
706+
*/
707+
public function testExecuteException(): void
678708
{
679709
$addressId = 1;
680710
$postValue = 'post_value';

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/TextTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class TextTest extends AbstractFormTestCase
1616
/** @var \Magento\Framework\Stdlib\StringUtils */
1717
protected $stringHelper;
1818

19+
/**
20+
* {@inheritDoc}
21+
*/
1922
protected function setUp()
2023
{
2124
parent::setUp();

app/code/Magento/Eav/Test/Unit/Model/Attribute/Data/MultilineTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class MultilineTest extends \PHPUnit\Framework\TestCase
2121
*/
2222
protected $stringMock;
2323

24+
/**
25+
* {@inheritDoc}
26+
*/
2427
protected function setUp()
2528
{
2629
/** @var TimezoneInterface $timezoneMock */

app/code/Magento/Eav/Test/Unit/Model/Attribute/Data/TextTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class TextTest extends \PHPUnit\Framework\TestCase
1313
*/
1414
protected $_model;
1515

16+
/**
17+
* {@inheritDoc}
18+
*/
1619
protected function setUp()
1720
{
1821
$locale = $this->createMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
@@ -33,27 +36,39 @@ protected function setUp()
3336
);
3437
}
3538

39+
/**
40+
* {@inheritDoc}
41+
*/
3642
protected function tearDown()
3743
{
3844
$this->_model = null;
3945
}
4046

41-
public function testValidateValueString()
47+
/**
48+
* Test for string validation
49+
*/
50+
public function testValidateValueString(): void
4251
{
4352
$inputValue = '0';
4453
$expectedResult = true;
4554
$this->assertEquals($expectedResult, $this->_model->validateValue($inputValue));
4655
}
4756

48-
public function testValidateValueInteger()
57+
/**
58+
* Test for integer validation
59+
*/
60+
public function testValidateValueInteger(): void
4961
{
5062
$inputValue = 0;
5163
$expectedResult = ['"Test" is a required value.'];
5264
$result = $this->_model->validateValue($inputValue);
5365
$this->assertEquals($expectedResult, [(string)$result[0]]);
5466
}
5567

56-
public function testWithoutLengthValidation()
68+
/**
69+
* Test without length validation
70+
*/
71+
public function testWithoutLengthValidation(): void
5772
{
5873
$expectedResult = true;
5974
$defaultAttributeData = [

app/code/Magento/Ui/Test/Unit/DataProvider/EavValidationRulesTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class EavValidationRulesTest extends \PHPUnit\Framework\TestCase
3030
*/
3131
protected $attributeMock;
3232

33+
/**
34+
* {@inheritDoc}
35+
*/
3336
protected function setUp()
3437
{
3538
$this->objectManager = new ObjectManager($this);
@@ -43,11 +46,13 @@ protected function setUp()
4346
}
4447

4548
/**
49+
* @param string $attributeInputType
50+
* @param mixed $validateRules
4651
* @param array $data
4752
* @param array $expected
4853
* @dataProvider buildDataProvider
4954
*/
50-
public function testBuild($attributeInputType, $validateRules, $data, $expected)
55+
public function testBuild($attributeInputType, $validateRules, $data, $expected): void
5156
{
5257
$this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($attributeInputType);
5358
$this->attributeMock->expects($this->any())->method('getValidateRules')->willReturn($validateRules);

dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class AddressTest extends \Magento\TestFramework\TestCase\AbstractController
1818
/** @var FormKey */
1919
private $formKey;
2020

21+
/**
22+
* {@inheritDoc}
23+
*/
2124
protected function setUp()
2225
{
2326
parent::setUp();

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendControlle
4444
/** @var \Magento\TestFramework\ObjectManager */
4545
protected $objectManager;
4646

47+
/**
48+
* {@inheritDoc}
49+
*/
4750
protected function setUp()
4851
{
4952
parent::setUp();
@@ -67,6 +70,9 @@ protected function setUp()
6770
);
6871
}
6972

73+
/**
74+
* {@inheritDoc}
75+
*/
7076
protected function tearDown()
7177
{
7278
/**
@@ -522,7 +528,10 @@ public function testEditAction()
522528
$this->assertContains('<h1 class="page-title">test firstname test lastname</h1>', $body);
523529
}
524530

525-
public function testNewAction()
531+
/**
532+
* Tests new action
533+
*/
534+
public function testNewAction(): void
526535
{
527536
$this->dispatch('backend/customer/index/edit');
528537
$body = $this->getResponse()->getBody();

0 commit comments

Comments
 (0)