Skip to content

Commit 209c713

Browse files
author
Sergey Shvets
committed
MAGETWO-86239: Customer Address attribute value length is still validated when min/max length fields are not displayed at the backend
1 parent c3ceef0 commit 209c713

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Eav\Test\Unit\Model\Attribute\Data;
78

9+
use Magento\Framework\Locale\ResolverInterface;
10+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
11+
812
class MultilineTest extends \PHPUnit\Framework\TestCase
913
{
1014
/**
@@ -13,15 +17,18 @@ class MultilineTest extends \PHPUnit\Framework\TestCase
1317
protected $model;
1418

1519
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject
20+
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Stdlib\StringUtils
1721
*/
1822
protected $stringMock;
1923

2024
protected function setUp()
2125
{
22-
$timezoneMock = $this->createMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
26+
/** @var \PHPUnit_Framework_MockObject_MockObject | TimezoneInterface $timezoneMock */
27+
$timezoneMock = $this->createMock(TimezoneInterface::class);
28+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Psr\Log\LoggerInterface $loggerMock */
2329
$loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
24-
$localeResolverMock = $this->createMock(\Magento\Framework\Locale\ResolverInterface::class);
30+
/** @var \PHPUnit_Framework_MockObject_MockObject | ResolverInterface $localeResolverMock */
31+
$localeResolverMock = $this->createMock(ResolverInterface::class);
2532
$this->stringMock = $this->createMock(\Magento\Framework\Stdlib\StringUtils::class);
2633

2734
$this->model = new \Magento\Eav\Model\Attribute\Data\Multiline(
@@ -33,19 +40,23 @@ protected function setUp()
3340
}
3441

3542
/**
36-
* @covers \Magento\Eav\Model\Attribute\Data\Multiline::extractValue
43+
* @covers \Magento\Eav\Model\Attribute\Data\Multiline::extractValue
3744
*
3845
* @param mixed $param
3946
* @param mixed $expectedResult
4047
* @dataProvider extractValueDataProvider
4148
*/
4249
public function testExtractValue($param, $expectedResult)
4350
{
51+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\RequestInterface $requestMock */
4452
$requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
53+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Eav\Model\Attribute $attributeMock */
4554
$attributeMock = $this->createMock(\Magento\Eav\Model\Attribute::class);
4655

4756
$requestMock->expects($this->once())->method('getParam')->will($this->returnValue($param));
48-
$attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue('attributeCode'));
57+
$attributeMock->expects($this->once())
58+
->method('getAttributeCode')
59+
->will($this->returnValue('attributeCode'));
4960

5061
$this->model->setAttribute($attributeMock);
5162
$this->assertEquals($expectedResult, $this->model->extractValue($requestMock));
@@ -69,17 +80,21 @@ public function extractValueDataProvider()
6980
}
7081

7182
/**
72-
* @covers \Magento\Eav\Model\Attribute\Data\Multiline::outputValue
83+
* @covers \Magento\Eav\Model\Attribute\Data\Multiline::outputValue
7384
*
7485
* @param string $format
7586
* @param mixed $expectedResult
7687
* @dataProvider outputValueDataProvider
7788
*/
7889
public function testOutputValue($format, $expectedResult)
7990
{
91+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Model\AbstractModel $entityMock */
8092
$entityMock = $this->createMock(\Magento\Framework\Model\AbstractModel::class);
81-
$entityMock->expects($this->once())->method('getData')->will($this->returnValue("value1\nvalue2"));
93+
$entityMock->expects($this->once())
94+
->method('getData')
95+
->will($this->returnValue("value1\nvalue2"));
8296

97+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Eav\Model\Attribute $attributeMock */
8398
$attributeMock = $this->createMock(\Magento\Eav\Model\Attribute::class);
8499

85100
$this->model->setEntity($entityMock);
@@ -113,8 +128,8 @@ public function outputValueDataProvider()
113128
}
114129

115130
/**
116-
* @covers \Magento\Eav\Model\Attribute\Data\Multiline::validateValue
117-
* @covers \Magento\Eav\Model\Attribute\Data\Text::validateValue
131+
* @covers \Magento\Eav\Model\Attribute\Data\Multiline::validateValue
132+
* @covers \Magento\Eav\Model\Attribute\Data\Text::validateValue
118133
*
119134
* @param mixed $value
120135
* @param bool $isAttributeRequired
@@ -124,14 +139,23 @@ public function outputValueDataProvider()
124139
*/
125140
public function testValidateValue($value, $isAttributeRequired, $rules, $expectedResult)
126141
{
142+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Model\AbstractModel $entityMock */
127143
$entityMock = $this->createMock(\Magento\Framework\Model\AbstractModel::class);
128-
$entityMock->expects($this->any())->method('getDataUsingMethod')->will($this->returnValue("value1\nvalue2"));
144+
$entityMock->expects($this->any())
145+
->method('getDataUsingMethod')
146+
->will($this->returnValue("value1\nvalue2"));
129147

148+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Eav\Model\Attribute $attributeMock */
130149
$attributeMock = $this->createMock(\Magento\Eav\Model\Attribute::class);
131150
$attributeMock->expects($this->any())->method('getMultilineCount')->will($this->returnValue(2));
132151
$attributeMock->expects($this->any())->method('getValidateRules')->will($this->returnValue($rules));
133-
$attributeMock->expects($this->any())->method('getStoreLabel')->will($this->returnValue('Label'));
134-
$attributeMock->expects($this->any())->method('getIsRequired')->will($this->returnValue($isAttributeRequired));
152+
$attributeMock->expects($this->any())
153+
->method('getStoreLabel')
154+
->will($this->returnValue('Label'));
155+
156+
$attributeMock->expects($this->any())
157+
->method('getIsRequired')
158+
->will($this->returnValue($isAttributeRequired));
135159

136160
$this->stringMock->expects($this->any())->method('strlen')->will($this->returnValue(5));
137161

@@ -159,21 +183,21 @@ public function validateValueDataProvider()
159183
'expectedResult' => true,
160184
],
161185
[
162-
'value' => ['value1', 'value2'],
186+
'value' => ['value1', 'value2'],
163187
'isAttributeRequired' => false,
164188
'rules' => [],
165189
'expectedResult' => true,
166190
],
167191
[
168192
'value' => 'value',
169193
'isAttributeRequired' => false,
170-
'rules' => ['max_text_length' => 3],
194+
'rules' => ['input_validation' => 'other', 'max_text_length' => 3],
171195
'expectedResult' => ['"Label" length must be equal or less than 3 characters.'],
172196
],
173197
[
174198
'value' => 'value',
175199
'isAttributeRequired' => false,
176-
'rules' => ['min_text_length' => 10],
200+
'rules' => ['input_validation' => 'other', 'min_text_length' => 10],
177201
'expectedResult' => ['"Label" length must be equal or greater than 10 characters.'],
178202
],
179203
[

0 commit comments

Comments
 (0)