Skip to content

Commit d0dea2d

Browse files
committed
37919: Added More Test Cases for Validation & and updated the Copyright Years
1 parent 53899c1 commit d0dea2d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

app/code/Magento/Rule/Model/Condition/AbstractCondition.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2015 Adobe
3+
* Copyright 2011 Adobe
44
* All Rights Reserved.
55
*/
66
namespace Magento\Rule\Model\Condition;
@@ -865,6 +865,11 @@ public function validateAttribute($validatedValue)
865865
}
866866
}
867867
break;
868+
case '===':
869+
if (!is_array($validatedValue) && !is_array($value)) {
870+
$result = $this->_compareValues($validatedValue, $value);
871+
}
872+
break;
868873
}
869874

870875
if ('!=' == $option || '>' == $option || '<' == $option || '!{}' == $option || '!()' == $option) {
@@ -885,7 +890,8 @@ public function validateAttribute($validatedValue)
885890
protected function _compareValues($validatedValue, $value, $strict = true)
886891
{
887892
if ($strict && is_numeric($validatedValue) && is_numeric($value)) {
888-
if (preg_match('/^0\d+$/', $validatedValue) || preg_match('/^0\d+$/', $value)) {
893+
$pattern = '/^0\d+$/';
894+
if (preg_match($pattern, $validatedValue) || preg_match($pattern, $value)) {
889895
return $validatedValue === $value;
890896
}
891897
return $validatedValue == $value;

app/code/Magento/Rule/Test/Unit/Model/Condition/AbstractConditionTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2015 Adobe
3+
* Copyright 2013 Adobe
44
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
@@ -65,8 +65,17 @@ public static function validateAttributeDataProvider()
6565
[null, '==', 0, false],
6666
[null, '==', 0.00, false],
6767

68+
// Test cases for strict equality with leading zeros
6869
['0123', '===', '123', false],
70+
['000123', '===', '123', false],
6971
['123', '===', '0123', false],
72+
['123', '===', '000123', false],
73+
['0123', '===', '0123', true],
74+
75+
// Test cases for strict equality with different numeric types
76+
[0123, '===', '0123', false],
77+
['123', '===', 0123, false],
78+
[0123, '===', 0123, true],
7079

7180
[1, '!=', 1, false],
7281
[0, '!=', 1, true],

0 commit comments

Comments
 (0)