-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatetimeTest.php
More file actions
270 lines (248 loc) · 8.42 KB
/
DatetimeTest.php
File metadata and controls
270 lines (248 loc) · 8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/**
* RegistrationAnswerHelper::singleChoice()のテスト
*
* @property RegistrationAnswerHelper $RegistrationAnswerHelper
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Allcreator <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('View', 'View');
App::uses('NetCommonsCakeTestCase', 'NetCommons.TestSuite');
App::uses('RegistrationAnswerHelper', 'Registrations.View/Helper');
App::uses('NetCommonsHtmlHelper', 'NetCommons.View/Helper');
App::uses('RegistrationsComponent', 'Registrations.Controller/Component');
/**
* Summary for RegistrationAnswerHelper Test Case
*/
class RegistrationAnswerHelperDatetimeTest extends NetCommonsCakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$View = new View();
$this->RegistrationAnswer = new RegistrationAnswerHelper($View);
$this->NetCommonsHtml = new NetCommonsHtmlHelper($View);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->RegistrationAnswer);
parent::tearDown();
}
/**
* _getComElement method
*
* @return string
*/
protected function _getComElement() {
$ret = <<< EOT
<div class="has-error">
</div>
<input type="hidden" name="data[RegistrationAnswer][qKey1][0][registration_answer_summary_id]" id="RegistrationAnswerQKey10RegistrationAnswerSummaryId"/>
<input type="hidden" name="data[RegistrationAnswer][qKey1][0][registration_question_key]" value="qKey1" id="RegistrationAnswerQKey10RegistrationQuestionKey"/>
<input type="hidden" name="data[RegistrationAnswer][qKey1][0][id]" id="RegistrationAnswerQKey10Id"/>
<input type="hidden" name="data[RegistrationAnswer][qKey1][0][matrix_choice_key]" id="RegistrationAnswerQKey10MatrixChoiceKey"/>
EOT;
return $ret;
}
/**
* _getDatetimeBaseElement method
*
* @return string
*/
protected function _getDatetimeBaseElement() {
$ret = <<< EOT
<div class="row">
<div class="col-sm-4">
<div class="date">
<divclass="inputtext"style="position:relative;position:relative;">
<input name="data[RegistrationAnswer][qKey1][0][answer_value]" class="form-control"
datetimepicker="1" datetimepicker-options="%s"
ng-model="dateAnswer['qKey1']"
data-toggle="dropdown"
type="text" id="RegistrationAnswerQKey10AnswerValue"/>
</div>
</div>
</div>
</div>
<span class="help-block">%s</span>
EOT;
return $ret;
}
/**
* Test RegistrationAnswer->dateTimeInput()
*
* @return void
*/
public function testDateTimeInputDate() {
$question = array(
'key' => 'qKey1',
'question_type' => RegistrationsComponent::TYPE_DATE_AND_TIME,
'is_range' => 0,
'question_type_option' => RegistrationsComponent::TYPE_OPTION_DATE,
);
$datetimePickerOpt = htmlspecialchars(json_encode(array(
'format' => 'YYYY-MM-DD'
)));
$help = '';
$expected = preg_replace('/[\n|\r|\t|\s]/', '', sprintf($this->_getDatetimeBaseElement(), $datetimePickerOpt, $help) . $this->_getComElement());
$actual = $this->RegistrationAnswer->answer($question);
$actual = preg_replace('/[\n|\r|\t|\s]/', '', $actual);
$this->assertTextEquals($expected, $actual);
}
/**
* Test RegistrationAnswer->dateTimeInput()
*
* @return void
*/
public function testDateTimeInputDateRage() {
$question = array(
'key' => 'qKey1',
'question_type' => RegistrationsComponent::TYPE_DATE_AND_TIME,
'is_range' => 1,
'question_type_option' => RegistrationsComponent::TYPE_OPTION_DATE,
'min' => '2014-08-01',
'max' => '2016-08-01',
);
$datetimePickerOpt = htmlspecialchars(
json_encode(array(
'format' => 'YYYY-MM-DD',
'minDate' => '2014-08-01',
'maxDate' => '2016-08-01',
)
)
);
$help = sprintf(__d('registrations', 'Please enter at %s to %s'), date('Y-m-d', strtotime($question['min'])), date('Y-m-d', strtotime($question['max'])));
$expected = preg_replace('/[\n|\r|\t|\s]/', '', sprintf($this->_getDatetimeBaseElement(), $datetimePickerOpt, $help) . $this->_getComElement());
$actual = $this->RegistrationAnswer->answer($question);
$actual = preg_replace('/[\n|\r|\t|\s]/', '', $actual);
$this->assertTextEquals($expected, $actual);
}
/**
* Test RegistrationAnswer->dateTimeInput()
*
* @return void
*/
public function testDateTimeInputTime() {
$question = array(
'key' => 'qKey1',
'question_type' => RegistrationsComponent::TYPE_DATE_AND_TIME,
'is_range' => 0,
'question_type_option' => RegistrationsComponent::TYPE_OPTION_TIME,
);
$datetimePickerOpt = htmlspecialchars(json_encode(array(
'format' => 'HH:mm'
)));
$help = '';
$expected = sprintf($this->_getDatetimeBaseElement(), $datetimePickerOpt, $help);
$expected = str_replace('calendar', 'time', $expected);
$expected = preg_replace('/[\n|\r|\t|\s]/', '', $expected . $this->_getComElement());
$actual = $this->RegistrationAnswer->answer($question);
$actual = preg_replace('/[\n|\r|\t|\s]/', '', $actual);
$this->assertTextEquals($expected, $actual);
}
/**
* Test RegistrationAnswer->dateTimeInput()
*
* @return void
*/
public function testDateTimeInputTimeRange() {
$question = array(
'key' => 'qKey1',
'question_type' => RegistrationsComponent::TYPE_DATE_AND_TIME,
'is_range' => 1,
'question_type_option' => RegistrationsComponent::TYPE_OPTION_TIME,
'min' => '00:00',
'max' => '15:15',
);
$today = date('Y-m-d');
$datetimePickerOpt = htmlspecialchars(json_encode(array(
'format' => 'HH:mm',
'minDate' => $today . ' 00:00',
'maxDate' => $today . ' 15:15',
)));
$help = sprintf(__d('registrations', 'Please enter at %s to %s'), date('H:i', strtotime($question['min'])), date('H:i', strtotime($question['max'])));
$expected = sprintf($this->_getDatetimeBaseElement(), $datetimePickerOpt, $help);
$expected = str_replace('calendar', 'time', $expected);
$expected = preg_replace('/[\n|\r|\t|\s]/', '', $expected . $this->_getComElement());
$actual = $this->RegistrationAnswer->answer($question);
$actual = preg_replace('/[\n|\r|\t|\s]/', '', $actual);
$this->assertTextEquals($expected, $actual);
}
/**
* Test RegistrationAnswer->dateTimeInput()
*
* @return void
*/
public function testDateTimeInputDatetime() {
$question = array(
'key' => 'qKey1',
'question_type' => RegistrationsComponent::TYPE_DATE_AND_TIME,
'is_range' => 0,
'question_type_option' => RegistrationsComponent::TYPE_OPTION_DATE_TIME,
);
$datetimePickerOpt = htmlspecialchars(json_encode(array(
'format' => 'YYYY-MM-DD HH:mm'
)));
$help = '';
$expected = preg_replace('/[\n|\r|\t|\s]/', '', sprintf($this->_getDatetimeBaseElement(), $datetimePickerOpt, $help) . $this->_getComElement());
$actual = $this->RegistrationAnswer->answer($question);
$actual = preg_replace('/[\n|\r|\t|\s]/', '', $actual);
$this->assertTextEquals($expected, $actual);
}
/**
* Test RegistrationAnswer->dateTimeInput()
*
* @return void
*/
public function testDateTimeInputDatetimeRange() {
$question = array(
'key' => 'qKey1',
'question_type' => RegistrationsComponent::TYPE_DATE_AND_TIME,
'is_range' => 1,
'question_type_option' => RegistrationsComponent::TYPE_OPTION_DATE_TIME,
'min' => '2014-08-01 00:00',
'max' => '2016-08-01 15:00',
);
$datetimePickerOpt = htmlspecialchars(
json_encode(array(
'format' => 'YYYY-MM-DD HH:mm',
'minDate' => '2014-08-01 00:00',
'maxDate' => '2016-08-01 15:00',
)
)
);
$help = sprintf(__d('registrations', 'Please enter at %s to %s'), date('Y-m-d H:i', strtotime($question['min'])), date('Y-m-d H:i', strtotime($question['max'])));
$expected = preg_replace('/[\n|\r|\t|\s]/', '', sprintf($this->_getDatetimeBaseElement(), $datetimePickerOpt, $help) . $this->_getComElement());
$actual = $this->RegistrationAnswer->answer($question);
$actual = preg_replace('/[\n|\r|\t|\s]/', '', $actual);
$this->assertTextEquals($expected, $actual);
}
/**
* Test RegistrationAnswer->dateTimeInput()
*
* @return void
*/
public function testDateTimeInputDatetimeReadonly() {
$question = array(
'key' => 'qKey1',
'question_type' => RegistrationsComponent::TYPE_DATE_AND_TIME,
'is_range' => 0,
'question_type_option' => RegistrationsComponent::TYPE_OPTION_DATE_TIME,
);
$expected = preg_replace('/[\n|\r|\t|\s]/', '', $this->_getComElement());
$actual = $this->RegistrationAnswer->answer($question, true);
$actual = preg_replace('/[\n|\r|\t|\s]/', '', $actual);
$this->assertTextEquals($expected, $actual);
}
}