-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTopicGetQueryOptionsTestCase.php
More file actions
491 lines (469 loc) · 19.9 KB
/
TopicGetQueryOptionsTestCase.php
File metadata and controls
491 lines (469 loc) · 19.9 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
<?php
/**
* Topic::getQueryOptions()のテスト
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('NetCommonsGetTest', 'NetCommons.TestSuite');
/**
* Topic::getQueryOptions()のテスト
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Topics\Test\Case\Model\Topic
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
abstract class TopicGetQueryOptionsTestCase extends NetCommonsGetTest {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.categories.category',
'plugin.categories.categories_language',
'plugin.categories.category_order',
'plugin.topics.topic_frame_setting',
'plugin.topics.topic_frames_block',
'plugin.topics.topic_frames_plugin',
'plugin.topics.topic_frames_room',
'plugin.workflow.workflow_comment',
'plugin.topics.block4topics',
'plugin.topics.blocks_language4topics',
'plugin.topics.plugin4topics',
'plugin.topics.room4topics',
'plugin.topics.rooms_language4topics',
'plugin.topics.roles_room4topics',
'plugin.topics.roles_rooms_user4topics',
'plugin.topics.topic4topics',
'plugin.topics.topic_readable4topics',
'plugin.topics.topic_user_status4topics',
);
/**
* Plugin name
*
* @var string
*/
public $plugin = 'topics';
/**
* Model name
*
* @var string
*/
protected $_modelName = 'Topic';
/**
* Method name
*
* @var string
*/
protected $_methodName = 'getQueryOptions';
/**
* フラットで表示、ステータスの絞り込みなしのテストのDataProvider
* ※テストデータを返却するメソッドのため、@codeCoverageIgnore で除外する
*
* ### 戻り値
* - userId ユーザID
* - expected 期待値
*
* ### テストデータ
* #### 掲示板
* - content_key_1[topic_id=1,2] 管理者が投稿(公開中)
* - content_key_2[topic_id=3] 一般1が投稿(未承認)
* - content_key_3[topic_id=4] 一般1が投稿(承認待ち⇒差し戻し)
* - content_key_4[topic_id=5,6] 一般1が投稿(承認待ち⇒公開)
* - content_key_5[topic_id=7,8] 一般1が投稿(承認待ち⇒公開⇒承認待ち(編集者が修正))
* #### ブログ(公開日のチェック)
* - content_key_9 管理者が投稿(公開中、現在)
* - content_key_10 管理者が投稿(公開中、未来)
* - content_key_11 管理者が投稿(公開中、過去1日前)
* - content_key_12 管理者が投稿(公開中、過去3日前)
* - content_key_13 管理者が投稿(公開中、過去7日前)
* - content_key_14 管理者が投稿(公開中、過去14日前)
* - content_key_15 管理者が投稿(公開中、過去30日前)
* - content_key_16 管理者が投稿(公開中、過去30日以上前)
* #### お知らせ(ブロックの公開状態、公開日のチェック)
* - content_key_17[block_id=3] ブロック公開
* - content_key_18[block_id=4] ブロック非公開
* - content_key_19[block_id=5] ブロック期限付き+期限内
* - content_key_20[block_id=6] ブロック期限付き+期限内(startのみ指定)
* - content_key_21[block_id=7] ブロック期限付き+期限内(endのみ指定)
* - content_key_22[block_id=8] ブロック期限付き+期限前
* - content_key_23[block_id=9] ブロック期限付き+期限切れ
* - content_key_24[block_id=10,room_id=6] 管理者プライベート
* - content_key_25[block_id=11,room_id=9] 一般1プライベート
* - content_key_26[block_id=12,room_id=12] ルーム2
* #### FAQ(カテゴリ)
* - content_key_27 カテゴリなし
* - content_key_28 カテゴリ1
* - content_key_29 カテゴリ1
* - content_key_30 カテゴリ2
* - content_key_31 存在しないカテゴリ
* #### 回覧板(イレギュラープラグイン)
* - content_key_32 ルームに参加している全会員(パブリック)
* - content_key_33 ルームに参加している全会員(ルーム2)
* - content_key_34 個別に選択(パブリック)
* - content_key_35 個別に選択(ルーム2, 参加していないユーザを含む)
* - content_key_36 回覧期間、期間内、回答期限なし
* - content_key_37 回覧期間、期間内、回答期限あり(期間内)
* - content_key_54 回覧期間、期間内、回答期限あり(期間外)
* - content_key_38 回覧期間、期間内(start、end指定なし)、回答期限なし
* - content_key_39 回覧期間、期間内(start、end指定なし)、回答期限あり(期間内)
* - content_key_55 回覧期間、期間内(start、end指定なし)、回答期限あり(期間外)
* - content_key_40 回覧期間、期間内(startのみ指定)、回答期限なし
* - content_key_41 回覧期間、期間内(startのみ指定)、回答期限あり(期間内)
* - content_key_56 回覧期間、期間内(startのみ指定)、回答期限あり(期間外)
* - content_key_42 回覧期間、期間内(endのみ指定)、回答期限なし
* - content_key_43 回覧期間、期間内(endのみ指定)、回答期限あり(期間内)
* - content_key_57 回覧期間、期間内(endのみ指定)、回答期限あり(期間外)
* - content_key_44 回覧期間、期間前、回答期限なし
* - content_key_45 回覧期間、期間前、回答期限あり(期間内)
* - content_key_58 回覧期間、期間前、回答期限あり(期間外)
* - content_key_46 回覧期間、期間終了(endのみ指定)、回答期限なし
* - content_key_47 回覧期間、期間終了(endのみ指定)、回答期限あり(範囲内)
* - content_key_59 回覧期間、期間終了(endのみ指定)、回答期限あり(範囲外)
* - content_key_48 回覧期間、期間終了(start,end指定)、回答期限なし
* - content_key_49 回覧期間、期間終了(start,end指定)、回答期限あり(範囲内)
* - content_key_60 回覧期間、期間終了(start,end指定)、回答期限あり(範囲外)
* #### カレンダー(イレギュラープラグイン)
* - content_key_70 プライベートの予定(共有なし)
* - content_key_71 プライベートの予定(共有あり)
* - content_key_72 パブリックの予定
* - content_key_73 会員全体の予定
* - content_key_74 ルームの予定
*
* @param array $topicIds トピックID
* @param int $userId ユーザID
* @return array データ
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @codeCoverageIgnore
*/
protected function _data($topicIds, $userId) {
$result = array();
foreach ($topicIds as $topicId) {
$data = array();
if (in_array($topicId, ['1', '2', '3', '4', '5', '6', '7', '8'], true)) {
//#### 掲示板
if ($topicId === '1') {
// - content_key_1 管理者が投稿(公開中)
// ** is_latest
$data = array(
'Topic' => array('id' => '1', 'content_key' => 'content_key_1', 'category_id' => null),
'TopicReadable' => array('id' => '1', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '1';
}
} elseif ($topicId === '2') {
// - content_key_1 管理者が投稿(公開中)
// ** is_active
$data = array(
'Topic' => array('id' => '2', 'content_key' => 'content_key_1', 'category_id' => null),
'TopicReadable' => array('id' => '2', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
} elseif ($topicId === '3') {
// - content_key_2 一般1が投稿(未承認)
// ** is_latestのみ
$data = array(
'Topic' => array('id' => '3', 'content_key' => 'content_key_2', 'category_id' => null),
'TopicReadable' => array('id' => '3', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($userId === '4') {
$data['TopicUserStatus']['id'] = '2';
}
} elseif ($topicId === '4') {
// - content_key_3 一般1が投稿(承認待ち⇒差し戻し)
// ** is_latestのみ
$data = array(
'Topic' => array('id' => '4', 'content_key' => 'content_key_3', 'category_id' => null),
'TopicReadable' => array('id' => '4', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '3';
} elseif ($userId === '4') {
$data['TopicUserStatus']['id'] = '4';
}
} elseif ($topicId === '5') {
// - content_key_4 一般1が投稿(承認待ち⇒公開)
// ** is_latest
$data = array(
'Topic' => array('id' => '5', 'content_key' => 'content_key_4', 'category_id' => null),
'TopicReadable' => array('id' => '5', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '5';
} elseif ($userId === '4') {
$data['TopicUserStatus']['id'] = '6';
}
} elseif ($topicId === '6') {
// - content_key_4 一般1が投稿(承認待ち⇒公開)
// ** is_active
$data = array(
'Topic' => array('id' => '6', 'content_key' => 'content_key_4', 'category_id' => null),
'TopicReadable' => array('id' => '6', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($userId === '6') {
$data['TopicUserStatus']['id'] = '7';
}
} elseif ($topicId === '7') {
// - content_key_5 一般1が投稿(承認待ち⇒公開⇒承認待ち(編集者が修正))
// ** is_latest
$data = array(
'Topic' => array('id' => '7', 'content_key' => 'content_key_5', 'category_id' => null),
'TopicReadable' => array('id' => '7', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '8';
} elseif ($userId === '4') {
$data['TopicUserStatus']['id'] = '9';
} elseif ($userId === '3') {
$data['TopicUserStatus']['id'] = '10';
}
} elseif ($topicId === '8') {
// - content_key_5 一般1が投稿(承認待ち⇒公開⇒承認待ち(編集者が修正))
// ** is_active
$data = array(
'Topic' => array('id' => '8', 'content_key' => 'content_key_5', 'category_id' => null),
'TopicReadable' => array('id' => '8', 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
}
} elseif (in_array($topicId, ['27', '28', '29', '30', '31'], true)) {
//#### FAQ(カテゴリ)
if ($topicId === '27') {
// - content_key_27 カテゴリなし
$topicCateId = null;
$categoryId = null;
} elseif ($topicId === '28' || $topicId === '29') {
// - content_key_28 カテゴリ1
// - content_key_29 カテゴリ1
$topicCateId = '1';
$categoryId = '1';
} elseif ($topicId === '30') {
// - content_key_30 カテゴリ2
$topicCateId = '2';
$categoryId = '2';
} else {
// - content_key_31 存在しないカテゴリ
$topicCateId = '9999';
$categoryId = null;
}
$data = array(
'Topic' => array(
'id' => $topicId,
'content_key' => 'content_key_' . $topicId,
'category_id' => $topicCateId
),
'TopicReadable' => array('id' => $topicId, 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => $categoryId),
);
} elseif ($topicId >= '32' && $topicId <= '60') {
//#### 回覧板(イレギュラープラグイン)
$data = array(
'Topic' => array(
'id' => $topicId, 'content_key' => 'content_key_' . $topicId, 'category_id' => null
),
'TopicReadable' => array('id' => $topicId, 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($topicId === '32' || $topicId === '50') {
// - content_key_32 ルームに参加している全会員(パブリック)
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '32';
} elseif ($userId === '4') {
$data['TopicReadable']['id'] = '55';
$data['TopicUserStatus']['id'] = '50';
} elseif ($userId === '5' || $userId === '6') {
$data['TopicReadable']['id'] = '55';
}
$data['Topic']['content_key'] = 'content_key_32';
} elseif ($topicId === '33' || $topicId === '51') {
// - content_key_33 ルームに参加している全会員(ルーム2)
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '33';
} elseif ($userId === '4') {
$data['TopicUserStatus']['id'] = '51';
} elseif ($userId === '3') {
$data['TopicReadable']['id'] = '56';
}
$data['Topic']['content_key'] = 'content_key_33';
} elseif ($topicId === '34' || $topicId === '52') {
// - content_key_34 個別に選択(パブリック)
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '34';
} elseif ($userId === '2') {
$data['TopicReadable']['id'] = '50';
} elseif ($userId === '4') {
$data['TopicReadable']['id'] = '51';
$data['TopicUserStatus']['id'] = '52';
}
$data['Topic']['content_key'] = 'content_key_34';
$data['TopicReadable']['user_id'] = $userId;
} elseif ($topicId === '35' || $topicId === '53') {
// - content_key_35 個別に選択(ルーム2, 参加していないユーザを含む)
if ($userId === '1') {
$data['TopicUserStatus']['id'] = '35';
} elseif ($userId === '2') {
$data['TopicReadable']['id'] = '52';
} elseif ($userId === '4') {
$data['TopicReadable']['id'] = '53';
$data['TopicUserStatus']['id'] = '53';
}
$data['Topic']['content_key'] = 'content_key_35';
$data['TopicReadable']['user_id'] = $userId;
} else {
// - content_key_36 回覧期間、期間内、回答期限なし
// - content_key_37 回覧期間、期間内、回答期限あり(期間内)
// - content_key_54 回覧期間、期間内、回答期限あり(期間外)
if ($topicId === '54') {
$data['TopicReadable']['id'] = '57';
}
// - content_key_38 回覧期間、期間内(start、end指定なし)、回答期限なし
// - content_key_39 回覧期間、期間内(start、end指定なし)、回答期限あり(期間内)
// - content_key_55 回覧期間、期間内(start、end指定なし)、回答期限あり(期間外)
if ($topicId === '55') {
$data['TopicReadable']['id'] = '58';
}
// - content_key_40 回覧期間、期間内(startのみ指定)、回答期限なし
// - content_key_41 回覧期間、期間内(startのみ指定)、回答期限あり(期間内)
// - content_key_56 回覧期間、期間内(startのみ指定)、回答期限あり(期間外)
if ($topicId === '56') {
$data['TopicReadable']['id'] = '59';
}
// - content_key_42 回覧期間、期間内(endのみ指定)、回答期限なし
// - content_key_43 回覧期間、期間内(endのみ指定)、回答期限あり(期間内)
// - content_key_57 回覧期間、期間内(endのみ指定)、回答期限あり(期間外)
if ($topicId === '57') {
$data['TopicReadable']['id'] = '60';
}
// - content_key_44 回覧期間、期間前、回答期限なし
// - content_key_45 回覧期間、期間前、回答期限あり(期間内)
// - content_key_58 回覧期間、期間前、回答期限あり(期間外)
if ($topicId === '58') {
$data['TopicReadable']['id'] = '61';
}
// - content_key_46 回覧期間、期間終了(endのみ指定)、回答期限なし
// - content_key_47 回覧期間、期間終了(endのみ指定)、回答期限あり(範囲内)
// - content_key_59 回覧期間、期間終了(endのみ指定)、回答期限あり(範囲外)
if ($topicId === '59') {
$data['TopicReadable']['id'] = '62';
}
// - content_key_48 回覧期間、期間終了(start,end指定)、回答期限なし
// - content_key_49 回覧期間、期間終了(start,end指定)、回答期限あり(範囲内)
// - content_key_60 回覧期間、期間終了(start,end指定)、回答期限あり(範囲外)
if ($topicId === '60') {
$data['TopicReadable']['id'] = '63';
}
}
} elseif ($topicId >= '70' && $topicId <= '74') {
//#### カレンダー(イレギュラープラグイン)
// - content_key_70 プライベートの予定(共有なし)
// - content_key_71 プライベートの予定(共有あり)
// - content_key_72 パブリックの予定
// - content_key_73 会員全体の予定
// - content_key_74 ルームの予定
$data = array(
'Topic' => array(
'id' => $topicId,
'content_key' => 'content_key_' . $topicId,
'category_id' => null
),
'TopicReadable' => array('id' => $topicId, 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
if ($topicId === '71') {
if ($userId === '4') {
$data['TopicReadable']['id'] = '75';
$data['TopicReadable']['user_id'] = $userId;
$data['Topic']['content_key'] = 'content_key_71';
}
}
} else {
//#### ブログ(公開日のチェック)
// - content_key_9 管理者が投稿(公開中、現在)
// - content_key_10 管理者が投稿(公開中、未来)
// - content_key_11 管理者が投稿(公開中、過去1日前)
// - content_key_12 管理者が投稿(公開中、過去3日前)
// - content_key_13 管理者が投稿(公開中、過去7日前)
// - content_key_14 管理者が投稿(公開中、過去14日前)
// - content_key_15 管理者が投稿(公開中、過去30日前)
// - content_key_16 管理者が投稿(公開中、過去30日以上前)
//#### お知らせ(ブロックの公開状態、公開日のチェック)
// - content_key_17[block_id=3] ブロック公開
// - content_key_18[block_id=4] ブロック非公開
// - content_key_19[block_id=5] ブロック期限付き+期限内
// - content_key_20[block_id=6] ブロック期限付き+期限内(startのみ指定)
// - content_key_21[block_id=7] ブロック期限付き+期限内(endのみ指定)
// - content_key_22[block_id=8] ブロック期限付き+期限前
// - content_key_23[block_id=9] ブロック期限付き+期限切れ
// - content_key_24[block_id=10,room_id=6] 管理者プライベート
// - content_key_25[block_id=11,room_id=9] 一般1プライベート
// - content_key_26[block_id=12,room_id=12] ルーム2
$data = array(
'Topic' => array(
'id' => $topicId,
'content_key' => 'content_key_' . $topicId,
'category_id' => null
),
'TopicReadable' => array('id' => $topicId, 'user_id' => '0'),
'TopicUserStatus' => array('id' => null),
'Category' => array('id' => null),
);
}
$result[] = $data;
}
return $result;
}
/**
* getQueryOptions()のテスト
*
* @param int $userId ユーザID
* @param int $status ステータス
* @param array $options オプション
* @param array $expected 期待値
* @dataProvider dataProviderByFlatWOStatus
* @return void
*/
protected function _testGetQueryOptions($userId, $status, $options, $expected) {
$model = $this->_modelName;
$methodName = $this->_methodName;
//データ生成
if ($userId) {
Current::write('User.id', $userId);
}
//テスト実施
$result = $this->$model->find('all',
Hash::merge(
array('fields' => array(
'Topic.id', 'Topic.content_key', 'Topic.category_id',
'TopicReadable.id', 'TopicReadable.user_id',
'TopicUserStatus.id', 'Category.id'
)),
$this->$model->$methodName($status, $options)
)
);
//チェック
$this->assertEquals($result, $expected);
}
}