Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reduce duplication in test case.

  • Loading branch information...
commit 8800d7bdec1a2a08999ca7932a3b830a0ec79c6d 1 parent b1dfab8
@markstory markstory authored
Showing with 69 additions and 58 deletions.
  1. +69 −58 lib/Cake/Test/Case/View/Helper/TextHelperTest.php
View
127 lib/Cake/Test/Case/View/Helper/TextHelperTest.php
@@ -166,80 +166,91 @@ public function testAutoLinkEscape() {
}
/**
+ * Data provider for autoLinking
+ */
+ public static function autoLinkProvider() {
+ return array(
+ array(
+ 'This is a test text',
+ 'This is a test text',
+ ),
+ array(
+ 'This is a test that includes (www.cakephp.org)',
+ 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)',
+ ),
+ array(
+ 'This is a test that includes www.cakephp.org:8080',
+ 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>',
+ ),
+ array(
+ 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
+ '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>',
+ ),
+ array(
+ 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
+ 'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
+ ),
+ array(
+ 'This is a test that includes http://example.com/test.php?foo=bar text',
+ 'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text',
+ ),
+ array(
+ 'This is a test that includes www.example.com/test.php?foo=bar text',
+ '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',
+ ),
+ array(
+ 'Text with a partial www.cakephp.org URL',
+ 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL',
+ ),
+ array(
+ 'Text with a partial WWW.cakephp.org URL',
+ 'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> URL',
+ ),
+ array(
+ 'Text with a partial WWW.cakephp.org &copy, URL',
+ 'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> &amp;copy, URL',
+ ),
+ array(
+ 'Text with a url www.cot.ag/cuIb2Q and more',
+ 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more',
+ ),
+ array(
+ 'Text with a url http://www.does--not--work.com and more',
+ 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more',
+ ),
+ array(
+ 'Text with a url http://www.not--work.com and more',
+ 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
+ ),
+ );
+ }
+
+/**
* testAutoLinkUrls method
*
+ * @dataProvider autoLinkProvider
* @return void
*/
- public function testAutoLinkUrls() {
- $text = 'This is a test text';
- $expected = 'This is a test text';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'This is a test that includes (www.cakephp.org)';
- $expected = 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'This is a test that includes www.cakephp.org:8080';
- $expected = 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>';
+ public function testAutoLinkUrls($text, $expected) {
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
+ }
- $text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
- $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>';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
- $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>';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'This is a test that includes http://example.com/test.php?foo=bar text';
- $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';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'This is a test that includes www.example.com/test.php?foo=bar text';
- $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';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'Text with a partial www.cakephp.org URL';
- $expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertRegExp('#^' . $expected . '$#', $result);
-
+/**
+ * Test the options for autoLinkUrls
+ *
+ * @return void
+ */
+ public function testAutoLinkUrlsOptions() {
$text = 'Text with a partial www.cakephp.org URL';
$expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
$result = $this->Text->autoLinkUrls($text, array('class' => 'link'));
$this->assertRegExp('#^' . $expected . '$#', $result);
- $text = 'Text with a partial WWW.cakephp.org URL';
- $expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertRegExp('#^' . $expected . '$#', $result);
-
$text = 'Text with a partial WWW.cakephp.org &copy; URL';
$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> &copy; URL';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertRegExp('#^' . $expected . '$#', $result);
-
- $text = 'Text with a url www.cot.ag/cuIb2Q and more';
- $expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'Text with a url http://www.does--not--work.com and more';
- $expected = 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
-
- $text = 'Text with a url http://www.not--work.com and more';
- $expected = 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more';
- $result = $this->Text->autoLinkUrls($text);
- $this->assertEquals($expected, $result);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.