12
12
use Magento \Framework \ObjectManagerInterface ;
13
13
use Magento \Framework \Stdlib \DateTime \DateTime ;
14
14
use Magento \TestFramework \Helper \Bootstrap ;
15
- use Magento \Store \Model \ StoreManagerInterface ;
15
+ use Magento \TestFramework \ Store \ExecuteInStoreContext ;
16
16
use PHPUnit \Framework \TestCase ;
17
17
18
18
/**
19
19
* Checks Datetime attribute's frontend model
20
20
*
21
+ * @magentoAppArea frontend
22
+ *
21
23
* @see \Magento\Eav\Model\Entity\Attribute\Frontend\Datetime
22
24
*/
23
25
class DatetimeTest extends TestCase
@@ -43,25 +45,28 @@ class DatetimeTest extends TestCase
43
45
private $ productRepository ;
44
46
45
47
/**
46
- * @var StoreManagerInterface
48
+ * @var DateTime
47
49
*/
48
- private $ storeManager ;
50
+ private $ dateTime ;
49
51
50
52
/**
51
- * @var DateTime
53
+ * @var ExecuteInStoreContext
52
54
*/
53
- private $ dateTime ;
55
+ private $ executeInStoreContext ;
54
56
57
+ /**
58
+ * @inheritdoc
59
+ */
55
60
protected function setUp (): void
56
61
{
57
62
parent ::setUp ();
58
63
59
64
$ this ->objectManager = Bootstrap::getObjectManager ();
60
- $ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
61
65
$ this ->attributeRepository = $ this ->objectManager ->get (ProductAttributeRepositoryInterface::class);
62
66
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
63
67
$ this ->productRepository ->cleanCache ();
64
68
$ this ->dateTime = $ this ->objectManager ->create (DateTime::class);
69
+ $ this ->executeInStoreContext = $ this ->objectManager ->get (ExecuteInStoreContext::class);
65
70
}
66
71
67
72
/**
@@ -80,14 +85,16 @@ public function testFrontendValueOnDifferentWebsites(): void
80
85
$ attribute = $ this ->attributeRepository ->get ('datetime_attribute ' );
81
86
$ product = $ this ->productRepository ->get ('simple-on-two-websites ' );
82
87
$ 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
+ );
87
94
$ this ->assertEquals (
88
95
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 '
91
98
);
92
99
}
93
100
}
0 commit comments