-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditTest.php
212 lines (188 loc) · 4.69 KB
/
EditTest.php
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
<?php
/**
* CabinetBlocksController::add(),edit(),delete()
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Ryuji AMANO <ryuji@ryus.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');
/**
* CabinetBlocksController::add(),edit(),delete()
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @package NetCommons\Cabinets\Test\Case\Controller\CabinetBlocksController
*/
class CabinetBlocksControllerEditTest extends BlocksControllerEditTest {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.cabinets.cabinet',
'plugin.cabinets.cabinet_file',
'plugin.cabinets.cabinet_file_tree',
'plugin.cabinets.block_setting_for_cabinet',
'plugin.workflow.workflow_comment',
'plugin.authorization_keys.authorization_keys',
'plugin.site_manager.site_setting',
);
/**
* Plugin name
*
* @var string
*/
public $plugin = 'cabinets';
/**
* Controller name
*
* @var string
*/
protected $_controller = 'cabinet_blocks';
/**
* Edit controller name
*
* @var string
*/
protected $_editController = 'cabinet_blocks';
/**
* テストDataの取得
*
* @param bool $isEdit 編集かどうか
* @return array
*/
private function __data($isEdit) {
$frameId = '6';
//$frameKey = 'frame_3';
if ($isEdit) {
$blockId = '2';
$blockKey = 'block_1';
$cabinetId = '3';
$cabinetKey = 'cabinet_key_2';
} else {
$blockId = null;
$blockKey = null;
$cabinetId = null;
$cabinetKey = null;
}
$data = array(
'Frame' => array(
'id' => $frameId
),
'Block' => array(
'id' => $blockId,
'key' => $blockKey,
'language_id' => '2',
'room_id' => '2',
'plugin_key' => $this->plugin,
'public_type' => '1',
'from' => null,
'to' => null,
),
// 必要のデータセットをここに書く
'Cabinet' => array(
'id' => $cabinetId,
'key' => $cabinetKey,
'block_id' => $blockId,
'name' => 'Cabinet name',
),
);
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' => 'Cabinet.name', // エラーにするフィールド指定
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('cabinets', 'Cabinet 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' => 'Cabinet.name', //エラーにするフィールド指定
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('cabinets', 'Cabinet name')),
)
);
return $results;
}
/**
* delete()アクションDataProvider
*
* ### 戻り値
* - data 削除データ
*
* @return array
*/
public function dataProviderDelete() {
$data = array(
'Block' => array(
'id' => '4',
'key' => 'block_2',
),
//必要に応じてパラメータ変更する
'Cabinet' => array(
'key' => 'cabinet_key_2',
),
);
//テストデータ
$results = array();
$results[0] = array('data' => $data);
return $results;
}
/**
* CabinetNotFoundでBadRequest
*
* @return void
*/
public function testEditCabinetNotFound() {
//ログイン
TestAuthGeneral::login($this);
$this->_mockForReturnFalse('Cabinets.Cabinet', 'getCabinet', 1);
// Blog::getBlog()がfalseならBadRequest
//$this->setExpectedException('BadRequestException');
//テスト実行
$this->_testGetAction(array('action' => 'edit', 'block_id' => '2', 'frame_id' => '6'),
false, 'BadRequestException', 'view');
//ログアウト
TestAuthGeneral::logout($this);
}
}