@@ -22,102 +22,114 @@ public function contextProvider() {
22
22
'2020-05-30 02:00 UTC ' , // "now" time
23
23
[ 'enabled ' => false ], // value for Announcement in app_config.php
24
24
false , // should be displayed or not
25
- null , // shutdown warning message
25
+ null , // maintenance message
26
26
],
27
27
'announcement enabled ' => [
28
28
'2020-05-30 02:00 UTC ' ,
29
29
[ 'enabled ' => true ],
30
30
true ,
31
- null
31
+ null , // no maintenance message since no maintenance is scheduled
32
32
],
33
- 'announcement disabled, hide in 1 minute ' => [
33
+ 'announcement enabled, 10 minutes 59 seconds to go, with warning ' => [
34
+ '2020-05-30 01:49:01 UTC ' ,
35
+ [ 'enabled ' => true , 'maintenance ' => ['start ' => '2020-05-30 02:00 UTC ' ] ],
36
+ true ,
37
+ 'Tatoeba will temporarily shut down for maintenance in 10 minutes. ' ,
38
+ ],
39
+ 'announcement enabled, 1 minute to go, with warning ' => [
34
40
'2020-05-30 01:59 UTC ' ,
35
- [ 'enabled ' => false , 'hideAfter ' => '2020-05-30 02:00 UTC ' ],
41
+ [ 'enabled ' => true , 'maintenance ' => ['start ' => '2020-05-30 02:00 UTC ' ] ],
42
+ true ,
43
+ 'Tatoeba will temporarily shut down for maintenance in 1 minute. ' ,
44
+ ],
45
+ 'announcement disabled, maintenance scheduled ' => [
46
+ '2020-05-30 01:50 UTC ' ,
47
+ [ 'enabled ' => false , 'maintenance ' => ['start ' => '2020-05-30 02:00 UTC ' ] ],
36
48
false ,
37
49
null ,
38
50
],
39
- 'announcement enabled, 11 minutes to go, without warning ' => [
40
- '2020-05-30 01:49:00 UTC ' ,
41
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' ],
51
+ 'announcement enabled, maintenance scheduled but no warning ' => [
52
+ '2020-05-30 01:50 UTC ' ,
53
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '], ' shutdownWarning ' => false ],
42
54
true ,
43
55
null ,
44
56
],
45
- 'announcement enabled, 11 minutes to go, with warning ' => [
46
- '2020-05-30 01:49:00 UTC ' ,
47
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' , 'shutdownWarning ' => true ],
57
+ 'announcement enabled, maintenance starts in 5 seconds ' => [
58
+ '2020-05-30 01:59:55 UTC ' ,
59
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '] , 'shutdownWarning ' => true ],
48
60
true ,
49
- null ,
61
+ ' in 5 seconds ' ,
50
62
],
51
- 'announcement enabled, 10 minutes 59 seconds to go, with warning ' => [
52
- '2020-05-30 01:49:01 UTC ' ,
53
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' , 'shutdownWarning ' => true ],
63
+ 'announcement enabled, maintenance starts in 1 hour ' => [
64
+ '2020-05-30 01:00 UTC ' ,
65
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '] , 'shutdownWarning ' => true ],
54
66
true ,
55
- 'in 10 minutes ' ,
67
+ 'in 1 hour ' ,
56
68
],
57
- 'announcement enabled, 10 minutes to go, with warning ' => [
58
- '2020-05-30 01:50 UTC ' ,
59
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' , 'shutdownWarning ' => true ],
69
+ 'announcement enabled, maintenance starts in 2 hours ' => [
70
+ '2020-05-30 00:00 UTC ' ,
71
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '] , 'shutdownWarning ' => true ],
60
72
true ,
61
- 'in 10 minutes ' ,
73
+ 'in 2 hours ' ,
62
74
],
63
- 'announcement enabled, 1 minute to go, with warning ' => [
64
- '2020-05-30 01:59 UTC ' ,
65
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' , 'shutdownWarning ' => true ],
75
+ 'announcement enabled, maintenance starts tomorrow ' => [
76
+ '2020-05-29 23:00 UTC ' ,
77
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '] , 'shutdownWarning ' => true ],
66
78
true ,
67
- 'in 1 minute ' ,
79
+ 'in 1 day ' ,
68
80
],
69
- 'announcement enabled, 59 seconds to go, with warning ' => [
70
- '2020-05-30 01:59:01 UTC ' ,
71
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' , 'shutdownWarning ' => true ],
81
+ 'announcement enabled, maintenance starts in 3 days ' => [
82
+ '2020-05-27 02:00 UTC ' ,
83
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '] , 'shutdownWarning ' => true ],
72
84
true ,
73
- 'in 59 seconds ' ,
85
+ 'in 3 days ' ,
74
86
],
75
- 'announcement enabled, 1 second to go, with warning ' => [
76
- '2020-05-30 01:59:59 UTC ' ,
77
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' , 'shutdownWarning ' => true ],
87
+ 'announcement enabled, maintenance starts in 1 week ' => [
88
+ '2020-05-23 02:00 UTC ' ,
89
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '] , 'shutdownWarning ' => true ],
78
90
true ,
79
- 'in 1 second ' ,
91
+ 'in 1 week ' ,
80
92
],
81
- 'announcement enabled, hide exactly now, without warning ' => [
82
- '2020-05-30 02:00 UTC ' ,
83
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' ],
93
+ 'announcement enabled, maintenance starts in the past ' => [
94
+ '2020-05-30 02:01 UTC ' ,
95
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '], ' shutdownWarning ' => true ],
84
96
false ,
85
97
null ,
86
98
],
87
- 'announcement enabled, hide exactly now, with warning ' => [
99
+ 'announcement enabled, maintenance starts far in the future ' => [
88
100
'2020-05-30 02:00 UTC ' ,
89
- [ 'enabled ' => true , 'hideAfter ' => ' 2020 -05-30 02:00 UTC ' ],
90
- false ,
91
- null ,
101
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2030 -05-30 02:00 UTC '], ' shutdownWarning ' => true ],
102
+ true ,
103
+ ' in 10 years ' ,
92
104
],
93
- 'announcement enabled, hide 1 second ago ' => [
94
- '2020-05-30 02:00:01 UTC ' ,
95
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' ],
96
- false ,
105
+ 'announcement enabled, maintenance starts but shutdownWarning disabled ' => [
106
+ '2020-05-30 01:50 UTC ' ,
107
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' 2020-05-30 02:00 UTC '], ' shutdownWarning ' => false ],
108
+ true ,
97
109
null ,
98
110
],
99
- 'announcement enabled, hide 1 minute ago ' => [
100
- '2020-05-30 02:01 UTC ' ,
101
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' ],
102
- false ,
111
+ 'announcement enabled, invalid maintenance start time ' => [
112
+ '2020-05-30 01:50 UTC ' ,
113
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => ' invalid-time ' ], ' shutdownWarning ' => true ],
114
+ true ,
103
115
null ,
104
116
],
105
- 'announcement enabled, hide 10 years ago ' => [
106
- '2030 -05-30 02:00 UTC ' ,
107
- [ 'enabled ' => true , 'hideAfter ' => ' 2020-05-30 02:00 UTC ' ],
108
- false ,
117
+ 'announcement enabled, maintenance start time empty ' => [
118
+ '2020 -05-30 01:50 UTC ' ,
119
+ [ 'enabled ' => true , 'maintenance ' => [ ' start ' => '' ], ' shutdownWarning ' => true ],
120
+ true ,
109
121
null ,
110
122
],
111
- 'announcement enabled, hideAfter empty ' => [
112
- '2020-05-30 02:00 UTC ' ,
113
- [ 'enabled ' => true , ' hideAfter ' => '' ],
123
+ 'announcement enabled, no maintenance configuration ' => [
124
+ '2020-05-30 01:50 UTC ' ,
125
+ [ 'enabled ' => true ],
114
126
true ,
115
127
null ,
116
128
],
117
- 'announcement enabled, hideAfter invalid ' => [
118
- '2020-05-30 02:00 UTC ' ,
119
- [ 'enabled ' => true , ' hideAfter ' => ' foobar ' ],
120
- true ,
129
+ 'announcement disabled, no maintenance configuration ' => [
130
+ '2020-05-30 01:50 UTC ' ,
131
+ [ 'enabled ' => false ],
132
+ false ,
121
133
null ,
122
134
],
123
135
];
@@ -130,14 +142,18 @@ public function testEverything($now, $config, $shouldShow, $warning)
130
142
{
131
143
Time::setTestNow (new Time ($ now ));
132
144
$ helper = $ this ->createHelperWithConfig ($ config );
133
-
145
+
134
146
$ this ->assertEquals ($ shouldShow , $ helper ->isDisplayed ());
147
+ $ maintenanceMessage = $ helper ->getMaintenanceMessage ();
148
+
135
149
if (is_null ($ warning )) {
136
- $ this ->assertNull ($ helper ->shutdownWarning ());
150
+ $ this ->assertEmpty ($ maintenanceMessage );
151
+ } elseif (is_string ($ maintenanceMessage )) {
152
+ $ this ->assertContains ($ warning , $ maintenanceMessage );
137
153
} else {
138
- $ this ->assertContains ( $ warning , $ helper -> shutdownWarning ( ));
154
+ $ this ->fail ( ' getMaintenanceMessage returned an unexpected value: ' . var_export ( $ maintenanceMessage , true ));
139
155
}
140
-
156
+
141
157
Time::setTestNow ();
142
158
}
143
159
}
0 commit comments