1212use Magento \Framework \ObjectManagerInterface ;
1313use Magento \Framework \Stdlib \DateTime \DateTime ;
1414use Magento \TestFramework \Helper \Bootstrap ;
15- use Magento \Store \Model \ StoreManagerInterface ;
15+ use Magento \TestFramework \ Store \ExecuteInStoreContext ;
1616use PHPUnit \Framework \TestCase ;
1717
1818/**
1919 * Checks Datetime attribute's frontend model
2020 *
21+ * @magentoAppArea frontend
22+ *
2123 * @see \Magento\Eav\Model\Entity\Attribute\Frontend\Datetime
2224 */
2325class DatetimeTest extends TestCase
@@ -43,25 +45,28 @@ class DatetimeTest extends TestCase
4345 private $ productRepository ;
4446
4547 /**
46- * @var StoreManagerInterface
48+ * @var DateTime
4749 */
48- private $ storeManager ;
50+ private $ dateTime ;
4951
5052 /**
51- * @var DateTime
53+ * @var ExecuteInStoreContext
5254 */
53- private $ dateTime ;
55+ private $ executeInStoreContext ;
5456
57+ /**
58+ * @inheritdoc
59+ */
5560 protected function setUp (): void
5661 {
5762 parent ::setUp ();
5863
5964 $ this ->objectManager = Bootstrap::getObjectManager ();
60- $ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
6165 $ this ->attributeRepository = $ this ->objectManager ->get (ProductAttributeRepositoryInterface::class);
6266 $ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
6367 $ this ->productRepository ->cleanCache ();
6468 $ this ->dateTime = $ this ->objectManager ->create (DateTime::class);
69+ $ this ->executeInStoreContext = $ this ->objectManager ->get (ExecuteInStoreContext::class);
6570 }
6671
6772 /**
@@ -80,14 +85,16 @@ public function testFrontendValueOnDifferentWebsites(): void
8085 $ attribute = $ this ->attributeRepository ->get ('datetime_attribute ' );
8186 $ product = $ this ->productRepository ->get ('simple-on-two-websites ' );
8287 $ 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 );
88+ $ firstWebsiteValue = $ attribute ->getFrontend ()->getValue ($ product );
89+ $ secondWebsiteValue = $ this ->executeInStoreContext ->execute (
90+ 'fixture_second_store ' ,
91+ [$ attribute ->getFrontend (), 'getValue ' ],
92+ $ product
93+ );
8794 $ this ->assertEquals (
8895 self ::ONE_HOUR_IN_MILLISECONDS ,
89- $ this ->dateTime ->gmtTimestamp ($ valueOnWebsiteOne ) - $ this ->dateTime ->gmtTimestamp ($ valueOnWebsiteTwo ),
90- 'The difference between the two time zones are incorrect '
96+ $ this ->dateTime ->gmtTimestamp ($ firstWebsiteValue ) - $ this ->dateTime ->gmtTimestamp ($ secondWebsiteValue ),
97+ 'The difference between values per different timezones is incorrect '
9198 );
9299 }
93100}
0 commit comments