6
6
namespace Magento \Ui \Test \Unit \Component \Form \Element \DataType ;
7
7
8
8
use Magento \Ui \Component \Form \Element \DataType \Date ;
9
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
10
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
11
+ use Magento \Framework \View \Element \UiComponent \Context ;
12
+ use Magento \Framework \Locale \ResolverInterface ;
13
+ use Magento \Framework \View \Element \UiComponent \Processor ;
9
14
10
15
class DateTest extends \PHPUnit_Framework_TestCase
11
16
{
12
- /**
13
- * @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject
14
- */
15
- private $ context ;
17
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
18
+ private $ contextMock ;
16
19
17
- /**
18
- * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
19
- */
20
- private $ localeDate ;
20
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
21
+ private $ localeDateMock ;
21
22
22
- /**
23
- * @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
24
- */
25
- private $ localeResolver ;
23
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
24
+ private $ localeResolverMock ;
26
25
27
- /**
28
- * @var Date
29
- */
30
- private $ model ;
31
-
32
- public function setUp ()
33
- {
34
- $ processorMock = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponent \Processor::class)
35
- ->disableOriginalConstructor ()
36
- ->getMock ();
26
+ /** @var \Magento\Ui\Component\Form\Element\DataType\Date */
27
+ private $ date ;
37
28
38
- $ this ->context = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponent \ContextInterface::class)
39
- ->getMockForAbstractClass ();
40
- $ this ->context ->expects ($ this ->any ())
41
- ->method ('getProcessor ' )
42
- ->willReturn ($ processorMock );
29
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
30
+ private $ processorMock ;
43
31
44
- $ this -> localeDate = $ this -> getMockBuilder ( \Magento \Framework \Stdlib \ DateTime \TimezoneInterface::class)
45
- -> getMockForAbstractClass () ;
32
+ /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
33
+ private $ objectManagerHelper ;
46
34
47
- $ this ->localeResolver = $ this ->getMockBuilder (\Magento \Framework \Locale \ResolverInterface::class)
48
- ->getMockForAbstractClass ();
35
+ public function setUp ()
36
+ {
37
+ $ this ->contextMock = $ this ->getMock (Context::class, [], [], '' , false );
38
+ $ this ->localeDateMock = $ this ->getMock (TimezoneInterface::class, [], [], '' , false );
39
+ $ this ->localeResolverMock = $ this ->getMock (ResolverInterface::class, [], [], '' , false );
40
+ $ this ->objectManagerHelper = new ObjectManager ($ this );
41
+ $ this ->processorMock = $ this ->getMock (Processor::class, [], [], '' , false );
42
+ $ this ->contextMock ->expects ($ this ->any ())->method ('getProcessor ' )->willReturn ($ this ->processorMock );
49
43
}
50
44
51
45
public function testPrepareWithTimeOffset ()
52
46
{
53
- $ this ->model = new Date (
54
- $ this ->context ,
55
- $ this ->localeDate ,
56
- $ this ->localeResolver ,
47
+ $ this ->date = new Date (
48
+ $ this ->contextMock ,
49
+ $ this ->localeDateMock ,
50
+ $ this ->localeResolverMock ,
57
51
[],
58
52
[
59
53
'config ' => [
@@ -64,13 +58,13 @@ public function testPrepareWithTimeOffset()
64
58
65
59
$ localeDateFormat = 'dd/MM/y ' ;
66
60
67
- $ this ->localeDate ->expects ($ this ->once ())
61
+ $ this ->localeDateMock ->expects ($ this ->once ())
68
62
->method ('getDateFormat ' )
69
63
->willReturn ($ localeDateFormat );
70
64
71
- $ this ->model ->prepare ();
65
+ $ this ->date ->prepare ();
72
66
73
- $ config = $ this ->model ->getConfig ();
67
+ $ config = $ this ->date ->getConfig ();
74
68
$ this ->assertTrue (is_array ($ config ));
75
69
76
70
$ this ->assertArrayHasKey ('options ' , $ config );
@@ -85,10 +79,10 @@ public function testPrepareWithoutTimeOffset()
85
79
{
86
80
$ defaultDateFormat = 'MM/dd/y ' ;
87
81
88
- $ this ->model = new Date (
89
- $ this ->context ,
90
- $ this ->localeDate ,
91
- $ this ->localeResolver ,
82
+ $ this ->date = new Date (
83
+ $ this ->contextMock ,
84
+ $ this ->localeDateMock ,
85
+ $ this ->localeResolverMock ,
92
86
[],
93
87
[
94
88
'config ' => [
@@ -102,25 +96,42 @@ public function testPrepareWithoutTimeOffset()
102
96
103
97
$ localeDateFormat = 'dd/MM/y ' ;
104
98
105
- $ this ->localeDate ->expects ($ this ->once ())
99
+ $ this ->localeDateMock ->expects ($ this ->once ())
106
100
->method ('getDateFormat ' )
107
101
->willReturn ($ localeDateFormat );
108
- $ this ->localeDate ->expects ($ this ->once ())
102
+ $ this ->localeDateMock ->expects ($ this ->any ())
109
103
->method ('getConfigTimezone ' )
110
104
->willReturn ('America/Los_Angeles ' );
111
105
112
- $ this ->model ->prepare ();
106
+ $ this ->date ->prepare ();
113
107
114
- $ config = $ this ->model ->getConfig ();
108
+ $ config = $ this ->date ->getConfig ();
115
109
$ this ->assertTrue (is_array ($ config ));
116
110
117
- $ this ->assertArrayHasKey ('timeOffset ' , $ config );
118
-
119
111
$ this ->assertArrayHasKey ('options ' , $ config );
120
112
$ this ->assertArrayHasKey ('dateFormat ' , $ config ['options ' ]);
121
113
$ this ->assertEquals ($ localeDateFormat , $ config ['options ' ]['dateFormat ' ]);
122
114
123
115
$ this ->assertArrayHasKey ('outputDateFormat ' , $ config );
124
116
$ this ->assertEquals ($ localeDateFormat , $ config ['outputDateFormat ' ]);
125
117
}
118
+
119
+ /**
120
+ * This tests ensures that userTimeZone is properly saved in the configuration
121
+ */
122
+ public function testPrepare ()
123
+ {
124
+ $ this ->date = $ this ->objectManagerHelper ->getObject (
125
+ Date::class,
126
+ [
127
+ 'context ' => $ this ->contextMock ,
128
+ 'localeDate ' => $ this ->localeDateMock ,
129
+ 'localeResolver ' => $ this ->localeResolverMock
130
+ ]
131
+ );
132
+ $ this ->localeDateMock ->expects ($ this ->any ())->method ('getConfigTimezone ' )->willReturn ('America/Chicago ' );
133
+ $ this ->date ->prepare ();
134
+ $ configArray = $ this ->date ->getData ('config ' );
135
+ $ this ->assertEquals ('America/Chicago ' , $ configArray ['storeTimeZone ' ]);
136
+ }
126
137
}
0 commit comments