-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEditTest.php
More file actions
505 lines (477 loc) · 18.5 KB
/
EditTest.php
File metadata and controls
505 lines (477 loc) · 18.5 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<?php
/**
* RegistrationEditController Test Case
*
* @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('WorkflowControllerEditTest', 'Workflow.TestSuite');
App::uses('RegistrationsComponent', 'Registrations.Controller/Component');
/**
* RegistrationEditController Test Case
*
* @author Allcreator <info@allcreator.net>
* @package NetCommons\Registrations\Test\Case\Controller\RegistrationEditController
*/
class RegistrationEditControllerEditTest extends WorkflowControllerEditTest {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.registrations.registration',
'plugin.registrations.block_setting_for_registration',
'plugin.registrations.registration_page',
'plugin.registrations.registration_question',
'plugin.registrations.registration_choice',
'plugin.registrations.registration_answer_summary',
'plugin.registrations.registration_answer',
'plugin.authorization_keys.authorization_keys',
'plugin.workflow.workflow_comment',
);
/**
* Plugin name
*
* @var array
*/
public $plugin = 'registrations';
/**
* Controller name
*
* @var string
*/
protected $_controller = 'registration_edit';
/**
* test Action name
*
* @var string
*/
protected $_myAction = 'edit';
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Registration = ClassRegistry::init('Registrations.Registration');
$this->Registration->Behaviors->unload('AuthorizationKey');
$this->controller->Session->expects($this->any())
->method('check')
->will($this->returnValueMap([['Registrations.registrationEdit.' . 'testSession', true]]));
$this->controller->Session->expects($this->any())
->method('read')
->will($this->returnValueMap([['Registrations.registrationEdit.' . 'testSession', $this->__getData()]]));
}
/**
* テストDataの取得
*
* @param string $registrationKey キー
* @return array
*/
private function __getData($registrationKey = null) {
$frameId = '6';
$blockId = '2';
$blockKey = 'block_1';
$data = array(
'save_' . WorkflowComponent::STATUS_IN_DRAFT => null,
'Frame' => array(
'id' => $frameId
),
'Block' => array(
'id' => $blockId,
'key' => $blockKey,
'language_id' => '2',
'room_id' => '2',
'plugin_key' => $this->plugin,
),
'Registration' => array(
'key' => $registrationKey,
'status' => WorkflowComponent::STATUS_IN_DRAFT,
'title' => 'EditTestTitle',
'sub_title' => 'EditTestSubTitle',
'is_total_show' => 0,
'answer_timing' => '0',
'answer_start_period' => '2016-08-01 00:00:00',
'answer_end_period' => '2017-08-01 00:00:00',
//'is_no_member_allow' => 0,
'is_key_pass_use' => 0,
'total_show_timing' => 0,
'total_show_start_period' => '',
),
'RegistrationPage' => array(
array(
'page_title' => __d('registrations', 'First Page'),
'page_sequence' => 0,
'route_number' => 0,
'RegistrationQuestion' => array(
array(
'question_sequence' => 0,
'question_value' => __d('registrations', 'New Question') . '1',
'question_type' => RegistrationsComponent::TYPE_SELECTION,
'is_require' => RegistrationsComponent::USES_NOT_USE,
'is_skip' => RegistrationsComponent::SKIP_FLAGS_NO_SKIP,
'is_choice_random' => RegistrationsComponent::USES_NOT_USE,
'is_range' => RegistrationsComponent::USES_NOT_USE,
'is_result_display' => RegistrationsComponent::EXPRESSION_SHOW,
'result_display_type' => RegistrationsComponent::RESULT_DISPLAY_TYPE_BAR_CHART,
'RegistrationChoice' => array(
array(
'choice_sequence' => 0,
'matrix_type' => RegistrationsComponent::MATRIX_TYPE_ROW_OR_NO_MATRIX,
'choice_label' => __d('registrations', 'new choice') . '1',
'other_choice_type' => RegistrationsComponent::OTHER_CHOICE_TYPE_NO_OTHER_FILED,
'graph_color' => '#FF0000',
'skip_page_sequence' => RegistrationsComponent::SKIP_GO_TO_END
)
)
)
)
)
),
'WorkflowComment' => array(
'comment' => 'WorkflowComment save test'
),
);
return $data;
}
/**
* editアクションのGETテスト(ログインなし)用DataProvider
*
* ### 戻り値
* - urlOptions: URLオプション
* - assert: テストの期待値
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderEditGet() {
$data = $this->__getData();
$results = array();
//ログインなし
$results[0] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_42'),
'assert' => null, 'exception' => 'ForbiddenException'
);
return $results;
}
/**
* editアクションのGETテスト(作成権限のみ)用DataProvider
*
* ### 戻り値
* - urlOptions: URLオプション
* - assert: テストの期待値
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderEditGetByCreatable() {
$data = $this->__getData();
$results = array();
//作成権限のみ
//--他人の記事の編集
$results[0] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_42'),
'assert' => null,
'exception' => 'BadRequestException'
);
//--自分の記事の編集(一度も公開していない)
$results[1] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_44'),
'assert' => array('method' => 'assertNotEmpty'),
);
// 存在してない登録フォームを指定
$results[2] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_99999'),
'assert' => null, 'exception' => 'BadRequestException', 'return' => 'json'
);
//新規作成
$results[3] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
'assert' => array('method' => 'assertNotEmpty'),
);
//--自分の記事の編集(公開すみ)
$results[4] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_10'),
'assert' => array('method' => 'assertNotEmpty'),
);
//--自分の記事の編集(一度も公開していない)
$results[1] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_44'),
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => '_method', 'value' => 'DELETE'),
);
return $results;
}
/**
* editアクションのGETテスト(編集権限、公開権限なし)用DataProvider
*
* ### 戻り値
* - urlOptions: URLオプション
* - assert: テストの期待値
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderEditGetByEditable() {
$data = $this->__getData();
$base = 0;
$results = array();
//編集権限あり
//--コンテンツあり 自分の記事(編集できるコンテンツ
$results[0] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_42'),
'assert' => array('method' => 'assertNotEmpty'),
);
/* 本来はここで表示ページの要素の妥当性をチェックするのだと思われるが
* 登録フォームはAngularでページ要素を展開しているため、NetCommons通常テスト確認メソッドが使えない
* ごく一部に限って確認を行うことにする
*/
// ページタブ,ページ追加リンク,項目追加ボタン,項目LI、項目種別選択,項目削除ボタン, 選択肢追加ボタン, 選択肢削除ボタン、キャンセルボタン、次へボタンの存在の確認
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][title]', 'value' => null),
)));
//array_push($results, Hash::merge($results[$base], array(
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][answer_timing]', 'value' => null),
//)));
//array_push($results, Hash::merge($results[$base], array(
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][total_show_timing]', 'value' => null),
//)));
//array_push($results, Hash::merge($results[$base], array(
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][is_no_member_allow]', 'value' => null),
//)));
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][is_key_pass_use]', 'value' => null),
)));
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][is_image_authentication]', 'value' => null),
)));
//array_push($results, Hash::merge($results[$base], array(
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][is_repeat_allow]', 'value' => null),
//)));
//array_push($results, Hash::merge($results[$base], array(
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Registration][is_anonymity]', 'value' => null),
//)));
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'textarea', 'name' => 'data[Registration][thanks_content]', 'value' => null),
)));
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'button', 'name' => 'save_' . WorkflowComponent::STATUS_IN_DRAFT, 'value' => null),
)));
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'button', 'name' => 'save_' . WorkflowComponent::STATUS_APPROVAL_WAITING, 'value' => null),
)));
//--コンテンツなし...編集対象データを指定せずに編集画面へ行くと不正リクエストエラー
$results[count($results)] = array(
'urlOptions' => array('frame_id' => '14', 'block_id' => null, 'action' => $this->_myAction, 'key' => null),
'assert' => null,
'exception' => 'BadRequestException'
);
return $results;
}
/**
* editアクションのGETテスト(公開権限あり)用DataProvider
*
* ### 戻り値
* - urlOptions: URLオプション
* - assert: テストの期待値
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderEditGetByPublishable() {
$data = $this->__getData();
$results = array();
//フレームID指定なしテスト
$results[0] = array(
'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_2'),
'assert' => array('method' => 'assertNotEmpty'),
);
//フレームID指定なしでも画面の内容がちゃんと表示されていることを確認している
array_push($results, Hash::merge($results[0], array(
'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_2'),
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Frame][id]', 'value' => null),
)));
// いったん公開して、その後の一時保存データに対して編集している
array_push($results, Hash::merge($results[0], array(
'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_2'),
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => '_method', 'value' => 'DELETE'),
)));
return $results;
}
/**
* editアクションのPOSTテスト用DataProvider
*
* ### 戻り値
* - data: 登録データ
* - role: ロール
* - urlOptions: URLオプション
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderEditPost() {
$data = $this->__getData();
return array(
//ログインなし
array(
'data' => $data, 'role' => null,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 'key' => 'registration_44'),
'exception' => 'ForbiddenException'
),
//作成権限のみ
//--他人の記事
array(
'data' => $data, 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'key' => 'registration_40'),
'exception' => 'BadRequestException'
),
array(
'data' => $data, 'role' => Role::ROOM_ROLE_KEY_EDITOR,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'key' => 'registration_40'),
'exception' => 'BadRequestException', 'return' => 'json'
),
//--自分の記事(一度も公開していない)
array(
'data' => $this->__getData('registration_44'), 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
),
//--自分の記事(公開)
array(
'data' => $this->__getData('registration_12'), 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
),
//編集権限あり
//--新規作成
array(
'data' => $data, 'role' => Role::ROOM_ROLE_KEY_EDITOR,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
),
//フレームID指定なし 新規作成テスト
array(
'data' => $data, 'role' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR,
'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
),
//--自分の記事(公開)
array(
'data' => $this->__getData('registration_4'), 'role' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
),
);
}
/**
* editアクションのValidationErrorテスト用DataProvider
*
* ### 戻り値
* - data: 登録データ
* - urlOptions: URLオプション
* - validationError: バリデーションエラー
*
* @return array
*/
public function dataProviderEditValidationError() {
$data = $this->__getData();
$dataPeriodOn = Hash::merge($data, array('Registration' => array('answer_timing' => '1')));
//$dataPeriodOn2 = Hash::merge($data, array('Registration' => array('total_show_timing' => '1')));
$result = array(
'data' => $data,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
);
$resultPeriodOn = array(
'data' => $dataPeriodOn,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
);
//$resultPeriodOn2 = array(
// 'data' => $dataPeriodOn2,
// 'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id'], 'action' => $this->_myAction, 's_id' => 'testSession'),
//);
return array(
Hash::merge($result, array(
'validationError' => array(
'field' => 'Registration.title',
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('registrations', 'Title')),
)
)),
//Hash::merge($result, array(
// 'validationError' => array(
// 'field' => 'Registration.answer_timing',
// 'value' => 'aa',
// 'message' => __d('net_commons', 'Invalid request.'),
// )
//)),
Hash::merge($resultPeriodOn, array(
'validationError' => array(
'field' => 'Registration.answer_start_period',
'value' => '2019-08-01 00:00:00',
'message' => __d('registrations', 'start period must be smaller than end period'),
)
)),
Hash::merge($resultPeriodOn, array(
'validationError' => array(
'field' => 'Registration.answer_end_period',
'value' => '2015-08-01 00:00:00',
'message' => __d('registrations', 'start period must be smaller than end period'),
)
)),
//Hash::merge($result, array(
// 'validationError' => array(
// 'field' => 'Registration.total_show_timing',
// 'value' => 'aa',
// 'message' => __d('net_commons', 'Invalid request.'),
// )
//)),
//5
//Hash::merge($resultPeriodOn2, array(
// 'validationError' => array(
// 'field' => 'Registration.total_show_start_period',
// 'value' => '',
// 'message' => __d('registrations', 'if you set the period, please set time.'),
// )
//)),
//Hash::merge($result, array(
// 'validationError' => array(
// 'field' => 'Registration.is_no_member_allow',
// 'value' => 'aa',
// 'message' => __d('net_commons', 'Invalid request.'),
// )
//)),
//Hash::merge($result, array(
// 'validationError' => array(
// 'field' => 'Registration.is_anonymity',
// 'value' => 'aa',
// 'message' => __d('net_commons', 'Invalid request.'),
// )
//)),
Hash::merge($result, array(
'validationError' => array(
'field' => 'Registration.is_key_pass_use',
'value' => 'aa',
'message' => __d('net_commons', 'Invalid request.'),
)
)),
//Hash::merge($result, array(
// 'validationError' => array(
// 'field' => 'Registration.is_repeat_allow',
// 'value' => 'aa',
// 'message' => __d('net_commons', 'Invalid request.'),
// )
//)),
Hash::merge($result, array(
'validationError' => array(
'field' => 'Registration.is_image_authentication',
'value' => 'aa',
'message' => __d('net_commons', 'Invalid request.'),
)
)),
);
}
}