Permalink
Browse files

Add additional useful tests for autoLink()

These new tests cover an important case that could easily be missed in
the future. Links with URL's should not be re-linked.

Refs #4998
  • Loading branch information...
markstory committed Oct 28, 2014
1 parent 5b32fd7 commit ebc1bcb624811ad41141ebe0298b2b4f0450e71f
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/Cake/Test/Case/View/Helper/TextHelperTest.php
@@ -314,6 +314,16 @@ public function testAutoLinkUrlsOptions() {
* @return void
*/
public function testAutoLinkUrlsEscape() {
+ $text = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
+ $expected = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
+ $result = $this->Text->autoLinkUrls($text, array('escape' => false));
+ $this->assertEquals($expected, $result);
+
+ $text = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
+ $expected = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
+ $result = $this->Text->autoLinkUrls($text, array('escape' => false));
+ $this->assertEquals($expected, $result);
+
$text = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$expected = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
@@ -331,22 +341,22 @@ public function testAutoLinkUrlsEscape() {
$text = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$expected = 'Text with a url &lt;a href=&quot;http://www.not-working-www.com&quot;&gt;www.not-working-www.com&lt;/a&gt; and more';
- $result = $this->Text->autoLinkUrls($text);
+ $result = $this->Text->autoLinkUrls($text, array('escape' => true));
$this->assertEquals($expected, $result);
$text = 'Text with a url www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
- $result = $this->Text->autoLinkUrls($text);
+ $result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a url http://www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">http://www.not-working-www.com</a> and more';
- $result = $this->Text->autoLinkUrls($text);
+ $result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a url http://www.www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.www.not-working-www.com">http://www.www.not-working-www.com</a> and more';
- $result = $this->Text->autoLinkUrls($text);
+ $result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
}

0 comments on commit ebc1bcb

Please sign in to comment.