-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBlocksControllerTest.php
More file actions
173 lines (144 loc) · 4.11 KB
/
BlocksControllerTest.php
File metadata and controls
173 lines (144 loc) · 4.11 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
<?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
*/
class BlocksControllerTest extends NetCommonsControllerTestCase {
/**
* Action name
*
* @var string
*/
protected $_action = 'index';
/**
* index()のテスト
*
* @return void
*/
public function testIndex() {
AuthGeneralTestSuite::login($this);
//アクション実行
$frameId = '6';
$this->_testNcAction(
array('frame_id' => $frameId)
);
$editUrl = $this->_getActionUrl(array('action' => 'edit'));
$this->assertRegExp('/<a href=".*?' . preg_quote($editUrl, '/') . '.*?".*?>/', $this->contents);
$this->assertRegExp(
'/<input.*?name="' . preg_quote('data[Frame][block_id]', '/') . '".*?>/', $this->contents
);
AuthGeneralTestSuite::logout($this);
}
/**
* index()のテスト
*
* @return void
*/
public function testIndexNoBlock() {
AuthGeneralTestSuite::login($this);
//アクション実行
$frameId = '18';
$this->_testNcAction(
array('frame_id' => $frameId)
);
//評価
$this->assertTextEquals('Blocks.Blocks/not_found', $this->controller->view);
AuthGeneralTestSuite::logout($this);
}
/**
* index()のログインなしテスト
*
* @return void
*/
public function testIndexWOLogin() {
$this->setExpectedException('ForbiddenException');
//アクション実行
$frameId = '6';
$this->_testNcAction(
array('frame_id' => $frameId)
);
}
/**
* index()のブロック編集権限なしテスト
*
* @return void
*/
public function testIndexWOBlockEditable() {
AuthGeneralTestSuite::login($this, Role::ROOM_ROLE_KEY_GENERAL_USER);
$this->testIndexWOLogin();
AuthGeneralTestSuite::logout($this);
}
/**
* index()の複数ページの最初のページテスト
*
* @return void
*/
public function testIndexFirstPageOnMultiplePages() {
AuthGeneralTestSuite::login($this);
//アクション実行
$frameId = '16';
$page = '1';
$this->_testNcAction(
array('frame_id' => $frameId)
);
//評価
$this->assertRegExp('/' . preg_quote('<ul class="pagination">', '/') . '/', $this->contents);
$this->assertNotRegExp('/<li><a.*?rel="first".*?<\/a><\/li>/', $this->contents);
$this->assertRegExp('/<li class="active"><a>' . $page . '<\/a><\/li>/', $this->contents);
$this->assertRegExp('/<li><a.*?rel="last".*?<\/a><\/li>/', $this->contents);
AuthGeneralTestSuite::logout($this);
}
/**
* index()の複数ページのテスト
*
* @return void
*/
public function testIndexOnMultiplePages() {
AuthGeneralTestSuite::login($this);
//アクション実行
$frameId = '16';
$page = '3';
$this->_testNcAction(
array('frame_id' => $frameId, 'page:' . $page)
);
//評価
$this->assertRegExp('/<ul class="pagination">/', $this->contents);
$this->assertRegExp('/<li><a.*?rel="first".*?<\/a><\/li>/', $this->contents);
$this->assertRegExp('/<li class="active"><a>' . $page . '<\/a><\/li>/', $this->contents);
$this->assertRegExp('/<li><a.*?rel="last".*?<\/a><\/li>/', $this->contents);
AuthGeneralTestSuite::logout($this);
}
/**
* index()の複数ページの最後のページテスト
*
* @return void
*/
public function testIndexLastPageOnMultiplePages() {
AuthGeneralTestSuite::login($this);
//アクション実行
$frameId = '16';
$page = '5';
$this->_testNcAction(
array('frame_id' => $frameId, 'page:' . $page)
);
//評価
$this->assertRegExp('/<ul class="pagination">/', $this->contents);
$this->assertRegExp('/<li><a.*?rel="first".*?<\/a><\/li>/', $this->contents);
$this->assertRegExp('/<li class="active"><a>' . $page . '<\/a><\/li>/', $this->contents);
$this->assertNotRegExp('/<li><a.*?rel="last".*?<\/a><\/li>/', $this->contents);
AuthGeneralTestSuite::logout($this);
}
}