-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAddTest.php
More file actions
321 lines (298 loc) · 9.73 KB
/
AddTest.php
File metadata and controls
321 lines (298 loc) · 9.73 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
<?php
/**
* RegistrationAddController 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('RegistrationAddController', 'Registrations.Controller');
App::uses('WorkflowControllerAddTest', 'Workflow.TestSuite');
/**
* FaqQuestionsController Test Case
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Faqs\Test\Case\Controller\FaqQuestionsController
*/
class RegistrationAddControllerAddTest extends WorkflowControllerAddTest {
/**
* 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.workflow.workflow_comment',
);
/**
* Plugin name
*
* @var array
*/
public $plugin = 'registrations';
/**
* Controller name
*
* @var string
*/
protected $_controller = 'registration_add';
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Registration = ClassRegistry::init('Registrations.Registration');
$this->Registration->Behaviors->unload('AuthorizationKey');
$this->ActionRegistrationAdd = ClassRegistry::init('Registrations.ActionRegistrationAdd');
Current::write('Block.id', '2');
}
/**
* テストDataの取得
*
* @return array
*/
private function __getData() {
$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,
),
'ActionRegistrationAdd' => array(
'create_option' => 'create',
'title' => 'New Registration Title',
),
);
return $data;
}
/**
* テストDataの取得
*
* @return array
*/
private function __getDataPastReuse() {
$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,
),
'ActionRegistrationAdd' => array(
'create_option' => 'reuse',
//'past_registration_id' => '32',
'past_registration_id' => '52',
),
);
return $data;
}
/**
* addアクションのGETテスト(ログインなし)用DataProvider
*
* ### 戻り値
* - urlOptions: URLオプション
* - assert: テストの期待値
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderAddGet() {
$data = $this->__getData();
$results = array();
//ログインなし
$results[0] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
'assert' => null, 'exception' => 'ForbiddenException'
);
return $results;
}
/**
* addアクションのGETテスト(作成権限あり)用DataProvider
*
* ### 戻り値
* - urlOptions: URLオプション
* - assert: テストの期待値
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderAddGetByCreatable() {
$data = $this->__getData();
$results = array();
//作成権限あり
$base = 0;
// 正しいフレームIDとブロックID
$results[0] = array(
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
'assert' => array('method' => 'assertNotEmpty'),
);
// フレームIDのhidden-inputがあるか
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Frame][id]', 'value' => $data['Frame']['id']),
)));
// ブロックIDのhidden-inputがあるか
//array_push($results, Hash::merge($results[$base], array(
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Block][id]', 'value' => $data['Block']['id']),
//)));
// 作成方法選択肢オプションがあるか
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[ActionRegistrationAdd][create_option]', 'value' => null),
)));
// タイトル入力テキストがあるか
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'text', 'name' => 'data[ActionRegistrationAdd][title]', 'value' => null),
)));
// 過去再利用の絞込テキスト入力とhiddenがあることを確認する
// 本当は過去の登録フォーム一覧が表示されることも確認せねばならないが、それはAngularで展開しているのでphpunitでは確認できないため省略
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'text', 'name' => 'data[ActionRegistrationAdd][past_search]', 'value' => null),
)));
array_push($results, Hash::merge($results[$base], array(
'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[ActionRegistrationAdd][past_registration_id]', 'value' => null),
)));
// テンプレートファイル読み込みがあるか
//array_push($results, Hash::merge($results[$base], array(
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[ActionRegistrationAdd][template_file]', 'value' => null),
//)));
//フレームID指定なしテスト (ありえないはず。 by RyujiAMANO)
//array_push($results, Hash::merge($results[$base], array(
// 'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id']),
// 'assert' => array('method' => 'assertNotEmpty'),
//)));
//array_push($results, Hash::merge($results[$base], array(
// 'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id']),
// 'assert' => array('method' => 'assertInput', 'type' => 'input', 'name' => 'data[Frame][id]', 'value' => null),
//)));
return $results;
}
/**
* addアクションのPOSTテスト用DataProvider
*
* ### 戻り値
* - data: 登録データ
* - role: ロール
* - urlOptions: URLオプション
* - exception: Exception
* - return: testActionの実行後の結果
*
* @return array
*/
public function dataProviderAddPost() {
$data = $this->__getData();
return array(
//ログインなし
array(
'data' => $data, 'role' => null,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
'exception' => 'ForbiddenException'
),
//作成権限あり
array(
'data' => $data, 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
),
array(
'data' => $this->__getDataPastReuse(), 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
),
//フレームID指定なしテスト
array(
'data' => $data, 'role' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR,
'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id']),
),
);
}
/**
* addアクションのValidationErrorテスト用DataProvider
*
* ### 戻り値
* - data: 登録データ
* - urlOptions: URLオプション
* - validationError: バリデーションエラー
*
* @return array
*/
public function dataProviderAddValidationError() {
$data = $this->__getData();
$result = array(
'data' => $data,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
);
$dataPastReuse = $this->__getDataPastReuse();
$resultPastReuse = array(
'data' => $dataPastReuse,
'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
);
//$dataTemplate = $this->__getData();
//$dataTemplate['ActionRegistrationAdd']['create_option'] = 'template';
//$resultTemplate = array(
// 'data' => $dataTemplate,
// 'urlOptions' => array('frame_id' => $data['Frame']['id'], 'block_id' => $data['Block']['id']),
//);
return array(
Hash::merge($result, array(
'validationError' => array(
'field' => 'ActionRegistrationAdd.create_option',
'value' => null,
'message' => sprintf(__d('registrations', 'Please choose create option.'))
)
)),
Hash::merge($result, array(
'validationError' => array(
'field' => 'ActionRegistrationAdd.title',
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('registrations', 'Title'))
)
)),
Hash::merge($resultPastReuse, array(
'validationError' => array(
'field' => 'ActionRegistrationAdd.past_registration_id',
'value' => '',
'message' => sprintf(__d('registrations', 'Please select past registration.'))
)
)),
Hash::merge($resultPastReuse, array(
'validationError' => array(
'field' => 'ActionRegistrationAdd.past_registration_id',
'value' => '9999999',
'message' => sprintf(__d('registrations', 'Please select past registration.'))
)
)),
//Hash::merge($resultTemplate, array(
// 'validationError' => array(
// 'field' => 'ActionRegistrationAdd.template_file',
// 'value' => null,
// 'message' => sprintf(__d('registrations', 'file upload error.'))
// )
//)),
);
}
}