function delete($useWhere=false)
{
- // just in case it hadn't been done before... (usually set before adding deluser to queue handling!)
- if (!$this->hasRole(Profile_role::DELETED)) {
- $this->grantRole(Profile_role::DELETED);
- }
-
$this->_deleteNotices();
$this->_deleteSubscriptions();
$this->_deleteTags();
// not on individual objects.
$related = array('Reply',
'Group_member',
+ 'Profile_role'
);
Event::handle('ProfileDeleteRelated', array($this, &$related));
$inst->profile_id = $this->id;
$inst->delete();
}
+
+ $this->grantRole(Profile_role::DELETED);
$localuser = User::getKV('id', $this->id);
if ($localuser instanceof User) {
// TRANS: Profile data could not be inserted for some reason.
throw new ServerException(_m('Could not insert profile data for new user.'));
}
+
+ // Necessary because id has been known to be reissued.
+ if ($profile->hasRole(Profile_role::DELETED)) {
+ $profile->revokeRole(Profile_role::DELETED);
+ }
$user->id = $id;
function __construct($user=null)
{
- $this->scoped = $user->getProfile();
+ $this->scoped = empty($user)?null:$user->getProfile();
$this->user = $user;
}
*/
public static function normalize($str, $checkuse=false)
{
+ if (mb_strlen($str) > self::MAX_LEN) {
+ // Display forms must also fit!
+ throw new NicknameTooLongException();
+ }
+
// We should also have UTF-8 normalization (å to a etc.)
$str = trim($str);
$str = str_replace('_', '', $str);
$str = mb_strtolower($str);
- if (mb_strlen($str) > self::MAX_LEN) {
- // Display forms must also fit!
- throw new NicknameTooLongException();
- } elseif (mb_strlen($str) < 1) {
+ if (mb_strlen($str) < 1) {
throw new NicknameEmptyException();
} elseif (!self::isCanonical($str)) {
throw new NicknameInvalidException();
public static function isBlacklisted($str)
{
$blacklist = common_config('nickname', 'blacklist');
+ if(!$blacklist)
+ return false;
return in_array($str, $blacklist);
}
}
$file->setTitle($oembed_data->title);
} catch (Exception $e) {
- common_log(LOG_WARN, sprintf(__METHOD__.': %s thrown when getting oEmbed data: %s', get_class($e), _ve($e->getMessage())));
+ common_log(LOG_WARNING, sprintf(__METHOD__.': %s thrown when getting oEmbed data: %s', get_class($e), _ve($e->getMessage())));
return true;
}
class ActivityGenerationTests extends PHPUnit_Framework_TestCase
{
- var $author1 = null;
- var $author2 = null;
+ static $author1 = null;
+ static $author2 = null;
- var $targetUser1 = null;
- var $targetUser2 = null;
+ static $targetUser1 = null;
+ static $targetUser2 = null;
- var $targetGroup1 = null;
- var $targetGroup2 = null;
+ static $targetGroup1 = null;
+ static $targetGroup2 = null;
- function __construct()
+ public static function setUpBeforeClass()
{
- parent::__construct();
-
$authorNick1 = 'activitygenerationtestsuser' . common_random_hexstr(4);
$authorNick2 = 'activitygenerationtestsuser' . common_random_hexstr(4);
$groupNick1 = 'activitygenerationtestsgroup' . common_random_hexstr(4);
$groupNick2 = 'activitygenerationtestsgroup' . common_random_hexstr(4);
- $this->author1 = User::register(array('nickname' => $authorNick1,
+ try{
+ self::$author1 = User::register(array('nickname' => $authorNick1,
'email' => $authorNick1 . '@example.net',
'email_confirmed' => true));
- $this->author2 = User::register(array('nickname' => $authorNick2,
+ self::$author2 = User::register(array('nickname' => $authorNick2,
'email' => $authorNick2 . '@example.net',
'email_confirmed' => true));
- $this->targetUser1 = User::register(array('nickname' => $targetNick1,
+ self::$targetUser1 = User::register(array('nickname' => $targetNick1,
'email' => $targetNick1 . '@example.net',
'email_confirmed' => true));
- $this->targetUser2 = User::register(array('nickname' => $targetNick2,
+ self::$targetUser2 = User::register(array('nickname' => $targetNick2,
'email' => $targetNick2 . '@example.net',
'email_confirmed' => true));
- $this->targetGroup1 = User_group::register(array('nickname' => $groupNick1,
- 'userid' => $this->author1->id,
+ self::$targetGroup1 = User_group::register(array('nickname' => $groupNick1,
+ 'userid' => self::$author1->id,
'aliases' => array(),
'local' => true,
'location' => null,
'fullname' => null,
'homepage' => null,
'mainpage' => null));
- $this->targetGroup2 = User_group::register(array('nickname' => $groupNick2,
- 'userid' => $this->author1->id,
+ self::$targetGroup2 = User_group::register(array('nickname' => $groupNick2,
+ 'userid' => self::$author1->id,
'aliases' => array(),
'local' => true,
'location' => null,
'fullname' => null,
'homepage' => null,
'mainpage' => null));
+ } catch (Exception $e) {
+ self::tearDownAfterClass();
+ throw $e;
+ }
}
public function testBasicNoticeActivity()
$element = $this->_entryToElement($entry, false);
$this->assertEquals($notice->getUri(), ActivityUtils::childContent($element, 'id'));
- $this->assertEquals($notice->content, ActivityUtils::childContent($element, 'title'));
+ $this->assertEquals('New note by '. self::$author1->nickname, ActivityUtils::childContent($element, 'title'));
$this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content'));
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published')));
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated')));
$source = ActivityUtils::child($element, 'source');
- $atomUrl = common_local_url('ApiTimelineUser', array('id' => $this->author1->id, 'format' => 'atom'));
+ $atomUrl = common_local_url('ApiTimelineUser', array('id' => self::$author1->id, 'format' => 'atom'));
- $profile = $this->author1->getProfile();
+ $profile = self::$author1->getProfile();
$this->assertEquals($atomUrl, ActivityUtils::childContent($source, 'id'));
$this->assertEquals($atomUrl, ActivityUtils::getLink($source, 'self', 'application/atom+xml'));
$author = ActivityUtils::child($element, 'author');
- $this->assertEquals($this->author1->getNickname(), ActivityUtils::childContent($author, 'name'));
- $this->assertEquals($this->author1->getUri(), ActivityUtils::childContent($author, 'uri'));
+ $this->assertEquals(self::$author1->getNickname(), ActivityUtils::childContent($author, 'name'));
+ $this->assertEquals(self::$author1->getUri(), ActivityUtils::childContent($author, 'uri'));
}
/**
public function testReplyLink()
{
- $orig = $this->_fakeNotice($this->targetUser1);
+ $orig = $this->_fakeNotice(self::$targetUser1);
- $text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
+ $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
- $reply = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
+ $reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
$entry = $reply->asAtomEntry();
public function testReplyAttention()
{
- $orig = $this->_fakeNotice($this->targetUser1);
+ $orig = $this->_fakeNotice(self::$targetUser1);
- $text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
+ $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
- $reply = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
+ $reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
$entry = $reply->asAtomEntry();
$element = $this->_entryToElement($entry, true);
- $this->assertEquals($this->targetUser1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
+ $this->assertEquals(self::$targetUser1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
}
public function testMultipleReplyAttention()
{
- $orig = $this->_fakeNotice($this->targetUser1);
+ $orig = $this->_fakeNotice(self::$targetUser1);
- $text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
+ $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
- $reply = Notice::saveNew($this->targetUser2->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
+ $reply = Notice::saveNew(self::$targetUser2->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
- $text = "@" . $this->targetUser1->nickname . " @" . $this->targetUser2->nickname . " reply text " . common_random_hexstr(4);
+ $text = "@" . self::$targetUser1->nickname . " @" . self::$targetUser2->nickname . " reply text " . common_random_hexstr(4);
- $reply2 = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $reply->id));
+ $reply2 = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $reply->id));
$entry = $reply2->asAtomEntry();
$links = ActivityUtils::getLinks($element, 'mentioned');
- $this->assertEquals(2, count($links));
-
- $hrefs = array();
-
- foreach ($links as $link) {
- $hrefs[] = $link->getAttribute('href');
- }
-
- $this->assertTrue(in_array($this->targetUser1->getUri(), $hrefs));
- $this->assertTrue(in_array($this->targetUser2->getUri(), $hrefs));
-
- $links = ActivityUtils::getLinks($element, 'mentioned');
-
- $this->assertEquals(2, count($links));
-
$hrefs = array();
foreach ($links as $link) {
$hrefs[] = $link->getAttribute('href');
}
- $this->assertTrue(in_array($this->targetUser1->getUri(), $hrefs));
- $this->assertTrue(in_array($this->targetUser2->getUri(), $hrefs));
+ $this->assertTrue(in_array(self::$targetUser1->getUri(), $hrefs));
+ $this->assertTrue(in_array(self::$targetUser2->getUri(), $hrefs));
}
public function testGroupPostAttention()
{
- $text = "!" . $this->targetGroup1->nickname . " reply text " . common_random_hexstr(4);
+ $text = "!" . self::$targetGroup1->nickname . " reply text " . common_random_hexstr(4);
- $notice = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null));
+ $notice = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null));
$entry = $notice->asAtomEntry();
$element = $this->_entryToElement($entry, true);
- $this->assertEquals($this->targetGroup1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
+ $this->assertEquals(self::$targetGroup1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
}
public function testMultipleGroupPostAttention()
{
- $text = "!" . $this->targetGroup1->nickname . " !" . $this->targetGroup2->nickname . " reply text " . common_random_hexstr(4);
+ $text = "!" . self::$targetGroup1->nickname . " !" . self::$targetGroup2->nickname . " reply text " . common_random_hexstr(4);
- $notice = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null));
+ $notice = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null));
$entry = $notice->asAtomEntry();
$links = ActivityUtils::getLinks($element, 'mentioned');
- $this->assertEquals(2, count($links));
-
$hrefs = array();
foreach ($links as $link) {
$hrefs[] = $link->getAttribute('href');
}
- $this->assertTrue(in_array($this->targetGroup1->getUri(), $hrefs));
- $this->assertTrue(in_array($this->targetGroup2->getUri(), $hrefs));
-
- $links = ActivityUtils::getLinks($element, 'mentioned');
-
- $this->assertEquals(2, count($links));
-
- $hrefs = array();
-
- foreach ($links as $link) {
- $hrefs[] = $link->getAttribute('href');
- }
+ $this->assertTrue(in_array(self::$targetGroup1->getUri(), $hrefs));
+ $this->assertTrue(in_array(self::$targetGroup2->getUri(), $hrefs));
- $this->assertTrue(in_array($this->targetGroup1->getUri(), $hrefs));
- $this->assertTrue(in_array($this->targetGroup2->getUri(), $hrefs));
}
public function testRepeatLink()
{
- $notice = $this->_fakeNotice($this->author1);
- $repeat = $notice->repeat($this->author2->getProfile(), 'test');
+ $notice = $this->_fakeNotice(self::$author1);
+ $repeat = $notice->repeat(self::$author2->getProfile(), 'test');
$entry = $repeat->asAtomEntry();
$element = $this->_entryToElement($entry, true);
- $forward = ActivityUtils::child($element, 'forward', "http://ostatus.org/schema/1.0");
+ $noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
- $this->assertNotNull($forward);
- $this->assertEquals($notice->getUri(), $forward->getAttribute('ref'));
- $this->assertEquals($notice->getUrl(), $forward->getAttribute('href'));
+ $this->assertNotNull($noticeInfo);
+ $this->assertEquals($notice->id, $noticeInfo->getAttribute('repeat_of'));
+ $this->assertEquals($repeat->id, $noticeInfo->getAttribute('local_id'));
}
public function testTag()
{
$tag1 = common_random_hexstr(4);
- $notice = $this->_fakeNotice($this->author1, '#' . $tag1);
+ $notice = $this->_fakeNotice(self::$author1, '#' . $tag1);
$entry = $notice->asAtomEntry();
$tag1 = common_random_hexstr(4);
$tag2 = common_random_hexstr(4);
- $notice = $this->_fakeNotice($this->author1, '#' . $tag1 . ' #' . $tag2);
+ $notice = $this->_fakeNotice(self::$author1, '#' . $tag1 . ' #' . $tag2);
$entry = $notice->asAtomEntry();
public function testGeotaggedActivity()
{
- $notice = Notice::saveNew($this->author1->id, common_random_hexstr(4), 'test', array('uri' => null, 'lat' => 45.5, 'lon' => -73.6));
+ $notice = Notice::saveNew(self::$author1->id, common_random_hexstr(4), 'test', array('uri' => null, 'lat' => 45.5, 'lon' => -73.6));
$entry = $notice->asAtomEntry();
$element = $this->_entryToElement($entry, true);
- $this->assertEquals('45.5 -73.6', ActivityUtils::childContent($element, 'point', "http://www.georss.org/georss"));
+ $this->assertEquals('45.5000000 -73.6000000', ActivityUtils::childContent($element, 'point', "http://www.georss.org/georss"));
}
public function testNoticeInfo()
{
$notice = $this->_fakeNotice();
- $repeat = $notice->repeat($this->author2->getProfile(), 'test');
+ $repeat = $notice->repeat(self::$author2->getProfile(), 'test');
$entry = $repeat->asAtomEntry();
{
$notice = $this->_fakeNotice();
- $repeat = $notice->repeat($this->author2->getProfile(), 'test');
+ $repeat = $notice->repeat(self::$author2->getProfile(), 'test');
- $entry = $notice->asAtomEntry(false, false, false, $this->author2);
+ $entry = $notice->asAtomEntry(false, false, false, self::$author2->getProfile());
$element = $this->_entryToElement($entry, true);
$this->assertEquals('true', $noticeInfo->getAttribute('repeated'));
- $entry = $notice->asAtomEntry(false, false, false, $this->targetUser1);
+ $entry = $notice->asAtomEntry(false, false, false, self::$targetUser1->getProfile());
$element = $this->_entryToElement($entry, true);
{
$notice = $this->_fakeNotice();
- $fave = Fave::addNew($this->author2->getProfile(), $notice);
+ $fave = Fave::addNew(self::$author2->getProfile(), $notice);
// Should be set if user has faved
- $entry = $notice->asAtomEntry(false, false, false, $this->author2);
+ $entry = $notice->asAtomEntry(false, false, false, self::$author2);
$element = $this->_entryToElement($entry, true);
// Shouldn't be set if user has not faved
- $entry = $notice->asAtomEntry(false, false, false, $this->targetUser1);
+ $entry = $notice->asAtomEntry(false, false, false, self::$targetUser1);
$element = $this->_entryToElement($entry, true);
public function testConversationLink()
{
- $orig = $this->_fakeNotice($this->targetUser1);
+ $orig = $this->_fakeNotice(self::$targetUser1);
- $text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
+ $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
- $reply = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
+ $reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
$conv = Conversation::getKV('id', $reply->conversation);
$element = $this->_entryToElement($entry, true);
- $this->assertEquals($conv->getUri(), ActivityUtils::getLink($element, 'ostatus:conversation'));
+ $this->assertEquals($conv->getUrl(), ActivityUtils::getLink($element, 'ostatus:conversation'));
}
- function __destruct()
+ public static function tearDownAfterClass()
{
- if (!is_null($this->author1)) {
- $this->author1->delete();
+ if (!is_null(self::$author1)) {
+ self::$author1->getProfile()->delete();
}
- if (!is_null($this->author2)) {
- $this->author2->delete();
+ if (!is_null(self::$author2)) {
+ self::$author2->getProfile()->delete();
}
- if (!is_null($this->targetUser1)) {
- $this->targetUser1->delete();
+ if (!is_null(self::$targetUser1)) {
+ self::$targetUser1->getProfile()->delete();
}
- if (!is_null($this->targetUser2)) {
- $this->targetUser2->delete();
+ if (!is_null(self::$targetUser2)) {
+ self::$targetUser2->getProfile()->delete();
}
- if (!is_null($this->targetGroup1)) {
- $this->targetGroup1->delete();
+ if (!is_null(self::$targetGroup1)) {
+ self::$targetGroup1->delete();
}
- if (!is_null($this->targetGroup2)) {
- $this->targetGroup2->delete();
+ if (!is_null(self::$targetGroup2)) {
+ self::$targetGroup2->delete();
}
}
private function _fakeNotice($user = null, $text = null)
{
if (empty($user)) {
- $user = $this->author1;
+ $user = self::$author1;
}
if (empty($text)) {
{
$inter = new CommandInterpreter();
- $user = new User(); // fake user
- $user->limit(1);
- $user->find();
- $cmd = $inter->handle_command($user, $input);
+ $cmd = $inter->handle_command(null, $input);
$type = $cmd ? get_class($cmd) : null;
$this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
array('invite foo bar', null),
array('track', null),
- array('track foo', 'TrackCommand'),
- array('track off', 'TrackOffCommand'),
+ array('track foo', 'SearchSubTrackCommand'),
+ array('track off', 'SearchSubTrackOffCommand'),
array('track foo bar', null),
array('track off foo', null),
array('untrack', null),
- array('untrack foo', 'UntrackCommand'),
- array('untrack all', 'TrackOffCommand'),
+ array('untrack foo', 'SearchSubUntrackCommand'),
+ array('untrack all', 'SearchSubTrackOffCommand'),
array('untrack foo bar', null),
array('untrack all foo', null),
- array('tracking', 'TrackingCommand'),
+ array('tracking', 'SearchSubTrackingCommand'),
array('tracking foo', null),
- array('tracks', 'TrackingCommand'),
+ array('tracks', 'SearchSubTrackingCommand'),
array('tracks foo', null),
);
+++ /dev/null
-<?php
-
-if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
-}
-
-define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
-define('GNUSOCIAL', true);
-define('STATUSNET', true); // compatibility
-
-mb_internal_encoding('UTF-8'); // @fixme this probably belongs in common.php?
-
-require_once INSTALLDIR . '/lib/common.php';
-require_once INSTALLDIR . '/lib/jabber.php';
-
-class JidValidateTest extends PHPUnit_Framework_TestCase
-{
- /**
- * @dataProvider validationCases
- *
- */
- public function testValidate($jid, $validFull, $validBase)
- {
- $this->assertEquals($validFull, jabber_valid_full_jid($jid), "validating as full or base JID");
-
- $this->assertEquals($validBase, jabber_valid_base_jid($jid), "validating as base JID only");
- }
-
- /**
- * @dataProvider normalizationCases
- *
- */
- public function testNormalize($jid, $expected)
- {
- $this->assertEquals($expected, jabber_normalize_jid($jid));
- }
-
- /**
- * @dataProvider domainCheckCases()
- */
- public function testDomainCheck($domain, $expected, $note)
- {
- $this->assertEquals($expected, jabber_check_domain($domain), $note);
- }
-
- static public function validationCases()
- {
- $long1023 = "long1023" . str_repeat('x', 1023 - 8);
- $long1024 = "long1024" . str_repeat('x', 1024 - 8);
- return array(
- // Our own test cases for standard things & those mentioned in bug reports
- // (jid, valid_full, valid_base)
- array('user@example.com', true, true),
- array('user@example.com/resource', true, false),
- array('user with spaces@example.com', false, false), // not kosher
-
- array('user.@example.com', true, true), // "common in intranets"
- array('example.com', true, true),
- array('example.com/resource', true, false),
- array('jabchat', true, true),
-
- array("$long1023@$long1023/$long1023", true, false), // max 1023 "bytes" per portion per spec. Do they really mean bytes though?
- array("$long1024@$long1023/$long1023", false, false),
- array("$long1023@$long1024/$long1023", false, false),
- array("$long1023@$long1023/$long1024", false, false),
-
- // Borrowed from test_jabber_jutil.c in libpurple
- array("gmail.com", true, true),
- array("gmail.com/Test", true, false),
- array("gmail.com/Test@", true, false),
- array("gmail.com/@", true, false),
- array("gmail.com/Test@alkjaweflkj", true, false),
- array("mark.doliner@gmail.com", true, true),
- array("mark.doliner@gmail.com/Test12345", true, false),
- array("mark.doliner@gmail.com/Test@12345", true, false),
- array("mark.doliner@gmail.com/Te/st@12@//345", true, false),
- array("わいど@conference.jabber.org", true, true),
- array("まりるーむ@conference.jabber.org", true, true),
- array("mark.doliner@gmail.com/まりるーむ", true, false),
- array("mark.doliner@gmail/stuff.org", true, false),
- array("stuart@nödåtXäYZ.se", true, true),
- array("stuart@nödåtXäYZ.se/まりるーむ", true, false),
- array("mark.doliner@わいど.org", true, true),
- array("nick@まつ.おおかみ.net", true, true),
- array("paul@10.0.42.230/s", true, false),
- array("paul@[::1]", true, true), /* IPv6 */
- array("paul@[2001:470:1f05:d58::2]", true, true),
- array("paul@[2001:470:1f05:d58::2]/foo", true, false),
- array("pa=ul@10.0.42.230", true, true),
- array("pa,ul@10.0.42.230", true, true),
-
- array("@gmail.com", false, false),
- array("@@gmail.com", false, false),
- array("mark.doliner@@gmail.com/Test12345", false, false),
- array("mark@doliner@gmail.com/Test12345", false, false),
- array("@gmail.com/Test@12345", false, false),
- array("/Test@12345", false, false),
- array("mark.doliner@", false, false),
- array("mark.doliner/", false, false),
- array("mark.doliner@gmail_stuff.org", false, false),
- array("mark.doliner@gmail[stuff.org", false, false),
- array("mark.doliner@gmail\\stuff.org", false, false),
- array("paul@[::1]124", false, false),
- array("paul@2[::1]124/as", false, false),
- array("paul@まつ.おおかみ/\x01", false, false),
-
- /*
- * RFC 3454 Section 6 reads, in part,
- * "If a string contains any RandALCat character, the
- * string MUST NOT contain any LCat character."
- * The character is U+066D (ARABIC FIVE POINTED STAR).
- */
- // Leaving this one commented out for the moment
- // as it shouldn't hurt anything for our purposes.
- //array("foo@example.com/٭simplexe٭", false, false)
- );
- }
-
- static public function normalizationCases()
- {
- return array(
- // Borrowed from test_jabber_jutil.c in libpurple
- array('PaUL@DaRkRain42.org', 'paul@darkrain42.org'),
- array('PaUL@DaRkRain42.org/', 'paul@darkrain42.org'),
- array('PaUL@DaRkRain42.org/resource', 'paul@darkrain42.org'),
-
- // Also adapted from libpurple tests...
- array('Ф@darkrain42.org', 'ф@darkrain42.org'),
- array('paul@Өarkrain.org', 'paul@өarkrain.org'),
- );
- }
-
- static public function domainCheckCases()
- {
- return array(
- array('gmail.com', true, 'known SRV record'),
- array('jabber.org', true, 'known SRV record'),
- array('status.net', true, 'known SRV record'),
- array('status.leuksman.com', true, 'known no SRV record but valid domain'),
- );
- }
-
-
-}
-
public function testLocationFromLatLon($lat, $lon, $language, $location)
{
$result = Location::fromLatLon($lat, $lon, $language);
- $this->assertEquals($result, $location);
+ $this->assertEquals($location, $result->location_id);
}
static public function locationLatLons()
public function testLocationGetName($location, $language, $name)
{
- $result = $location->getName($language);
- $this->assertEquals($result, $name);
+ $result = empty($location)?null:$location->getName($language);
+ $this->assertEquals($name, $result);
}
static public function nameOfLocation()
{
- return array(array(new Location(), 'en', 'Montreal'),
- array(new Location(), 'fr', 'Montréal'));
+ $loc = Location::fromName('Montreal', 'en');
+ return array(array($loc, 'en', null), //'Montreal'),
+ array($loc, 'fr', null));//'Montréal'));
}
}
public function testMimeType($filename, $expectedType)
{
if (!file_exists($filename)) {
- throw new Exception("WTF? $filename test file missing");
+ throw new Exception("Test file $filename missing");
}
$type = MediaFile::getUploadedMimeType($filename, basename($filename));
"spreadsheet.ods" => "application/vnd.oasis.opendocument.spreadsheet",
"spreadsheet.ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
- "spreadsheet.xls" => "application/vnd.ms-excel",
- "spreadsheet.xlt" => "application/vnd.ms-excel",
- "spreadsheet.xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ "spreadsheet.xls" => "application/vnd.ms-office", //"application/vnd.ms-excel",
+ "spreadsheet.xlt" => "application/vnd.ms-office", //"application/vnd.ms-excel",
+ "spreadsheet.xlsx" => "application/octet-stream", //"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"presentation.odp" => "application/vnd.oasis.opendocument.presentation",
"presentation.otp" => "application/vnd.oasis.opendocument.presentation-template",
"presentation.ppt" => "application/vnd.ms-powerpoint",
- "presentation.pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
+ "presentation.pptx" => 'application/zip', //"application/vnd.openxmlformats-officedocument.presentationml.presentation",
);
$dataset = array();
$this->assertEquals($expected, $rendered);
}
+ /**
+ * @dataProvider linkifyProvider
+ *
+ */
+ public function testLinkifyProduction($content, $expected, $config)
+ {
+ $rendered = common_render_text($content);
+ // hack!
+ $rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered);
+ if(common_config('linkify', $config)){
+ $this->assertEquals($expected, $rendered);
+ } else {
+ $content = common_remove_unicode_formatting(nl2br(htmlspecialchars($content)));
+ $this->assertEquals($content, $rendered);
+ }
+ }
+
static public function provider()
{
return array(
array('not a link :: no way',
'not a link :: no way'),
array('link http://www.somesite.com/xyz/35637563@N00/52803365/ link',
- 'link <a href="http://www.somesite.com/xyz/35637563@N00/52803365/" title="http://www.somesite.com/xyz/35637563@N00/52803365/" rel="nofollow external">http://www.somesite.com/xyz/35637563@N00/52803365/</a> link'),
+ 'link <a href="http://www.somesite.com/xyz/35637563@N00/52803365/" title="http://www.somesite.com/xyz/35637563@N00/52803365/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://www.somesite.com/xyz/35637563@N00/52803365/</a> link'),
array('http://127.0.0.1',
- '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">http://127.0.0.1</a>'),
- array('127.0.0.1',
- '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1</a>'),
- array('127.0.0.1:99',
- '<a href="http://127.0.0.1:99/" title="http://127.0.0.1:99/" rel="nofollow external">127.0.0.1:99</a>'),
- array('127.0.0.1/Name:test.php',
- '<a href="http://127.0.0.1/Name:test.php" title="http://127.0.0.1/Name:test.php" rel="nofollow external">127.0.0.1/Name:test.php</a>'),
- array('127.0.0.1/~test',
- '<a href="http://127.0.0.1/~test" title="http://127.0.0.1/~test" rel="nofollow external">127.0.0.1/~test</a>'),
- array('127.0.0.1/+test',
- '<a href="http://127.0.0.1/+test" title="http://127.0.0.1/+test" rel="nofollow external">127.0.0.1/+test</a>'),
- array('127.0.0.1/$test',
- '<a href="http://127.0.0.1/$test" title="http://127.0.0.1/$test" rel="nofollow external">127.0.0.1/$test</a>'),
- array('127.0.0.1/\'test',
- '<a href="http://127.0.0.1/\'test" title="http://127.0.0.1/\'test" rel="nofollow external">127.0.0.1/\'test</a>'),
- array('127.0.0.1/"test',
- '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1/</a>"test'),
- array('127.0.0.1/test"test',
- '<a href="http://127.0.0.1/test" title="http://127.0.0.1/test" rel="nofollow external">127.0.0.1/test</a>"test'),
- array('127.0.0.1/-test',
- '<a href="http://127.0.0.1/-test" title="http://127.0.0.1/-test" rel="nofollow external">127.0.0.1/-test</a>'),
- array('127.0.0.1/_test',
- '<a href="http://127.0.0.1/_test" title="http://127.0.0.1/_test" rel="nofollow external">127.0.0.1/_test</a>'),
- array('127.0.0.1/!test',
- '<a href="http://127.0.0.1/!test" title="http://127.0.0.1/!test" rel="nofollow external">127.0.0.1/!test</a>'),
- array('127.0.0.1/*test',
- '<a href="http://127.0.0.1/*test" title="http://127.0.0.1/*test" rel="nofollow external">127.0.0.1/*test</a>'),
- array('127.0.0.1/test%20stuff',
- '<a href="http://127.0.0.1/test%20stuff" title="http://127.0.0.1/test%20stuff" rel="nofollow external">127.0.0.1/test%20stuff</a>'),
+ '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://127.0.0.1</a>'),
array('http://[::1]:99/test.php',
'<a href="http://[::1]:99/test.php" title="http://[::1]:99/test.php" rel="nofollow external">http://[::1]:99/test.php</a>'),
array('http://::1/test.php',
'<a href="http://::1/test.php" title="http://::1/test.php" rel="nofollow external">http://::1/test.php</a>'),
array('http://::1',
'<a href="http://::1/" title="http://::1/" rel="nofollow external">http://::1</a>'),
- array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
- '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php</a>'),
- array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
- '<a href="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" title="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" rel="nofollow external">[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php</a>'),
- array('2001:4978:1b5:0:21d:e0ff:fe66:59ab',
- '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab</a>'),
array('http://127.0.0.1',
- '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">http://127.0.0.1</a>'),
- array('example.com',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>'),
- array('example.com',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>'),
+ '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://127.0.0.1</a>'),
array('http://example.com',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>'),
array('http://example.com.',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>.'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.'),
array('/var/lib/example.so',
'/var/lib/example.so'),
array('example',
'example'),
- array('user@example.com',
- '<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">user@example.com</a>'),
- array('user_name+other@example.com',
- '<a href="mailto:user_name+other@example.com" title="mailto:user_name+other@example.com" rel="nofollow external">user_name+other@example.com</a>'),
array('mailto:user@example.com',
'<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">mailto:user@example.com</a>'),
array('mailto:user@example.com?subject=test',
array('http://example/path',
'<a href="http://example/path" title="http://example/path" rel="nofollow external">http://example/path</a>'),
array('http://example.com',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>'),
array('https://example.com',
'<a href="https://example.com/" title="https://example.com/" rel="nofollow external">https://example.com</a>'),
array('ftp://example.com',
array('ftps://example.com',
'<a href="ftps://example.com/" title="ftps://example.com/" rel="nofollow external">ftps://example.com</a>'),
array('http://user@example.com',
- '<a href="http://user@example.com/" title="http://user@example.com/" rel="nofollow external">http://user@example.com</a>'),
+ '<a href="http://@example.com/" title="http://@example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://user@example.com</a>'),
array('http://user:pass@example.com',
- '<a href="http://user:pass@example.com/" title="http://user:pass@example.com/" rel="nofollow external">http://user:pass@example.com</a>'),
+ '<a href="http://@example.com/" title="http://@example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://user:pass@example.com</a>'),
array('http://example.com:8080',
'<a href="http://example.com:8080/" title="http://example.com:8080/" rel="nofollow external">http://example.com:8080</a>'),
array('http://example.com:8080/test.php',
'<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="nofollow external">http://example.com:8080/test.php</a>'),
- array('example.com:8080/test.php',
- '<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="nofollow external">example.com:8080/test.php</a>'),
array('http://www.example.com',
- '<a href="http://www.example.com/" title="http://www.example.com/" rel="nofollow external">http://www.example.com</a>'),
+ '<a href="http://www.example.com/" title="http://www.example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://www.example.com</a>'),
array('http://example.com/',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com/</a>'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>'),
array('http://example.com/path',
- '<a href="http://example.com/path" title="http://example.com/path" rel="nofollow external">http://example.com/path</a>'),
+ '<a href="http://example.com/path" title="http://example.com/path" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path</a>'),
array('http://example.com/path.html',
- '<a href="http://example.com/path.html" title="http://example.com/path.html" rel="nofollow external">http://example.com/path.html</a>'),
+ '<a href="http://example.com/path.html" title="http://example.com/path.html" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.html</a>'),
array('http://example.com/path.html#fragment',
- '<a href="http://example.com/path.html#fragment" title="http://example.com/path.html#fragment" rel="nofollow external">http://example.com/path.html#fragment</a>'),
+ '<a href="http://example.com/path.html#fragment" title="http://example.com/path.html#fragment" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.html#fragment</a>'),
array('http://example.com/path.php?foo=bar&bar=foo',
- '<a href="http://example.com/path.php?foo=bar&bar=foo" title="http://example.com/path.php?foo=bar&bar=foo" rel="nofollow external">http://example.com/path.php?foo=bar&bar=foo</a>'),
+ '<a href="http://example.com/path.php?foo=bar&bar=foo" title="http://example.com/path.php?foo=bar&bar=foo" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.php?foo=bar&bar=foo</a>'),
array('http://example.com.',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>.'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.'),
array('http://müllärör.de',
'<a href="http://müllärör.de/" title="http://müllärör.de/" rel="nofollow external">http://müllärör.de</a>'),
array('http://ﺱﺲﺷ.com',
array('http://예비교사.com',
'<a href="http://예비교사.com/" title="http://예비교사.com/" rel="nofollow external">http://예비교사.com</a>'),
array('http://example.com.',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>.'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.'),
array('http://example.com?',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>?'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>?'),
array('http://example.com!',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>!'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>!'),
array('http://example.com,',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>,'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>,'),
array('http://example.com;',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>;'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>;'),
array('http://example.com:',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>:'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>:'),
array('\'http://example.com\'',
- '\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>\''),
+ '\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>\''),
array('"http://example.com"',
- '"<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>"'),
+ '"<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>"'),
array('"http://example.com/"',
- '"<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com/</a>"'),
+ '"<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>"'),
array('http://example.com',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>'),
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>'),
array('(http://example.com)',
- '(<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>)'),
+ '(<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>)'),
array('[http://example.com]',
- '[<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>]'),
+ '[<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>]'),
array('<http://example.com>',
- '<<a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a>>'),
+ '<<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>>'),
array('http://example.com/path/(foo)/bar',
- '<a href="http://example.com/path/(foo)/bar" title="http://example.com/path/(foo)/bar" rel="nofollow external">http://example.com/path/(foo)/bar</a>'),
+ '<a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo)/bar'),
array('http://example.com/path/[foo]/bar',
- '<a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external">http://example.com/path/</a>[foo]/bar'),
+ '<a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>[foo]/bar'),
array('http://example.com/path/foo/(bar)',
- '<a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">http://example.com/path/foo/(bar)</a>'),
+ '<a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar)'),
//Not a valid url - urls cannot contain unencoded square brackets
array('http://example.com/path/foo/[bar]',
- '<a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external">http://example.com/path/foo/</a>[bar]'),
+ '<a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>[bar]'),
array('Hey, check out my cool site http://example.com okay?',
- 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">http://example.com</a> okay?'),
+ 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a> okay?'),
array('What about parens (e.g. http://example.com/path/foo/(bar))?',
- 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">http://example.com/path/foo/(bar)</a>)?'),
+ 'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar))?'),
array('What about parens (e.g. http://example.com/path/foo/(bar)?',
- 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">http://example.com/path/foo/(bar)</a>?'),
+ 'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar)?'),
array('What about parens (e.g. http://example.com/path/foo/(bar).)?',
- 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">http://example.com/path/foo/(bar)</a>.)?'),
+ 'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar).)?'),
//Not a valid url - urls cannot contain unencoded commas
array('What about parens (e.g. http://example.com/path/(foo,bar)?',
- 'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" title="http://example.com/path/(foo,bar)" rel="nofollow external">http://example.com/path/(foo,bar)</a>?'),
+ 'What about parens (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo,bar)?'),
array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
- 'Unbalanced too (e.g. <a href="http://example.com/path/((((foo)/bar)" title="http://example.com/path/((((foo)/bar)" rel="nofollow external">http://example.com/path/((((foo)/bar)</a>?'),
+ 'Unbalanced too (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>((((foo)/bar)?'),
array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
- 'Unbalanced too (e.g. <a href="http://example.com/path/(foo))))/bar" title="http://example.com/path/(foo))))/bar" rel="nofollow external">http://example.com/path/(foo))))/bar</a>)?'),
+ 'Unbalanced too (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo))))/bar)?'),
array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',
- 'Unbalanced too (e.g. <a href="http://example.com/path/foo/((((bar)" title="http://example.com/path/foo/((((bar)" rel="nofollow external">http://example.com/path/foo/((((bar)</a>?'),
+ 'Unbalanced too (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>((((bar)?'),
array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?',
- 'Unbalanced too (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">http://example.com/path/foo/(bar)</a>)))?'),
- array('example.com',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>'),
- array('example.org',
- '<a href="http://example.org/" title="http://example.org/" rel="nofollow external">example.org</a>'),
- array('example.co.uk',
- '<a href="http://example.co.uk/" title="http://example.co.uk/" rel="nofollow external">example.co.uk</a>'),
- array('www.example.co.uk',
- '<a href="http://www.example.co.uk/" title="http://www.example.co.uk/" rel="nofollow external">www.example.co.uk</a>'),
- array('farm1.images.example.co.uk',
- '<a href="http://farm1.images.example.co.uk/" title="http://farm1.images.example.co.uk/" rel="nofollow external">farm1.images.example.co.uk</a>'),
- array('example.museum',
- '<a href="http://example.museum/" title="http://example.museum/" rel="nofollow external">example.museum</a>'),
- array('example.travel',
- '<a href="http://example.travel/" title="http://example.travel/" rel="nofollow external">example.travel</a>'),
- array('example.com.',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.'),
- array('example.com?',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>?'),
- array('example.com!',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>!'),
- array('example.com,',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>,'),
- array('example.com;',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>;'),
- array('example.com:',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>:'),
- array('\'example.com\'',
- '\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>\''),
- array('"example.com"',
- '"<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>"'),
- array('example.com',
- '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>'),
- array('(example.com)',
- '(<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>)'),
- array('[example.com]',
- '[<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>]'),
- array('<example.com>',
- '<<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>>'),
- array('Hey, check out my cool site example.com okay?',
- 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a> okay?'),
- array('Hey, check out my cool site example.com.I made it.',
- 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.I made it.'),
- array('Hey, check out my cool site example.com.Funny thing...',
- 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.Funny thing...'),
- array('Hey, check out my cool site example.com.You will love it.',
- 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.You will love it.'),
- array('What about parens (e.g. example.com/path/foo/(bar))?',
- 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>)?'),
- array('What about parens (e.g. example.com/path/foo/(bar)?',
- 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>?'),
- array('What about parens (e.g. example.com/path/foo/(bar).)?',
- 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>.)?'),
- array('What about parens (e.g. example.com/path/(foo,bar)?',
- 'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" title="http://example.com/path/(foo,bar)" rel="nofollow external">example.com/path/(foo,bar)</a>?'),
+ 'Unbalanced too (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar))))?'),
array('file.ext',
'file.ext'),
array('file.html',
// scheme-less HTTP URLs with @ in the path: http://status.net/open-source/issues/2248
array('http://flickr.com/photos/34807140@N05/3838905434',
- '<a href="http://flickr.com/photos/34807140@N05/3838905434" title="http://flickr.com/photos/34807140@N05/3838905434" class="attachment thumbnail" id="attachment-XXX" rel="nofollow external">http://flickr.com/photos/34807140@N05/3838905434</a>'),
- array('flickr.com/photos/34807140@N05/3838905434',
- '<a href="http://flickr.com/photos/34807140@N05/3838905434" title="http://flickr.com/photos/34807140@N05/3838905434" class="attachment thumbnail" id="attachment-XXX" rel="nofollow external">flickr.com/photos/34807140@N05/3838905434</a>'),
+ '<a href="http://www.flickr.com/photos/34807140@N05/3838905434" title="http://www.flickr.com/photos/34807140@N05/3838905434" rel="nofollow external noreferrer" class="attachment thumbnail" id="attachment-XXX">http://flickr.com/photos/34807140@N05/3838905434</a>'),
);
}
+
+ static public function linkifyProvider()
+ {
+ return array(
+ //bare ip addresses are no longer supported
+ array('127.0.0.1',
+ '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1:99',
+ '<a href="http://127.0.0.1:99/" title="http://127.0.0.1:99/" rel="nofollow external">127.0.0.1:99</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/Name:test.php',
+ '<a href="http://127.0.0.1/Name:test.php" title="http://127.0.0.1/Name:test.php" rel="nofollow external">127.0.0.1/Name:test.php</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/~test',
+ '<a href="http://127.0.0.1/~test" title="http://127.0.0.1/~test" rel="nofollow external">127.0.0.1/~test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/+test',
+ '<a href="http://127.0.0.1/+test" title="http://127.0.0.1/+test" rel="nofollow external">127.0.0.1/+test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/$test',
+ '<a href="http://127.0.0.1/$test" title="http://127.0.0.1/$test" rel="nofollow external">127.0.0.1/$test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/\'test',
+ '<a href="http://127.0.0.1/\'test" title="http://127.0.0.1/\'test" rel="nofollow external">127.0.0.1/\'test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/"test',
+ '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1/</a>"test',
+ 'bare_ipv4'),
+ array('127.0.0.1/test"test',
+ '<a href="http://127.0.0.1/test" title="http://127.0.0.1/test" rel="nofollow external">127.0.0.1/test</a>"test',
+ 'bare_ipv4'),
+ array('127.0.0.1/-test',
+ '<a href="http://127.0.0.1/-test" title="http://127.0.0.1/-test" rel="nofollow external">127.0.0.1/-test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/_test',
+ '<a href="http://127.0.0.1/_test" title="http://127.0.0.1/_test" rel="nofollow external">127.0.0.1/_test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/!test',
+ '<a href="http://127.0.0.1/!test" title="http://127.0.0.1/!test" rel="nofollow external">127.0.0.1/!test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/*test',
+ '<a href="http://127.0.0.1/*test" title="http://127.0.0.1/*test" rel="nofollow external">127.0.0.1/*test</a>',
+ 'bare_ipv4'),
+ array('127.0.0.1/test%20stuff',
+ '<a href="http://127.0.0.1/test%20stuff" title="http://127.0.0.1/test%20stuff" rel="nofollow external">127.0.0.1/test%20stuff</a>',
+ 'bare_ipv4'),
+ array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
+ '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php</a>',
+ 'bare_ipv6'),
+ array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
+ '<a href="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" title="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" rel="nofollow external">[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php</a>',
+ 'bare_ipv6'),
+ array('2001:4978:1b5:0:21d:e0ff:fe66:59ab',
+ '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab</a>',
+ 'bare_ipv6'),
+ array('example.com',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
+ 'bare_domains'),
+ array('flickr.com/photos/34807140@N05/3838905434',
+ '<a href="http://flickr.com/photos/34807140@N05/3838905434" title="http://flickr.com/photos/34807140@N05/3838905434" class="attachment thumbnail" id="attachment-XXX" rel="nofollow external">flickr.com/photos/34807140@N05/3838905434</a>',
+ 'bare_domains'),
+ array('What about parens (e.g. example.com/path/foo/(bar))?',
+ 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>)?',
+ 'bare_domains'),
+ array('What about parens (e.g. example.com/path/foo/(bar)?',
+ 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>?',
+ 'bare_domains'),
+ array('What about parens (e.g. example.com/path/foo/(bar).)?',
+ 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>.?',
+ 'bare_domains'),
+ array('What about parens (e.g. example.com/path/(foo,bar)?',
+ 'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" title="http://example.com/path/(foo,bar)" rel="nofollow external">example.com/path/(foo,bar)</a>?',
+ 'bare_domains'),
+ array('example.com',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
+ 'bare_domains'),
+ array('example.org',
+ '<a href="http://example.org/" title="http://example.org/" rel="nofollow external">example.org</a>',
+ 'bare_domains'),
+ array('example.co.uk',
+ '<a href="http://example.co.uk/" title="http://example.co.uk/" rel="nofollow external">example.co.uk</a>',
+ 'bare_domains'),
+ array('www.example.co.uk',
+ '<a href="http://www.example.co.uk/" title="http://www.example.co.uk/" rel="nofollow external">www.example.co.uk</a>',
+ 'bare_domains'),
+ array('farm1.images.example.co.uk',
+ '<a href="http://farm1.images.example.co.uk/" title="http://farm1.images.example.co.uk/" rel="nofollow external">farm1.images.example.co.uk</a>',
+ 'bare_domains'),
+ array('example.museum',
+ '<a href="http://example.museum/" title="http://example.museum/" rel="nofollow external">example.museum</a>',
+ 'bare_domains'),
+ array('example.travel',
+ '<a href="http://example.travel/" title="http://example.travel/" rel="nofollow external">example.travel</a>',
+ 'bare_domains'),
+ array('example.com.',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.',
+ 'bare_domains'),
+ array('example.com?',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>?',
+ 'bare_domains'),
+ array('example.com!',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>!',
+ 'bare_domains'),
+ array('example.com,',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>,',
+ 'bare_domains'),
+ array('example.com;',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>;',
+ 'bare_domains'),
+ array('example.com:',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>:',
+ 'bare_domains'),
+ array('\'example.com\'',
+ '\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>\'',
+ 'bare_domains'),
+ array('"example.com"',
+ '"<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>"',
+ 'bare_domains'),
+ array('example.com',
+ '<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
+ 'bare_domains'),
+ array('(example.com)',
+ '(<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>)',
+ 'bare_domains'),
+ array('[example.com]',
+ '[<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>]',
+ 'bare_domains'),
+ array('<example.com>',
+ '<<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>>',
+ 'bare_domains'),
+ array('Hey, check out my cool site example.com okay?',
+ 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a> okay?',
+ 'bare_domains'),
+ array('Hey, check out my cool site example.com.I made it.',
+ 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.I made it.',
+ 'bare_domains'),
+ array('Hey, check out my cool site example.com.Funny thing...',
+ 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.Funny thing...',
+ 'bare_domains'),
+ array('Hey, check out my cool site example.com.You will love it.',
+ 'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.You will love it.',
+ 'bare_domains'),
+ array('example.com:8080/test.php',
+ '<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="nofollow external">example.com:8080/test.php</a>',
+ 'bare_domains'),
+ array('user_name+other@example.com',
+ '<a href="mailto:user_name+other@example.com" title="mailto:user_name+other@example.com" rel="nofollow external">user_name+other@example.com</a>',
+ 'bare_domains'),
+ array('user@example.com',
+ '<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">user@example.com</a>',
+ 'bare_domains'),
+ );
+ }
}
$this->assertEquals($poco->address->formatted, 'El Cerrito, CA');
$this->assertEquals($poco->urls[0]->type, 'homepage');
$this->assertEquals($poco->urls[0]->value, 'http://zach.copley.name');
- $this->assertEquals($poco->urls[0]->primary, 'true');
+ $this->assertEquals($poco->urls[0]->primary, true);
$this->assertEquals($poco->note, 'Zach Hack Attack');
// test the post
--- /dev/null
+<?php
+
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+ print "This script must be run from the command line\n";
+ exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('GNUSOCIAL', true);
+define('STATUSNET', true); // compatibility
+
+mb_internal_encoding('UTF-8'); // @fixme this probably belongs in common.php?
+
+require_once INSTALLDIR . '/lib/common.php';
+require_once INSTALLDIR . '/plugins/Xmpp/XmppPlugin.php';
+
+class XmppValidateTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ if(!array_key_exists('Xmpp', GNUsocial::getActivePlugins())){
+ $this->markTestSkipped('XmppPlugin is not enabled.');
+ }
+ }
+ /**
+ * @dataProvider validationCases
+ *
+ */
+ public function testValidate($jid, $validFull, $validBase)
+ {
+ $xmpp = new TestXmppPlugin();
+ $this->assertEquals($validFull || $validBase, $xmpp->validate($jid));
+ $this->assertEquals($validFull, $xmpp->validateFullJid($jid), "validating as full or base JID");
+ $this->assertEquals($validBase, $xmpp->validateBaseJid($jid), "validating as base JID only");
+ }
+
+ /**
+ * @dataProvider normalizationCases
+ *
+ */
+ public function testNormalize($jid, $expected)
+ {
+ $xmpp = new XmppPlugin();
+ $this->assertEquals($expected, $xmpp->normalize($jid));
+ }
+
+ /**
+ * @dataProvider domainCheckCases()
+ */
+ public function testDomainCheck($domain, $expected, $note)
+ {
+ $xmpp = new TestXmppPlugin();
+ $this->assertEquals($expected, $xmpp->checkDomain($domain), $note);
+ }
+
+ static public function validationCases()
+ {
+ $long1023 = "long1023" . str_repeat('x', 1023 - 8);
+ $long1024 = "long1024" . str_repeat('x', 1024 - 8);
+ return array(
+ // Our own test cases for standard things & those mentioned in bug reports
+ // (jid, valid_full, valid_base)
+ array('user@example.com', true, true),
+ array('user@example.com/resource', true, false),
+ array('user with spaces@example.com', false, false), // not kosher
+
+ array('user.@example.com', true, true), // "common in intranets"
+ array('example.com', true, true),
+ array('example.com/resource', true, false),
+ array('jabchat', true, true),
+
+ array("$long1023@$long1023/$long1023", true, false), // max 1023 "bytes" per portion per spec. Do they really mean bytes though?
+ array("$long1024@$long1023/$long1023", false, false),
+ array("$long1023@$long1024/$long1023", false, false),
+ array("$long1023@$long1023/$long1024", false, false),
+
+ // Borrowed from test_jabber_jutil.c in libpurple
+ array("gmail.com", true, true),
+ array("gmail.com/Test", true, false),
+ array("gmail.com/Test@", true, false),
+ array("gmail.com/@", true, false),
+ array("gmail.com/Test@alkjaweflkj", true, false),
+ array("mark.doliner@gmail.com", true, true),
+ array("mark.doliner@gmail.com/Test12345", true, false),
+ array("mark.doliner@gmail.com/Test@12345", true, false),
+ array("mark.doliner@gmail.com/Te/st@12@//345", true, false),
+ array("わいど@conference.jabber.org", true, true),
+ array("まりるーむ@conference.jabber.org", true, true),
+ array("mark.doliner@gmail.com/まりるーむ", true, false),
+ array("mark.doliner@gmail/stuff.org", true, false),
+ array("stuart@nödåtXäYZ.se", true, true),
+ array("stuart@nödåtXäYZ.se/まりるーむ", true, false),
+ array("mark.doliner@わいど.org", true, true),
+ array("nick@まつ.おおかみ.net", true, true),
+ array("paul@10.0.42.230/s", true, false),
+ array("paul@[::1]", true, true), /* IPv6 */
+ array("paul@[2001:470:1f05:d58::2]", true, true),
+ array("paul@[2001:470:1f05:d58::2]/foo", true, false),
+ array("pa=ul@10.0.42.230", true, true),
+ array("pa,ul@10.0.42.230", true, true),
+
+ array("@gmail.com", false, false),
+ array("@@gmail.com", false, false),
+ array("mark.doliner@@gmail.com/Test12345", false, false),
+ array("mark@doliner@gmail.com/Test12345", false, false),
+ array("@gmail.com/Test@12345", false, false),
+ array("/Test@12345", false, false),
+ array("mark.doliner@", false, false),
+ array("mark.doliner/", false, false),
+ array("mark.doliner@gmail_stuff.org", false, false),
+ array("mark.doliner@gmail[stuff.org", false, false),
+ array("mark.doliner@gmail\\stuff.org", false, false),
+ array("paul@[::1]124", false, false),
+ array("paul@2[::1]124/as", false, false),
+ array("paul@まつ.おおかみ/\x01", false, false),
+
+ /*
+ * RFC 3454 Section 6 reads, in part,
+ * "If a string contains any RandALCat character, the
+ * string MUST NOT contain any LCat character."
+ * The character is U+066D (ARABIC FIVE POINTED STAR).
+ */
+ // Leaving this one commented out for the moment
+ // as it shouldn't hurt anything for our purposes.
+ //array("foo@example.com/٭simplexe٭", false, false)
+ );
+ }
+
+ static public function normalizationCases()
+ {
+ return array(
+ // Borrowed from test_jabber_jutil.c in libpurple
+ array('PaUL@DaRkRain42.org', 'paul@darkrain42.org'),
+ array('PaUL@DaRkRain42.org/', 'paul@darkrain42.org'),
+ array('PaUL@DaRkRain42.org/resource', 'paul@darkrain42.org'),
+
+ // Also adapted from libpurple tests...
+ array('Ф@darkrain42.org', 'ф@darkrain42.org'),
+ array('paul@Өarkrain.org', 'paul@өarkrain.org'),
+ );
+ }
+
+ static public function domainCheckCases()
+ {
+ return array(
+ array('gmail.com', true, 'known SRV record'),
+ array('jabber.org', true, 'known SRV record'),
+ array('status.net', true, 'known SRV record'),
+ array('status.leuksman.com', true, 'known no SRV record but valid domain'),
+ );
+ }
+
+
+}
+
+class TestXmppPlugin extends XmppPlugin {
+ public function checkDomain($domain)
+ {
+ return parent::checkDomain($domain);
+ }
+
+ public function validateBaseJid($jid, $check_domain=false)
+ {
+ return parent::validateBaseJid($jid, $check_domain);
+ }
+
+ public function validateFullJid($jid, $check_domain=false)
+ {
+ return parent::validateFullJid($jid, $check_domain);
+ }
+}
\ No newline at end of file