Skip to content

Commit f2dec07

Browse files
committed
Merge branch 'ACP2E-3453' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-VK-2024-11-27-CE
2 parents 2a28e71 + 17936fb commit f2dec07

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/UniqueValidator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Eav\Model\Entity\Attribute;
77

@@ -23,8 +23,9 @@ public function validate(
2323
$entityLinkField,
2424
array $entityIds
2525
) {
26-
if (isset($entityIds[0])) {
27-
return $entityIds[0] == $object->getData($entityLinkField);
26+
if ($entityIds) {
27+
// check for current and future updates
28+
return in_array($object->getData($entityLinkField), $entityIds);
2829
}
2930
return true;
3031
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Eav\Test\Unit\Model\Entity\Attribute;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Eav\Model\Entity\Attribute\UniqueValidator;
12+
use Magento\Framework\DataObject;
13+
use Magento\Eav\Model\Entity\AbstractEntity;
14+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
15+
16+
class UniqueValidatorTest extends TestCase
17+
{
18+
/**
19+
* @var UniqueValidator
20+
*/
21+
private $uniqueValidator;
22+
23+
protected function setUp(): void
24+
{
25+
$this->uniqueValidator = new UniqueValidator();
26+
}
27+
28+
public function testValidate()
29+
{
30+
$attribute = $this->createMock(AbstractAttribute::class);
31+
$object = $this->createMock(DataObject::class);
32+
$entity = $this->createMock(AbstractEntity::class);
33+
$entityLinkField = 'entityLinkField';
34+
$entityIds = [1, 2, 3];
35+
36+
$object->expects($this->once())
37+
->method('getData')
38+
->with($entityLinkField)
39+
->willReturn(2);
40+
41+
$this->assertTrue($this->uniqueValidator->validate($attribute, $object, $entity, $entityLinkField, $entityIds));
42+
}
43+
}

0 commit comments

Comments
 (0)