1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TextTest4AutoUrlLink |
4
|
|
|
* |
5
|
|
|
* Text::AutoUrlLink用テストケース |
6
|
|
|
* |
7
|
|
|
* @package risoluto |
8
|
|
|
* @author Risoluto Developers |
9
|
|
|
* @license http://opensource.org/licenses/bsd-license.php new BSD license |
10
|
|
|
* @copyright (C) 2008-2015 Risoluto Developers / All Rights Reserved. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
//------------------------------------------------------// |
14
|
|
|
// 名前空間の定義 |
15
|
|
|
//------------------------------------------------------// |
16
|
|
|
namespace Risoluto; |
17
|
|
|
|
18
|
|
|
//------------------------------------------------------// |
19
|
|
|
// テストクラス定義 |
20
|
|
|
//------------------------------------------------------// |
21
|
|
|
class TextTest4AutoUrlLink extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
//------------------------------------------------------// |
24
|
|
|
// テストメソッド定義 |
25
|
|
|
//------------------------------------------------------// |
26
|
|
|
/** |
27
|
|
|
* setUp() |
28
|
|
|
* |
29
|
|
|
* テストに必要な準備を実施 |
30
|
|
|
*/ |
31
|
|
|
protected function setUp() |
32
|
|
|
{ |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* test_AutoUrlLink_WithNoLinks() |
37
|
|
|
* |
38
|
|
|
* autoUrlLink()の挙動をテストする(URLが含まれないテキストの場合) |
39
|
|
|
*/ |
40
|
|
|
public function test_AutoUrlLink_WithNoLinks() |
41
|
|
|
{ |
42
|
|
|
$test = '<p>Risoluto is PHP Framework.</p>'; |
43
|
|
|
$want = '<p>Risoluto is PHP Framework.</p>'; |
44
|
|
|
|
45
|
|
|
$this->assertEquals( Text::autoUrlLink( $test ), $want ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* test_AutoUrlLink_WithOneHttpLink() |
50
|
|
|
* |
51
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~)が1つだけ含まれるテキストの場合) |
52
|
|
|
*/ |
53
|
|
|
public function test_AutoUrlLink_WithOneHttpLink() |
54
|
|
|
{ |
55
|
|
|
$test = '<p>See: http://www.example.com/</p>'; |
56
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\' target=\'_blank\'>http://www.example.com/</a></p>'; |
57
|
|
|
|
58
|
|
|
$this->assertEquals( Text::autoUrlLink( $test ), $want ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* test_AutoUrlLink_WithOneHttpsLink() |
63
|
|
|
* |
64
|
|
|
* autoUrlLink()の挙動をテストする(URL(https://~)が1つだけ含まれるテキストの場合) |
65
|
|
|
*/ |
66
|
|
|
public function test_AutoUrlLink_WithOneHttpsLink() |
67
|
|
|
{ |
68
|
|
|
$test = '<p>See: https://www.example.com/</p>'; |
69
|
|
|
$want = '<p>See: <a href=\'https://www.example.com/\' target=\'_blank\'>https://www.example.com/</a></p>'; |
70
|
|
|
|
71
|
|
|
$this->assertEquals( Text::autoUrlLink( $test ), $want ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* test_AutoUrlLink_WithTwoHttpLinks() |
76
|
|
|
* |
77
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~)が2つ含まれるテキストの場合) |
78
|
|
|
*/ |
79
|
|
|
public function test_AutoUrlLink_WithTwoHttpLinks() |
80
|
|
|
{ |
81
|
|
|
$test = '<p>See: http://www.example.com/ and http://www.example.org/</p>'; |
82
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\' target=\'_blank\'>http://www.example.com/</a> and <a href=\'http://www.example.org/\' target=\'_blank\'>http://www.example.org/</a></p>'; |
83
|
|
|
|
84
|
|
|
$this->assertEquals( Text::autoUrlLink( $test ), $want ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* test_AutoUrlLink_WithTwoHttpsLinks() |
89
|
|
|
* |
90
|
|
|
* autoUrlLink()の挙動をテストする(URL(https://~)が2つ含まれるテキストの場合) |
91
|
|
|
*/ |
92
|
|
|
public function test_AutoUrlLink_WithTwoHttpsLinks() |
93
|
|
|
{ |
94
|
|
|
$test = '<p>See: https://www.example.com/ and https://www.example.org/</p>'; |
95
|
|
|
$want = '<p>See: <a href=\'https://www.example.com/\' target=\'_blank\'>https://www.example.com/</a> and <a href=\'https://www.example.org/\' target=\'_blank\'>https://www.example.org/</a></p>'; |
96
|
|
|
|
97
|
|
|
$this->assertEquals( Text::autoUrlLink( $test ), $want ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* test_AutoUrlLink_WithHttpAndHttpLinks() |
102
|
|
|
* |
103
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~とhttps://~)が2つ含まれるテキストの場合) |
104
|
|
|
*/ |
105
|
|
|
public function test_AutoUrlLink_WithHttpAndHttpLinks() |
106
|
|
|
{ |
107
|
|
|
$test = '<p>See: http://www.example.com/ and https://www.example.org/</p>'; |
108
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\' target=\'_blank\'>http://www.example.com/</a> and <a href=\'https://www.example.org/\' target=\'_blank\'>https://www.example.org/</a></p>'; |
109
|
|
|
|
110
|
|
|
$this->assertEquals( Text::autoUrlLink( $test ), $want ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* test_AutoUrlLink_WithNoLinks_WithoutNewWindow() |
115
|
|
|
* |
116
|
|
|
* autoUrlLink()の挙動をテストする(URLが含まれないテキストの場合、新規ウインドウモードOFF) |
117
|
|
|
*/ |
118
|
|
|
public function test_AutoUrlLink_WithNoLinks_WithoutNewWindow() |
119
|
|
|
{ |
120
|
|
|
$test = '<p>Risoluto is PHP Framework.</p>'; |
121
|
|
|
$want = '<p>Risoluto is PHP Framework.</p>'; |
122
|
|
|
|
123
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false ), $want ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow() |
128
|
|
|
* |
129
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF) |
130
|
|
|
*/ |
131
|
|
|
public function test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow() |
132
|
|
|
{ |
133
|
|
|
$test = '<p>See: http://www.example.com/</p>'; |
134
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\'>http://www.example.com/</a></p>'; |
135
|
|
|
|
136
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false ), $want ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow() |
141
|
|
|
* |
142
|
|
|
* autoUrlLink()の挙動をテストする(URL(https://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF) |
143
|
|
|
*/ |
144
|
|
|
public function test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow() |
145
|
|
|
{ |
146
|
|
|
$test = '<p>See: https://www.example.com/</p>'; |
147
|
|
|
$want = '<p>See: <a href=\'https://www.example.com/\'>https://www.example.com/</a></p>'; |
148
|
|
|
|
149
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false ), $want ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow() |
154
|
|
|
* |
155
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF) |
156
|
|
|
*/ |
157
|
|
|
public function test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow() |
158
|
|
|
{ |
159
|
|
|
$test = '<p>See: http://www.example.com/ and http://www.example.org/</p>'; |
160
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\'>http://www.example.com/</a> and <a href=\'http://www.example.org/\'>http://www.example.org/</a></p>'; |
161
|
|
|
|
162
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false ), $want ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow() |
167
|
|
|
* |
168
|
|
|
* autoUrlLink()の挙動をテストする(URL(https://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF) |
169
|
|
|
*/ |
170
|
|
|
public function test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow() |
171
|
|
|
{ |
172
|
|
|
$test = '<p>See: https://www.example.com/ and https://www.example.org/</p>'; |
173
|
|
|
$want = '<p>See: <a href=\'https://www.example.com/\'>https://www.example.com/</a> and <a href=\'https://www.example.org/\'>https://www.example.org/</a></p>'; |
174
|
|
|
|
175
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false ), $want ); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow() |
180
|
|
|
* |
181
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~とhttps://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF) |
182
|
|
|
*/ |
183
|
|
|
public function test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow() |
184
|
|
|
{ |
185
|
|
|
$test = '<p>See: http://www.example.com/ and https://www.example.org/</p>'; |
186
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\'>http://www.example.com/</a> and <a href=\'https://www.example.org/\'>https://www.example.org/</a></p>'; |
187
|
|
|
|
188
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false ), $want ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* test_AutoUrlLink_WithNoLinks_WithoutNewWindow_WithExtraAttr() |
193
|
|
|
* |
194
|
|
|
* autoUrlLink()の挙動をテストする(URLが含まれないテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
195
|
|
|
*/ |
196
|
|
View Code Duplication |
public function test_AutoUrlLink_WithNoLinks_WithoutNewWindow_WithExtraAttr() |
|
|
|
|
197
|
|
|
{ |
198
|
|
|
$test = '<p>Risoluto is PHP Framework.</p>'; |
199
|
|
|
$attr = 'class=\'dummy\''; |
200
|
|
|
$want = '<p>Risoluto is PHP Framework.</p>'; |
201
|
|
|
|
202
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false, $attr ), $want ); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow_WithExtraAttr() |
207
|
|
|
* |
208
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
209
|
|
|
*/ |
210
|
|
View Code Duplication |
public function test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow_WithExtraAttr() |
|
|
|
|
211
|
|
|
{ |
212
|
|
|
$test = '<p>See: http://www.example.com/</p>'; |
213
|
|
|
$attr = 'class=\'dummy\''; |
214
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\' class=\'dummy\'>http://www.example.com/</a></p>'; |
215
|
|
|
|
216
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false, $attr ), $want ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow_WithExtraAttr() |
221
|
|
|
* |
222
|
|
|
* autoUrlLink()の挙動をテストする(URL(https://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
223
|
|
|
*/ |
224
|
|
View Code Duplication |
public function test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow_WithExtraAttr() |
|
|
|
|
225
|
|
|
{ |
226
|
|
|
$test = '<p>See: https://www.example.com/</p>'; |
227
|
|
|
$attr = 'class=\'dummy\''; |
228
|
|
|
$want = '<p>See: <a href=\'https://www.example.com/\' class=\'dummy\'>https://www.example.com/</a></p>'; |
229
|
|
|
|
230
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false, $attr ), $want ); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow_WithExtraAttr() |
235
|
|
|
* |
236
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
237
|
|
|
*/ |
238
|
|
View Code Duplication |
public function test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow_WithExtraAttr() |
|
|
|
|
239
|
|
|
{ |
240
|
|
|
$test = '<p>See: http://www.example.com/ and http://www.example.org/</p>'; |
241
|
|
|
$attr = 'class=\'dummy\''; |
242
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\' class=\'dummy\'>http://www.example.com/</a> and <a href=\'http://www.example.org/\' class=\'dummy\'>http://www.example.org/</a></p>'; |
243
|
|
|
|
244
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false, $attr ), $want ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow_WithExtraAttr() |
249
|
|
|
* |
250
|
|
|
* autoUrlLink()の挙動をテストする(URL(https://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
251
|
|
|
*/ |
252
|
|
View Code Duplication |
public function test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow_WithExtraAttr() |
|
|
|
|
253
|
|
|
{ |
254
|
|
|
$test = '<p>See: https://www.example.com/ and https://www.example.org/</p>'; |
255
|
|
|
$attr = 'class=\'dummy\''; |
256
|
|
|
$want = '<p>See: <a href=\'https://www.example.com/\' class=\'dummy\'>https://www.example.com/</a> and <a href=\'https://www.example.org/\' class=\'dummy\'>https://www.example.org/</a></p>'; |
257
|
|
|
|
258
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false, $attr ), $want ); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow_WithExtraAttr() |
263
|
|
|
* |
264
|
|
|
* autoUrlLink()の挙動をテストする(URL(http://~とhttps://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
265
|
|
|
*/ |
266
|
|
View Code Duplication |
public function test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow_WithExtraAttr() |
|
|
|
|
267
|
|
|
{ |
268
|
|
|
$test = '<p>See: http://www.example.com/ and https://www.example.org/</p>'; |
269
|
|
|
$attr = 'class=\'dummy\''; |
270
|
|
|
$want = '<p>See: <a href=\'http://www.example.com/\' class=\'dummy\'>http://www.example.com/</a> and <a href=\'https://www.example.org/\' class=\'dummy\'>https://www.example.org/</a></p>'; |
271
|
|
|
|
272
|
|
|
$this->assertEquals( Text::autoUrlLink( $test, false, $attr ), $want ); |
273
|
|
|
} |
274
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.