-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEditTest.php
More file actions
230 lines (203 loc) · 4.97 KB
/
EditTest.php
File metadata and controls
230 lines (203 loc) · 4.97 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
<?php
/**
* LinkBlocksController::edit()のテスト
*
* @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('BlocksControllerEditTest', 'Blocks.TestSuite');
/**
* LinkBlocksController::edit()のテスト
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Links\Test\Case\Controller\LinkBlocksController
*/
class LinkBlocksControllerEditTest extends BlocksControllerEditTest {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.categories.category',
'plugin.categories.category_order',
'plugin.categories.categories_language',
'plugin.links.link',
'plugin.links.link_frame_setting',
'plugin.links.link_order',
'plugin.links.block_setting_for_link',
'plugin.workflow.workflow_comment',
);
/**
* Plugin name
*
* @var string
*/
public $plugin = 'links';
/**
* Controller name
*
* @var string
*/
protected $_controller = 'link_blocks';
/**
* Edit controller name
*
* @var string
*/
protected $_editController = 'link_blocks';
/**
* テストDataの取得
*
* @param bool $isEdit 編集かどうか
* @return array
*/
private function __data($isEdit) {
$frameId = '6';
if ($isEdit) {
$blockId = '2';
$blockKey = 'block_2';
$linkId = '3';
$linkKey = $blockKey;
} else {
$blockId = null;
$blockKey = null;
$linkId = null;
$linkKey = $blockKey;
}
$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,
),
'LinkSetting' => array(
'id' => $linkId,
'block_key' => $linkKey,
),
'LinkBlock' => array(
'id' => $blockId,
'key' => $blockKey,
'name' => 'Link 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' => 'LinkBlock.name',
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Link list Title')),
)
);
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' => 'LinkBlock.name',
'value' => '',
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Link list Title')),
)
);
return $results;
}
/**
* edit()アクションのExceptionErrorテスト
*
* @return void
*/
public function testEditGetOnExceptionError() {
//ログイン
TestAuthGeneral::login($this);
//テストデータ
$this->_mockForReturnFalse('Links.LinkBlock', 'getLinkBlock');
//テスト実行
$this->_testGetAction(array('action' => 'edit', 'block_id' => '2', 'frame_id' => '6'), null, 'BadRequestException');
//ログアウト
TestAuthGeneral::logout($this);
}
/**
* delete()アクションDataProvider
*
* ### 戻り値
* - data 削除データ
*
* @return array
*/
public function dataProviderDelete() {
$data = array(
'Block' => array(
'id' => '4',
'key' => 'block_2',
),
'LinkBlock' => array(
'key' => 'block_2',
),
);
//テストデータ
$results = array();
$results[0] = array('data' => $data);
return $results;
}
/**
* delete()アクションのExceptionErrorテスト
*
* @return void
*/
public function testDeleteOnExceptionError() {
//ログイン
TestAuthGeneral::login($this);
//テストデータ
$this->_mockForReturnFalse('Links.LinkBlock', 'deleteLinkBlock');
//テスト実行
$data = $this->dataProviderDelete()[0]['data'];
$this->_testPostAction('delete', $data, array('action' => 'delete', 'block_id' => '2', 'frame_id' => '6'), 'BadRequestException');
//ログアウト
TestAuthGeneral::logout($this);
}
}