/** * Tests Text::autoLink() * * @test * @dataProvider provider_auto_link */ public function test_auto_link($text, $urls = array(), $emails = array()) { $linked_text = Text::autoLink($text); if ($urls === false) { $this->assertNotContains('http://', $linked_text); } elseif (count($urls)) { foreach ($urls as $url) { // Assert that all the urls have been caught by text autoLinkUrls() $this->assertContains(Text::autoLinkUrls($url), $linked_text); } } foreach ($emails as $email) { $this->assertContains('mailto:' . $email, $linked_text); } }
/** * Converts text email addresses and anchors into links. Existing links * will not be altered. * * echo Text::autoLink($text); * * [!!] This method is not foolproof since it uses regex to parse HTML. * * @param string $text text to auto link * @return string * @uses Text::autoLinkUrls * @uses Text::autoLinkEmails */ public static function autoLink($text) { // Auto link emails first to prevent problems with "*****@*****.**" return Text::autoLinkUrls(Text::autoLinkEmails($text)); }