123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <?php
- class TheWireRegexTest extends ElggCoreUnitTest {
-
- public function __construct() {
- $this->ia = elgg_set_ignore_access(TRUE);
- parent::__construct();
-
- }
-
- public function setUp() {
- }
-
- public function tearDown() {
-
- $this->swallowErrors();
- }
-
- public function __destruct() {
- elgg_set_ignore_access($this->ia);
-
- parent::__destruct();
- }
-
- protected function getUserWireLink($username) {
- $url = "thewire/owner/$username";
- $url = elgg_normalize_url($url);
- return "<a href=\"$url\">@$username</a>";
- }
-
- protected function getHashtagLink($tag) {
- $url = "thewire/tag/$tag";
- $url = elgg_normalize_url($url);
- return "<a href=\"$url\">#$tag</a>";
- }
-
- protected function getEmailLink($address) {
- return "<a href=\"mailto:$address\">$address</a>";
- }
-
- protected function getLink($address) {
- return parse_urls($address);
- }
-
- public function testReplaceUsernames() {
-
- $text = "@user test";
- $expected = $this->getUserWireLink('user') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test @user test";
- $expected = "test " . $this->getUserWireLink('user') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test @user, test";
- $expected = "test " . $this->getUserWireLink('user') . ", test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
-
- $text = "test ,@user test";
- $expected = "test ," . $this->getUserWireLink('user') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "@3user test";
- $expected = $this->getUserWireLink('3user') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "@user_name test";
- $expected = $this->getUserWireLink('user_name') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test (@user) test";
- $expected = "test (" . $this->getUserWireLink('user') . ") test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "@tyúkanyó";
- $expected = $this->getUserWireLink('tyúkanyó');
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
- }
-
- public function testReplaceHashtags() {
-
- $text = "#tag test";
- $expected = $this->getHashtagLink('tag') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test #tag test";
- $expected = "test " . $this->getHashtagLink('tag') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test #tag, test";
- $expected = "test " . $this->getHashtagLink('tag') . ", test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test,#tag test";
- $expected = "test," . $this->getHashtagLink('tag') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test #tag. test";
- $expected = "test " . $this->getHashtagLink('tag') . ". test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test (#tag) test";
- $expected = "test (" . $this->getHashtagLink('tag') . ") test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test #tag2000 test";
- $expected = "test " . $this->getHashtagLink('tag2000') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test #1 test";
- $expected = $text;
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
- }
-
- public function testReplaceEmailAddress() {
-
- $text = "test@test.com test";
- $expected = $this->getEmailLink('test@test.com') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test test@test.com test";
- $expected = "test " . $this->getEmailLink('test@test.com') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test test@test.com, test";
- $expected = "test " . $this->getEmailLink('test@test.com') . ", test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test,test@test.com test";
- $expected = "test," . $this->getEmailLink('test@test.com') . " test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test test@test.com. test";
- $expected = "test " . $this->getEmailLink('test@test.com') . ". test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test (test@test.com) test";
- $expected = "test (" . $this->getEmailLink('test@test.com') . ") test";
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "user1@domain1.com";
- $expected = $this->getEmailLink('user1@domain1.com');
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "user_name@domain.com";
- $expected = $this->getEmailLink('user_name@domain.com');
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "user.name@domain.com";
- $expected = $this->getEmailLink('user.name@domain.com');
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "user.name@domain.com.uk";
- $expected = $this->getEmailLink('user.name@domain.com.uk');
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
- }
-
- public function testReplaceLinks() {
-
- $text = "http://www.test.org";
- $expected = $this->getLink('http://www.test.org');
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test http://www.test.org";
- $expected = 'test ' . $this->getLink('http://www.test.org');
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test http://www.test.org, test";
- $expected = 'test ' . $this->getLink('http://www.test.org') . ', test';
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test,http://www.test.org test";
- $expected = 'test,' . $this->getLink('http://www.test.org') . ' test';
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test http://www.test.org. test";
- $expected = 'test ' . $this->getLink('http://www.test.org') . '. test';
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test (http://www.test.org) test";
- $expected = 'test (' . $this->getLink('http://www.test.org') . ') test';
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
-
- $text = "test www.test.org test";
- $expected = 'test ' . $this->getLink('www.test.org') . ' test';
- $result = thewire_filter($text);
- $this->assertEqual($result, $expected);
- }
- }
|