|
| 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