Skip to content

Commit efb74a1

Browse files
committed
ACP2E-3486: Default values are not set for date and time attributes with products RestAPI
1 parent 100e315 commit efb74a1

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\Backend;
9+
10+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
11+
use Magento\Eav\Model\Entity\Attribute\Backend\Datetime;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
14+
use Magento\Framework\DataObject;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class DatetimeTest extends TestCase
19+
{
20+
/**
21+
* @var TimezoneInterface|MockObject
22+
*/
23+
private $timezone;
24+
25+
/**
26+
* @var AbstractAttribute|MockObject
27+
*/
28+
private $attribute;
29+
30+
/**
31+
* @var Datetime
32+
*/
33+
private $model;
34+
35+
protected function setUp(): void
36+
{
37+
$this->attribute = $this->getMockBuilder(AbstractAttribute::class)
38+
->disableOriginalConstructor()
39+
->getMock();
40+
$this->timezone = $this->createMock(TimezoneInterface::class);
41+
$this->model = new Datetime($this->timezone);
42+
$this->model->setAttribute($this->attribute);
43+
}
44+
45+
/**
46+
* @throws LocalizedException
47+
*/
48+
public function testGetDefaultValue()
49+
{
50+
$attributeName = 'attribute';
51+
$defaultValue = '2024-01-01 00:00:00';
52+
$this->attribute->expects($this->once())->method('getName')->willReturn($attributeName);
53+
$this->attribute->expects($this->exactly(2))->method('getDefaultValue')->willReturn($defaultValue);
54+
$object = new DataObject();
55+
$this->model->beforeSave($object);
56+
$this->assertEquals($defaultValue, $object->getData($attributeName));
57+
}
58+
}

0 commit comments

Comments
 (0)