Skip to content

Commit ad81a01

Browse files
committed
AC-13535: Minimum and maximum value validation does not work for DOB attribute on Storefront
1 parent 76d0861 commit ad81a01

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

app/code/Magento/Customer/Test/Unit/Plugin/ValidateDobOnSaveTest.php

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ public function testInvalidDobStringThrows(): void
5050
$this->mockAttributeRulesArray(['date_range_min' => '1980-01-01', 'date_range_max' => '2000-12-31']);
5151

5252
$called = false;
53-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
54-
$called = true;
55-
return $c;
56-
};
53+
$proceed = $this->proceedPlugin($called, $customer);
5754

5855
$this->expectException(InputException::class);
5956
$this->expectExceptionMessage('Date of Birth is invalid.');
@@ -68,10 +65,7 @@ public function testDobBeforeMinThrows(): void
6865
$this->mockAttributeRulesArray(['date_range_min' => '1980-01-01', 'date_range_max' => '2000-12-31']);
6966

7067
$called = false;
71-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
72-
$called = true;
73-
return $c;
74-
};
68+
$proceed = $this->proceedPlugin($called, $customer);
7569

7670
$this->expectException(InputException::class);
7771
$this->expectExceptionMessage('on or after 1980-01-01');
@@ -86,10 +80,7 @@ public function testDobAfterMaxThrows(): void
8680
$this->mockAttributeRulesArray(['date_range_min' => '1980-01-01', 'date_range_max' => '2000-12-31']);
8781

8882
$called = false;
89-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
90-
$called = true;
91-
return $c;
92-
};
83+
$proceed = $this->proceedPlugin($called, $customer);
9384

9485
$this->expectException(InputException::class);
9586
$this->expectExceptionMessage('on or before 2000-12-31');
@@ -122,10 +113,7 @@ public function testEmptyDobSkipsValidationAndProceeds(): void
122113
$this->mockAttributeRulesArray(['date_range_min' => '1980-01-01', 'date_range_max' => '2000-12-31']);
123114

124115
$called = false;
125-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
126-
$called = true;
127-
return $c;
128-
};
116+
$proceed = $this->proceedPlugin($called, $customer);
129117

130118
$actual = $this->plugin->aroundSave($this->repo, $proceed, $customer, null);
131119

@@ -144,10 +132,7 @@ public function testRulesAsJsonStringAreUnserialized(): void
144132
$this->json->expects($this->once())->method('unserialize')->with($json)->willReturn($rules);
145133

146134
$called = false;
147-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
148-
$called = true;
149-
return $c;
150-
};
135+
$proceed = $this->proceedPlugin($called, $customer);
151136

152137
$this->expectException(InputException::class);
153138
$this->expectExceptionMessage('on or after 1980-01-01');
@@ -165,10 +150,7 @@ public function testMillisecondRulesBeforeMinThrows(): void
165150
$this->mockAttributeRulesArray(['date_range_min' => $minMs, 'date_range_max' => $maxMs]);
166151

167152
$called = false;
168-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
169-
$called = true;
170-
return $c;
171-
};
153+
$proceed = $this->proceedPlugin($called, $customer);
172154

173155
$this->expectException(InputException::class);
174156
$this->expectExceptionMessage('on or after 1980-01-01');
@@ -184,10 +166,7 @@ public function testDobAsMillisecondTimestampThrowsAgainstStringRule(): void
184166
$this->mockAttributeRulesArray(['date_range_min' => '1980-01-01', 'date_range_max' => '2000-12-31']);
185167

186168
$called = false;
187-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
188-
$called = true;
189-
return $c;
190-
};
169+
$proceed = $this->proceedPlugin($called, $customer);
191170

192171
$this->expectException(InputException::class);
193172
$this->expectExceptionMessage('on or after 1980-01-01');
@@ -274,10 +253,7 @@ public function testFallbackToGetValidateRulesArrayIsUsed(): void
274253
]);
275254

276255
$called = false;
277-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
278-
$called = true;
279-
return $c;
280-
};
256+
$proceed = $this->proceedPlugin($called, $customer);
281257

282258
$this->expectException(InputException::class);
283259
$this->expectExceptionMessage('on or after 1980-01-01');
@@ -324,10 +300,7 @@ public function testDobZeroEpochInvalidThrows(): void
324300
]);
325301

326302
$called = false;
327-
$proceed = function (CustomerInterface $c, $hash = null) use (&$called) {
328-
$called = true;
329-
return $c;
330-
};
303+
$proceed = $this->proceedPlugin($called, $customer);
331304

332305
$this->expectException(InputException::class);
333306
$this->expectExceptionMessage('Date of Birth is invalid.');
@@ -336,6 +309,22 @@ public function testDobZeroEpochInvalidThrows(): void
336309
$this->assertFalse($called);
337310
}
338311

312+
/**
313+
* Create a proceed closure that marks $called and returns either the given $result or the original $customer.
314+
*
315+
* @param bool $called Will be set to true when proceed is invoked
316+
* @param CustomerInterface|null $result Optional value to return instead of $customer
317+
* @return callable
318+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
319+
*/
320+
private function proceedPlugin(bool &$called, ?CustomerInterface $result = null): callable
321+
{
322+
return function (CustomerInterface $c, $hash = null) use (&$called) {
323+
$called = true;
324+
return $c;
325+
};
326+
}
327+
339328
/**
340329
* Create a customer mock with a specific DOB value.
341330
*

0 commit comments

Comments
 (0)