* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('TextHelper', 'View/Helper');
/**
* TextHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class TextHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
$controller = null;
$this->View = new View($controller);
$this->Text = new TextHelper($this->View);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->View, $this->Text);
}
/**
* testAutoLink method
*
* @return void
*/
public function testAutoLink() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'Text with a partial www.cakephp.org URL and test@cakephp.org email address';
$result = $this->Text->autoLink($text);
$expected = 'Text with a partial www.cakephp.org URL and test@cakephp\.org email address';
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL http://www.cakephp.org';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org and some more text';
$expected = 'This is a test text with URL http://www.cakephp.org and some more text';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = "This is a test text with URL http://www.cakephp.org\tand some more text";
$expected = "This is a test text with URL http://www.cakephp.org\tand some more text";
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org(and some more text)';
$expected = 'This is a test text with URL http://www.cakephp.org(and some more text)';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL http://www.cakephp.org';
$result = $this->Text->autoLink($text, array('class' => 'link'));
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL http://www.cakephp.org';
$result = $this->Text->autoLink($text, array('class' => 'link', 'id' => 'MyLink'));
$this->assertEquals($expected, $result);
}
/**
* Test escaping for autoLink
*
* @return void
*/
public function testAutoLinkEscape() {
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a <b>test</b> text with URL http://www.cakephp.org';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL http://www.cakephp.org';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($expected, $result);
}
/**
* testAutoLinkUrls method
*
* @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 (www.cakephp.org)';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
$text = 'Text with a partial www.cakephp.org URL';
$expected = 'Text with a partial www.cakephp.org URL';
$result = $this->Text->autoLinkUrls($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = 'Text with a partial www.cakephp.org URL';
$expected = 'Text with a partial www.cakephp.org 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 WWW.cakephp.org URL';
$result = $this->Text->autoLinkUrls($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = 'Text with a partial WWW.cakephp.org © URL';
$expected = 'Text with a partial WWW.cakephp.org © 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 www.cot.ag/cuIb2Q 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 http://www.does--not--work.com 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 http://www.not--work.com and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
}
/**
* Test autoLinkUrls with the escape option.
*
* @return void
*/
public function testAutoLinkUrlsEscape() {
$text = 'Text with a partial link link';
$expected = 'Text with a partial link link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a partial link';
$expected = 'Text with a partial link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a partial link';
$expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => true));
$this->assertEquals($expected, $result);
}
/**
* testAutoLinkEmails method
*
* @return void
*/
public function testAutoLinkEmails() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with email@example.com address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = "Text with o'hare._-bob@example.com address";
$expected = 'Text with o'hare._-bob@example.com address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with email@example.com address';
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
$this->assertRegExp('#^' . $expected . '$#', $result);
}
/**
* test invalid email addresses.
*
* @return void
*/
public function testAutoLinkEmailInvalid() {
$result = $this->Text->autoLinkEmails('this is a myaddress@gmx-de test');
$expected = 'this is a myaddress@gmx-de test';
$this->assertEquals($expected, $result);
}
}