-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLinkTest.php
More file actions
247 lines (212 loc) · 8.09 KB
/
LinkTest.php
File metadata and controls
247 lines (212 loc) · 8.09 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* NetCommonsHtmlHelper::link()のテスト
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @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');
/**
* NetCommonsHtmlHelper::link()のテスト
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @package NetCommons\NetCommons\Test\Case\View\Helper\NetCommonsHtmlHelper
*/
class NetCommonsHtmlHelperLinkTest extends NetCommonsHelperTestCase {
/**
* Plugin name
*
* @var string
*/
public $plugin = 'net_commons';
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->loadHelper('NetCommons.NetCommonsHtml');
}
/**
* testLink method
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testLink() {
Router::connect('/:controller/:action/*');
$this->NetCommonsHtml->request->webroot = '';
$result = $this->NetCommonsHtml->link('/home');
$expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link(array('action' => 'login', '<[You]>'));
$expected = array(
'a' => array('href' => '/login/%3C%5BYou%5D%3E'),
'preg:/\/login\/<\[You\]>/',
'/a'
);
$this->assertTags($result, $expected);
Router::reload();
//$result = $this->NetCommonsHtml->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true));
//$expected = array('a' => array('href' => Router::fullBaseUrl() . '/posts'), 'Posts', '/a');
//$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'if (confirm("Are you sure you want to do this?")) { return true; } return false;'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Home', '/home', array('escape' => false, 'confirm' => 'Confirm\'s "nightmares"'));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'if (confirm("Confirm's \"nightmares\"")) { return true; } return false;'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Home', '/home', array('default' => false));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Home', '/home', array('default' => false, 'onclick' => 'someFunction();'));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'someFunction(); event.returnValue = false; return false;'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Next >', '#');
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Next >', '#', array('escape' => true));
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Next >', '#', array('escape' => 'utf-8'));
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Next >', '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Next >', '#', array(
'title' => 'to escape … or not escape?',
'escape' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'to escape … or not escape?'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Next >', '#', array(
'title' => 'to escape … or not escape?',
'escape' => true
));
$expected = array(
'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Next >', '#', array(
'title' => 'Next >',
'escapeTitle' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'Next >'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('Original size', array(
'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
));
$expected = array(
'a' => array('href' => '/net_commons/images/view/3?height=100&width=200'),
'Original size',
'/a'
);
$this->assertTags($result, $expected);
Configure::write('Asset.timestamp', false);
$result = $this->NetCommonsHtml->link($this->NetCommonsHtml->image('test.gif'), '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link($this->NetCommonsHtml->image('test.gif'), '#', array(
'title' => 'hey "howdy"',
'escapeTitle' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'hey "howdy"'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->image('test.gif', array('url' => '#'));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link($this->NetCommonsHtml->image('../favicon.ico'), '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/../favicon.ico', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->image('../favicon.ico', array('url' => '#'));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/../favicon.ico', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('http://www.example.org?param1=value1¶m2=value2');
$expected = array('a' => array('href' => 'http://www.example.org?param1=value1&param2=value2'), 'http://www.example.org?param1=value1&param2=value2', '/a');
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('alert', 'javascript:alert(\'cakephp\');');
$expected = array('a' => array('href' => 'javascript:alert('cakephp');'), 'alert', '/a');
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('write me', 'mailto:example@cakephp.org');
$expected = array('a' => array('href' => 'mailto:example@cakephp.org'), 'write me', '/a');
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('call me on 0123465-798', 'tel:0123465-798');
$expected = array('a' => array('href' => 'tel:0123465-798'), 'call me on 0123465-798', '/a');
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('text me on 0123465-798', 'sms:0123465-798');
$expected = array('a' => array('href' => 'sms:0123465-798'), 'text me on 0123465-798', '/a');
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('say hello to 0123465-798', 'sms:0123465-798?body=hello there');
$expected = array('a' => array('href' => 'sms:0123465-798?body=hello there'), 'say hello to 0123465-798', '/a');
$this->assertTags($result, $expected);
$result = $this->NetCommonsHtml->link('say hello to 0123465-798', 'sms:0123465-798?body=hello "cakephp"');
$expected = array('a' => array('href' => 'sms:0123465-798?body=hello "cakephp"'), 'say hello to 0123465-798', '/a');
$this->assertTags($result, $expected);
}
}