Skip to content

Commit a3a5a2d

Browse files
author
Alex Akimov
committed
MAGETWO-43717: Attribute Group Code Generation Algorithm is Incorrect
1 parent bbd0dc6 commit a3a5a2d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public function beforeSave()
6666
if (!$this->getAttributeGroupCode()) {
6767
$groupName = $this->getAttributeGroupName();
6868
if ($groupName) {
69-
$this->setAttributeGroupCode(trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($groupName)), '-'));
69+
// in the following code md5 is not used for security purposes
70+
$this->setAttributeGroupCode(md5($groupName));
7071
}
7172
}
7273
return parent::beforeSave();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Eav\Test\Unit\Model\Entity\Attribute;
7+
8+
use Magento\Eav\Model\Entity\Attribute\Group;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
class GroupTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var Group
15+
*/
16+
private $model;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $resourceMock;
22+
23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $eventManagerMock;
27+
28+
protected function setUp()
29+
{
30+
$this->resourceMock = $this->getMock('Magento\Eav\Model\Resource\Entity\Attribute\Group', [], [], '', false);
31+
$this->eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
32+
$contextMock = $this->getMock('Magento\Framework\Model\Context', [], [], '', false);
33+
$contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManagerMock);
34+
$constructorArguments = [
35+
'resource' => $this->resourceMock,
36+
'context' => $contextMock,
37+
];
38+
$objectManager = new ObjectManager($this);
39+
$this->model = $objectManager->getObject('Magento\Eav\Model\Entity\Attribute\Group', $constructorArguments);
40+
}
41+
42+
public function testBeforeSaveGeneratesGroupCodeBasedOnGroupName()
43+
{
44+
$groupName = 'General';
45+
$expectedGroupCode = md5($groupName);
46+
$this->model->setAttributeGroupName($groupName);
47+
$this->model->beforeSave();
48+
$this->assertEquals($expectedGroupCode, $this->model->getAttributeGroupCode());
49+
}
50+
}

0 commit comments

Comments
 (0)