-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEditTest.php
More file actions
240 lines (215 loc) · 5.15 KB
/
EditTest.php
File metadata and controls
240 lines (215 loc) · 5.15 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
<?php
/**
* TaskBlocksController::add(),edit(),delete()
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Nakata Tomoyoshi <nakata.tomoyoshi@withone.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('BlocksControllerEditTest', 'Blocks.TestSuite');
/**
* TaskBlocksController::add(),edit(),delete()
*
* @author Nakata Tomoyoshi <nakata.tomoyoshi@withone.co.jp>
* @package NetCommons\Tasks\Test\Case\Controller\TaskBlocksController
*/
class TaskBlocksControllerEditTest extends BlocksControllerEditTest {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.categories.category',
'plugin.categories.category_order',
'plugin.categories.categories_language',
'plugin.tasks.task',
'plugin.tasks.task_charge',
'plugin.tasks.task_content',
'plugin.tasks.block_setting_for_task',
'plugin.workflow.workflow_comment',
);
/**
* Plugin name
*
* @var string
*/
public $plugin = 'tasks';
/**
* Controller name
*
* @var string
*/
protected $_controller = 'task_blocks';
/**
* Edit controller name
*
* @var string
*/
protected $_editController = 'task_blocks';
/**
* テストDataの取得
*
* @param bool $isEdit 編集かどうか
* @return array
*/
private function __data($isEdit) {
$frameId = '6';
//$frameKey = 'frame_3';
if ($isEdit) {
$blockId = '4';
$blockKey = 'block_2';
$taskId = '3';
$taskKey = 'task_key_2';
} else {
$blockId = null;
$blockKey = null;
$taskId = null;
$taskKey = null;
}
$data = array(
'Frame' => array(
'id' => $frameId
),
'Block' => array(
'id' => $blockId,
'key' => $blockKey,
'room_id' => '2',
'plugin_key' => $this->plugin,
'public_type' => '1',
'from' => null,
'to' => null,
),
'BlocksLanguage' => array(
'language_id' => '2',
),
'Task' => array(
'id' => $taskId,
'key' => $taskKey,
'block_id' => $blockId,
'name' => 'Task name',
),
'old' => Array(
'Categories' =>
'[{
"Category":{
"id":"1",
"block_id":"2",
"key":"category_1",
"language_id":"2",
"name":"Category 1",
"created_user":"1",
"created":"2015-01-28 04:56:56",
"modified_user":"1",
"modified":"2015-01-28 04:56:56"
},"CategoryOrder":{
"id":"1",
"category_key":"category_1",
"block_key":"block_1",
"weight":"1",
"created_user":"1",
"created":"2015-01-28 04:57:05",
"modified_user":"1",
"modified":"2015-01-28 04:57:05"
}
}]'
),
);
return $data;
}
/**
* add()アクションDataProvider
*
* ### 戻り値
* - method: リクエストメソッド(get or post or put)
* - data: 登録データ
* - validationError: バリデーションエラー
*
* @return array
*/
public function dataProviderAdd() {
$data = $this->__data(false);
//テストデータ
$results = array();
$results[0] = array('method' => 'get');
$results[1] = array('method' => 'put');
$results[2] = array('method' => 'post', 'data' => $data, 'validationError' => false);
$results[3] = array('method' => 'post', 'data' => $data,
'validationError' => array(
'field' => 'Task.name',
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('tasks', 'Task name')),
)
);
return $results;
}
/**
* edit()アクションDataProvider
*
* ### 戻り値
* - method: リクエストメソッド(get or post or put)
* - data: 登録データ
* - validationError: バリデーションエラー
*
* @return array
*/
public function dataProviderEdit() {
$data = $this->__data(true);
//テストデータ
$results = array();
$results[0] = array('method' => 'get');
$results[1] = array('method' => 'post');
$results[2] = array('method' => 'put', 'data' => $data, 'validationError' => false);
$results[3] = array('method' => 'put', 'data' => $data,
'validationError' => array(
'field' => 'Task.name',
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('tasks', 'Task name')),
)
);
$data['old'] = array();
$results[4] = array('method' => 'put', 'data' => $data, 'validationError' => false);
return $results;
}
/**
* delete()アクションDataProvider
*
* ### 戻り値
* - data 削除データ
*
* @return array
*/
public function dataProviderDelete() {
$data = array(
'Block' => array(
'id' => '4',
'key' => 'block_2',
),
'Task' => array(
'key' => 'task_key_2',
),
);
//テストデータ
$results = array();
$results[0] = array('data' => $data);
return $results;
}
/**
* TaskNotFoundでBadRequest
*
* @return void
*/
public function testEditTaskNotFound() {
//ログイン
TestAuthGeneral::login($this);
$this->_mockForReturnFalse('Tasks.Task', 'getTask', 1);
//テスト実行
$result = $this->_testGetAction(array('action' => 'edit', 'block_id' => '2', 'frame_id' => '6'),
false, 'BadRequestException', 'view');
$this->assertFalse($result);
//ログアウト
TestAuthGeneral::logout($this);
}
}