-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFrameSettingsControllerTest.php
More file actions
188 lines (168 loc) · 4.79 KB
/
FrameSettingsControllerTest.php
File metadata and controls
188 lines (168 loc) · 4.79 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
<?php
/**
* BlocksControllerTest
*
* @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite');
/**
* BlocksControllerTest
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Blocks\TestSuite
* @codeCoverageIgnore
*/
abstract class FrameSettingsControllerTest extends NetCommonsControllerTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
if (! $this->_controller) {
$this->_controller = Inflector::singularize($this->plugin) . '_' . 'frame_settings';
}
parent::setUp();
}
/**
* ロールチェックdataProvider
*
* ### 戻り値
* - action: アクション名
* - method: リクエストメソッド(get or post or put)
* - expected: 期待するviewファイル
* - role: ロール名
* - exception: Exception
*
* @return array
*/
public function dataProviderRoleAccess() {
$data = array(
array('edit', 'get', 'edit', Role::ROOM_ROLE_KEY_CHIEF_EDITOR, false),
array('edit', 'get', 'edit', Role::ROOM_ROLE_KEY_EDITOR, 'ForbiddenException'),
array('edit', 'get', 'edit', Role::ROOM_ROLE_KEY_GENERAL_USER, 'ForbiddenException'),
array('edit', 'get', 'edit', Role::ROOM_ROLE_KEY_VISITOR, 'ForbiddenException'),
array('edit', 'get', 'edit', null, 'ForbiddenException'),
);
return $data;
}
/**
* アクセス許可テスト
*
* @param string $action アクション名
* @param string $method リクエストメソッド(get or post or put)
* @param string $expected 期待するviewファイル
* @param string $role ロール名
* @param string $exception Exception
* @dataProvider dataProviderRoleAccess
* @return void
*/
public function testAccessPermission($action, $method, $expected, $role, $exception) {
if ($exception) {
$this->setExpectedException($exception);
}
if (isset($role)) {
TestAuthGeneral::login($this, $role);
}
//アクション実行
$frameId = '6';
$url = array(
'plugin' => $this->plugin,
'controller' => $this->_controller,
'action' => $action,
'frame_id' => $frameId
);
$params = array(
'method' => $method,
'return' => 'view'
);
$this->testAction(NetCommonsUrl::actionUrl($url), $params);
//チェック
$this->assertTextEquals($this->controller->view, $expected);
//ログアウト
if (isset($role)) {
TestAuthGeneral::logout($this);
}
}
/**
* edit()のテスト
*
* @param string $method リクエストメソッド(get or post or put)
* @param array $data 登録データ
* @param bool $validationError バリデーションエラー
* @param null|string $exception Exceptions Error
* @dataProvider dataProviderEdit
* @return void
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function testEdit($method, $data = null, $validationError = false, $exception = null) {
if ($exception) {
$this->setExpectedException($exception);
}
//ログイン
TestAuthGeneral::login($this);
$frameId = '6';
if ($validationError) {
$data = Hash::insert($data, $validationError['field'], $validationError['value']);
}
//アクション実行
$url = NetCommonsUrl::actionUrl(array(
'plugin' => $this->plugin,
'controller' => $this->_controller,
'action' => 'edit',
'frame_id' => $frameId,
));
$params = array(
'method' => $method,
'return' => 'view',
'data' => $data
);
$this->testAction($url, $params);
//チェック
if ($exception) {
//ログアウト
TestAuthGeneral::logout($this);
return;
}
if (in_array($method, ['put', 'post'], true) && ! $validationError) {
$header = $this->controller->response->header();
$asserts = array(
array('method' => 'assertNotEmpty', 'value' => $header['Location'])
);
} else {
$asserts = array(
array(
'method' => 'assertInput', 'type' => 'form',
'name' => null, 'value' => $url
),
array(
'method' => 'assertInput', 'type' => 'input',
'name' => 'data[Frame][id]', 'value' => $frameId
),
array(
'method' => 'assertInput', 'type' => 'input',
'name' => 'data[Frame][key]', 'value' => 'frame_3'
),
);
//バリデーションエラー(エラー表示あり)
if ($validationError) {
if ($validationError['message']) {
array_push($asserts, array(
'method' => 'assertNotEmpty', 'value' => $this->controller->validationErrors
));
array_push($asserts, array(
'method' => 'assertTextContains', 'expected' => $validationError['message']
));
}
}
}
//チェック
$this->asserts($asserts, $this->view);
//ログアウト
TestAuthGeneral::logout($this);
}
}