Skip to content

Commit 8800d7b

Browse files
committed
Reduce duplication in test case.
1 parent b1dfab8 commit 8800d7b

File tree

1 file changed

+69
-58
lines changed

1 file changed

+69
-58
lines changed

lib/Cake/Test/Case/View/Helper/TextHelperTest.php

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -165,81 +165,92 @@ public function testAutoLinkEscape() {
165165
$this->assertEquals($expected, $result);
166166
}
167167

168+
/**
169+
* Data provider for autoLinking
170+
*/
171+
public static function autoLinkProvider() {
172+
return array(
173+
array(
174+
'This is a test text',
175+
'This is a test text',
176+
),
177+
array(
178+
'This is a test that includes (www.cakephp.org)',
179+
'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)',
180+
),
181+
array(
182+
'This is a test that includes www.cakephp.org:8080',
183+
'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>',
184+
),
185+
array(
186+
'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
187+
'This is a test that includes <a href="http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
188+
),
189+
array(
190+
'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
191+
'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
192+
),
193+
array(
194+
'This is a test that includes http://example.com/test.php?foo=bar text',
195+
'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text',
196+
),
197+
array(
198+
'This is a test that includes www.example.com/test.php?foo=bar text',
199+
'This is a test that includes <a href="http://www.example.com/test.php?foo=bar">www.example.com/test.php?foo=bar</a> text',
200+
),
201+
array(
202+
'Text with a partial www.cakephp.org URL',
203+
'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL',
204+
),
205+
array(
206+
'Text with a partial WWW.cakephp.org URL',
207+
'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> URL',
208+
),
209+
array(
210+
'Text with a partial WWW.cakephp.org &copy, URL',
211+
'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> &amp;copy, URL',
212+
),
213+
array(
214+
'Text with a url www.cot.ag/cuIb2Q and more',
215+
'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more',
216+
),
217+
array(
218+
'Text with a url http://www.does--not--work.com and more',
219+
'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more',
220+
),
221+
array(
222+
'Text with a url http://www.not--work.com and more',
223+
'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
224+
),
225+
);
226+
}
227+
168228
/**
169229
* testAutoLinkUrls method
170230
*
231+
* @dataProvider autoLinkProvider
171232
* @return void
172233
*/
173-
public function testAutoLinkUrls() {
174-
$text = 'This is a test text';
175-
$expected = 'This is a test text';
176-
$result = $this->Text->autoLinkUrls($text);
177-
$this->assertEquals($expected, $result);
178-
179-
$text = 'This is a test that includes (www.cakephp.org)';
180-
$expected = 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)';
181-
$result = $this->Text->autoLinkUrls($text);
182-
$this->assertEquals($expected, $result);
183-
184-
$text = 'This is a test that includes www.cakephp.org:8080';
185-
$expected = 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>';
234+
public function testAutoLinkUrls($text, $expected) {
186235
$result = $this->Text->autoLinkUrls($text);
187236
$this->assertEquals($expected, $result);
237+
}
188238

189-
$text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
190-
$expected = 'This is a test that includes <a href="http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>';
191-
$result = $this->Text->autoLinkUrls($text);
192-
$this->assertEquals($expected, $result);
193-
194-
$text = 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
195-
$expected = 'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>';
196-
$result = $this->Text->autoLinkUrls($text);
197-
$this->assertEquals($expected, $result);
198-
199-
$text = 'This is a test that includes http://example.com/test.php?foo=bar text';
200-
$expected = 'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text';
201-
$result = $this->Text->autoLinkUrls($text);
202-
$this->assertEquals($expected, $result);
203-
204-
$text = 'This is a test that includes www.example.com/test.php?foo=bar text';
205-
$expected = 'This is a test that includes <a href="http://www.example.com/test.php?foo=bar">www.example.com/test.php?foo=bar</a> text';
206-
$result = $this->Text->autoLinkUrls($text);
207-
$this->assertEquals($expected, $result);
208-
209-
$text = 'Text with a partial www.cakephp.org URL';
210-
$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
211-
$result = $this->Text->autoLinkUrls($text);
212-
$this->assertRegExp('#^' . $expected . '$#', $result);
213-
239+
/**
240+
* Test the options for autoLinkUrls
241+
*
242+
* @return void
243+
*/
244+
public function testAutoLinkUrlsOptions() {
214245
$text = 'Text with a partial www.cakephp.org URL';
215246
$expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
216247
$result = $this->Text->autoLinkUrls($text, array('class' => 'link'));
217248
$this->assertRegExp('#^' . $expected . '$#', $result);
218249

219-
$text = 'Text with a partial WWW.cakephp.org URL';
220-
$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
221-
$result = $this->Text->autoLinkUrls($text);
222-
$this->assertRegExp('#^' . $expected . '$#', $result);
223-
224250
$text = 'Text with a partial WWW.cakephp.org &copy; URL';
225251
$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> &copy; URL';
226252
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
227253
$this->assertRegExp('#^' . $expected . '$#', $result);
228-
229-
$text = 'Text with a url www.cot.ag/cuIb2Q and more';
230-
$expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
231-
$result = $this->Text->autoLinkUrls($text);
232-
$this->assertEquals($expected, $result);
233-
234-
$text = 'Text with a url http://www.does--not--work.com and more';
235-
$expected = 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more';
236-
$result = $this->Text->autoLinkUrls($text);
237-
$this->assertEquals($expected, $result);
238-
239-
$text = 'Text with a url http://www.not--work.com and more';
240-
$expected = 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more';
241-
$result = $this->Text->autoLinkUrls($text);
242-
$this->assertEquals($expected, $result);
243254
}
244255

245256
/**

0 commit comments

Comments
 (0)