-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLinkButtonTest.php
More file actions
221 lines (197 loc) · 5.2 KB
/
LinkButtonTest.php
File metadata and controls
221 lines (197 loc) · 5.2 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
<?php
/**
* BackToHelper::linkButton()のテスト
*
* @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('NetCommonsHelperTestCase', 'NetCommons.TestSuite');
/**
* BackToHelper::linkButton()のテスト
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\NetCommons\Test\Case\View\Helper\BackToHelper
*/
class BackToHelperLinkButtonTest extends NetCommonsHelperTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array();
/**
* Plugin name
*
* @var string
*/
public $plugin = 'net_commons';
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
//テストデータ生成
$viewVars = array();
$requestData = array();
//Helperロード
$this->loadHelper('NetCommons.BackTo', $viewVars, $requestData);
}
/**
* linkButton()のテスト(タイトルテスト)
*
* ### 戻り値
* - title タイトル
*
* @return array データ
*/
public function dataProviderTitle() {
return array(
array('title' => ''),
array('title' => 'Input Title')
);
}
/**
* linkButton()のテスト(タイトルテスト)
*
* @param string $title タイトル
* @dataProvider dataProviderTitle
* @return void
*/
public function testLinkButtonWithTitle($title) {
//データ生成
$url = array('action' => 'edit');
$options = array();
//テスト実施
$result = $this->BackTo->linkButton($title, $url, $options);
//チェック
$expected = '<a href="/edit" class="btn btn-default">' .
'<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> ' . $title .
'</a>';
$this->assertEquals($expected, $result);
}
/**
* linkButton()のテスト(アイコンテスト)
*
* ### 戻り値
* - icon タイトル
*
* @return array データ
*/
public function dataProviderIcon() {
return array(
array('icon' => null),
array('icon' => false),
array('icon' => 'edit')
);
}
/**
* linkButton()のテスト(アイコンテスト)
*
* @param string $icon アイコン
* @dataProvider dataProviderIcon
* @return void
*/
public function testLinkButtonWithIcon($icon) {
//データ生成
$title = '';
$url = array('action' => 'edit');
if (isset($icon)) {
$options = array('icon' => $icon);
} else {
$options = array();
$icon = 'remove';
}
//テスト実施
$result = $this->BackTo->linkButton($title, $url, $options);
//チェック
if ($icon) {
$expected = '<a href="/edit" class="btn btn-default"><span class="glyphicon glyphicon-' . $icon . '" aria-hidden="true"></span> </a>';
} else {
$expected = '<a href="/edit" class="btn btn-default"></a>';
}
$this->assertEquals($expected, $result);
}
/**
* linkButton()のテスト(iconSizeのテスト)のDataProvider
*
* ### 戻り値
* - iconSize タイトル
*
* @return array データ
*/
public function dataProviderIconSize() {
return array(
array('iconSize' => ''),
array('iconSize' => 'xs')
);
}
/**
* linkButton()のテスト(iconSizeのテスト)
*
* @param string $iconSize アイコンサイズ
* @dataProvider dataProviderIconSize
* @return void
*/
public function testLinkButtonWithIconSize($iconSize) {
//データ生成
$title = '';
$url = array('action' => 'edit');
if (isset($iconSize)) {
$options = array('iconSize' => $iconSize);
}
//テスト実施
$result = $this->BackTo->linkButton($title, $url, $options);
//チェック
if ($iconSize) {
$expectedIconSize = ' ' . 'btn-' . $iconSize;
} else {
$expectedIconSize = '';
}
$expected = '<a href="/edit" class="btn btn-default' . $expectedIconSize . '">' .
'<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> ' .
'</a>';
$this->assertEquals($expected, $result);
}
/**
* linkButton()のテスト(タイトルのエスケープテスト)のDataProvider
*
* ### 戻り値
* - title タイトル
* - escapeTitle タイトルをエスケープするか
* - expectedTitle 期待値のタイトル
*
* @return array データ
*/
public function dataProviderEscapeTitle() {
return array(
array('title' => '<Input Title>', 'escapeTitle' => true, '<Input Title>'),
array('title' => '<Input Title>', 'escapeTitle' => false, '<Input Title>')
);
}
/**
* linkButton()のテスト(タイトルのエスケープテスト)
*
* @param string $title タイトル
* @param bool $escapeTitle タイトルをエスケープするか
* @param string $expectedTitle 期待値のタイトル
* @dataProvider dataProviderEscapeTitle
* @return void
*/
public function testLinkButtonWithEscapeTitle($title, $escapeTitle, $expectedTitle) {
//データ生成
$url = array('action' => 'edit');
$options = array('escapeTitle' => $escapeTitle);
//テスト実施
$result = $this->BackTo->linkButton($title, $url, $options);
//チェック
$expected = '<a href="/edit" class="btn btn-default">' .
'<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> ' . $expectedTitle .
'</a>';
$this->assertEquals($expected, $result);
}
}