Skip to content

Commit

Permalink
Add additional useful tests for autoLink()
Browse files Browse the repository at this point in the history
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 ebc1bcb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/Cake/Test/Case/View/Helper/TextHelperTest.php
Expand Up @@ -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));
Expand All @@ -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);
}

Expand Down

0 comments on commit ebc1bcb

Please sign in to comment.