Skip to content

Commit 3a384b9

Browse files
committed
MC-40865: Create automated test for: ""Date and Time" attribute correctly rendered regarding timezone settings"
1 parent 2e2af0a commit 3a384b9

File tree

1 file changed

+93
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Eav/Model/Entity/Attribute/Frontend

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Eav\Model\Entity\Attribute\Frontend;
9+
10+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Framework\Stdlib\DateTime\DateTime;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Checks Datetime attribute's frontend model
20+
*
21+
* @see \Magento\Eav\Model\Entity\Attribute\Frontend\Datetime
22+
*/
23+
class DatetimeTest extends TestCase
24+
{
25+
/**
26+
* @var int
27+
*/
28+
private const ONE_HOUR_IN_MILLISECONDS = 3600;
29+
30+
/**
31+
* @var ObjectManagerInterface
32+
*/
33+
private $objectManager;
34+
35+
/**
36+
* @var ProductAttributeRepositoryInterface
37+
*/
38+
private $attributeRepository;
39+
40+
/**
41+
* @var ProductRepositoryInterface
42+
*/
43+
private $productRepository;
44+
45+
/**
46+
* @var StoreManagerInterface
47+
*/
48+
private $storeManager;
49+
50+
/**
51+
* @var DateTime
52+
*/
53+
private $dateTime;
54+
55+
protected function setUp(): void
56+
{
57+
parent::setUp();
58+
59+
$this->objectManager = Bootstrap::getObjectManager();
60+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
61+
$this->attributeRepository = $this->objectManager->get(ProductAttributeRepositoryInterface::class);
62+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
63+
$this->productRepository->cleanCache();
64+
$this->dateTime = $this->objectManager->create(DateTime::class);
65+
}
66+
67+
/**
68+
* @magentoDbIsolation disabled
69+
*
70+
* @magentoDataFixture Magento/Catalog/_files/product_two_websites.php
71+
* @magentoDataFixture Magento/Catalog/_files/product_datetime_attribute.php
72+
*
73+
* @magentoConfigFixture default_store general/locale/timezone Europe/Moscow
74+
* @magentoConfigFixture fixture_second_store_store general/locale/timezone Europe/Kiev
75+
*
76+
* @return void
77+
*/
78+
public function testFrontendValueOnDifferentWebsites(): void
79+
{
80+
$attribute = $this->attributeRepository->get('datetime_attribute');
81+
$product = $this->productRepository->get('simple-on-two-websites');
82+
$product->setDatetimeAttribute($this->dateTime->date('Y-m-d H:i:s'));
83+
$valueOnWebsiteOne = $attribute->getFrontend()->getValue($product);
84+
$secondStoreId = $this->storeManager->getStore('fixture_second_store')->getId();
85+
$this->storeManager->setCurrentStore($secondStoreId);
86+
$valueOnWebsiteTwo = $attribute->getFrontend()->getValue($product);
87+
$this->assertEquals(
88+
self::ONE_HOUR_IN_MILLISECONDS,
89+
$this->dateTime->gmtTimestamp($valueOnWebsiteOne) - $this->dateTime->gmtTimestamp($valueOnWebsiteTwo),
90+
'The difference between the two time zones are incorrect'
91+
);
92+
}
93+
}

0 commit comments

Comments
 (0)