Text = new TextExtHelper(new View(null)); } public function testObject() { $this->assertTrue(is_a($this->Text, 'TextExtHelper')); } public function testAutoLinkEmails() { $text = 'Text with a url euro@euro.de and more'; $expected = 'Text with a url euro@euro.de and more'; $result = $this->Text->autoLinkEmails($text, array()); $this->assertEquals($result, $expected); $text = 'Text with a url euro@euro.de and more'; $expected = 'Text with a url euro@euro.de and more\''; $result = $this->Text->autoLinkEmails($text, array('obfuscate'=>true)); pr($text); echo $result; pr(h($result)); $this->assertNotEqual($result, $text); } public function testAutoLinkEmailsWithHtmlOrDangerousStrings() { $text = 'Text with a email euro@euro.de and more'; $expected = 'Text <i>with a email</i> euro@euro.de and more'; $result = $this->Text->autoLinkEmails($text); //pr(h($text)); $this->assertEquals($result, $expected); } public function testStripProtocol() { $urls = array( 'http://www.cakephp.org/bla/bla' => 'www.cakephp.org/bla/bla', 'www.cakephp.org' => 'www.cakephp.org' ); foreach ($urls as $url => $expected) { $is = $this->Text->stripProtocol($url); $this->assertEquals($is, $expected); } } public function testAutoLinkUrls() { $texts = array( 'text http://www.cakephp.org/bla/bla some more text' => '', 'This is a test text with URL http://www.cakephp.org\tand some more text' => 'This is a test text with URL http://www.cakephp.org\tand some more text' ); foreach ($texts as $text => $expected) { //$is = $this->Text->stripProtocol($url); //$this->assertEquals($is, $expected); } $text = 'Text with a url www.cot.ag/cuIb2Q/eruierieriu-erjekr and more'; $expected = 'Text with a url www.cot.ag/c... and more'; $result = $this->Text->autoLinkUrls($text, array('maxLength'=>12)); $this->assertEquals($result, $expected); $text = 'Text with a url http://www.cot.ag/cuIb2Q/eru and more'; $expected = 'Text with a url www.cot.ag/cuIb2Q/eru and more'; $result = $this->Text->autoLinkUrls($text, array('stripProtocol'=>true)); $this->assertEquals($result, $expected); $text = 'Text with a url http://www.cot.ag/cuIb2Q/eruierieriu-erjekr and more'; $expected = 'Text with a url http://www.cot.ag/cuIb2Q/eruierieriu-erjekr and more'; $result = $this->Text->autoLinkUrls($text, array('stripProtocol'=>false, 'maxLength'=>0)); $this->assertEquals($result, $expected); $text = 'Text with a url www.cot.ag/cuIb2Q/eruierieriu-erjekrwerweuwrweir-werwer-werwerwe-werwerwer-werwerdfrffsd-werwer and more'; $expected = 'Text with a url www.cot.ag/cuIb2Q/eruierieriu-erjekrwerweuwrweir-w... and more'; $result = $this->Text->autoLinkUrls($text); $this->assertEquals($result, $expected); } public function testAutoLinkUrlsWithEscapeFalse() { $text = 'Text with a url www.cot.ag/cuIb2Q/eruierieriu-erjekrwerweuwrweir-werwer and more'; $expected = 'Text with a url www.cot.ag/cuIb2Q/er... and more'; $result = $this->Text->autoLinkUrls($text, array('maxLength'=>20), array('escape'=>false)); $this->assertEquals($result, $expected); # not yet working /* $text = 'Text with a url www.cot.ag/cuIb2Q/eruierieriu-erjekrwerweuwrweir-werwer and more'; $expected = 'Text with a url www.cot.ag/cuIb2Q/er… and more'; $result = $this->Text->autoLinkUrls($text, array('maxLength'=>20), array('escape'=>false, 'html'=>true)); $this->assertEquals($result, $expected); */ $text = '

google

a http://maps.google.de/maps?f=d&source=s_d&saddr=m%C3%BCnchen&daddr=Berlin&hl=de&geocode=FXaL3gIdGrOwACnZX4yj-XWeRzF9mLF9SrgMAQ%3BFY1xIQMdSKTMACkBWQM_N06oRzFwO15bRiAhBA&mra=ls&sll=52.532932,13.41156&sspn=0.77021,2.348328&g=berlin&ie=UTF8&t=h&z=6 link'; $expected = '<h3>google<h3> a maps.google.de/maps?f=d&source... link'; $result = $this->Text->autoLinkUrls($text, array('maxLength'=>30)); $this->assertEquals($result, $expected); } public function testAutoLinkUrlsWithHtmlOrDangerousStrings() { $text = 'Text with a url www.cot.ag?id=2&sub=3 and more'; $expected = 'Text <i>with a url</i> www.cot.ag?id=2&sub=3 and more'; $result = $this->Text->autoLinkUrls($text); //pr(h($text)); $this->assertEquals($result, $expected); } /** * combined (emails + urls) * 2011-04-03 ms */ public function testAutoLink() { $text = 'Text with a url www.cot.ag?id=2&sub=3 and some email@domain.com more'; $expected = 'Text <i>with a url</i> www.cot.ag?id=2&sub=3 and some email@domain.com more'; $result = $this->Text->autoLink($text); pr(h($text)); $this->assertEquals($result, $expected); } /* from cake */ /** * 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); $result = $this->Text->autoLink('this is a myaddress@gmx-de test'); $expected = 'this is a myaddress@gmx-de test'; $this->assertEquals($expected, $result); } public function testAutoLinkUrlsWithCakeTests() { $text = 'This is a test text'; $expected = 'This is a test text'; $result = $this->Text->autoLinkUrls($text); $this->assertEquals($result, $expected); $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($result, $expected); $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(), 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), 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($result, $expected); } }