From 5fd6053220d9ff2c28735fcf5b8c99b83b09ecc0 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 28 Apr 2014 14:08:42 +0200 Subject: [PATCH] Code cleanup and enabling User object's etc. getUri() --- actions/foaf.php | 13 ++++---- classes/Profile.php | 10 +++++-- classes/User.php | 5 ++++ lib/accountmover.php | 2 +- lib/activityimporter.php | 25 +++++++--------- lib/activitymover.php | 2 +- lib/useractivitystream.php | 2 +- lib/util.php | 2 +- plugins/AutoSandbox/AutoSandboxPlugin.php | 8 +++-- plugins/OStatus/actions/usersalmon.php | 13 ++++---- plugins/OStatus/classes/FeedSub.php | 20 ++++++------- plugins/OStatus/classes/Ostatus_profile.php | 33 ++++++++++++--------- plugins/OStatus/scripts/fixup-shadow.php | 10 +++---- tests/ActivityGenerationTests.php | 32 ++++++++++---------- 14 files changed, 93 insertions(+), 84 deletions(-) diff --git a/actions/foaf.php b/actions/foaf.php index 83f7d97d58..bcdc86d886 100644 --- a/actions/foaf.php +++ b/actions/foaf.php @@ -90,11 +90,10 @@ class FoafAction extends Action // This is the document about the user - $this->showPpd('', $this->user->uri); + $this->showPpd('', $this->user->getUri()); // Would be nice to tell if they were a Person or not (e.g. a #person usertag?) - $this->elementStart('Agent', array('rdf:about' => - $this->user->uri)); + $this->elementStart('Agent', array('rdf:about' => $this->user->getUri())); if ($this->user->email) { $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email)); } @@ -158,7 +157,7 @@ class FoafAction extends Action } $person = $this->showMicrobloggingAccount($this->profile, - common_root_url(), $this->user->uri, + common_root_url(), $this->user->getUri(), /*$fetchSubscriptions*/true, /*$isSubscriber*/false); @@ -171,7 +170,7 @@ class FoafAction extends Action if ($sub->find()) { while ($sub->fetch()) { $profile = Profile::getKV('id', $sub->subscriber); - if (empty($profile)) { + if (!$profile instanceof Profile) { common_debug('Got a bad subscription: '.print_r($sub,true)); continue; } @@ -209,7 +208,7 @@ class FoafAction extends Action $profile = Profile::getKV($id); $this->elementStart('Agent', array('rdf:about' => $uri)); if ($type == BOTH) { - $this->element('knows', array('rdf:resource' => $this->user->uri)); + $this->element('knows', array('rdf:resource' => $this->user->getUri())); } $this->showMicrobloggingAccount($profile, ($local == 'local') ? common_root_url() : null, @@ -301,7 +300,7 @@ class FoafAction extends Action unset($sub); } else if ($isSubscriber) { // Just declare that they follow the user whose FOAF we're showing. - $this->element('sioc:follows', array('rdf:resource' => $this->user->uri . '#acct')); + $this->element('sioc:follows', array('rdf:resource' => $this->user->getUri() . '#acct')); } $this->elementEnd('OnlineAccount'); diff --git a/classes/Profile.php b/classes/Profile.php index 6adf059781..c40e0e0b17 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -1389,6 +1389,11 @@ class Profile extends Managed_DataObject return $this->profileurl; } + public function getNickname() + { + return $this->nickname; + } + /** * Returns the best URI for a profile. Plugins may override. * @@ -1403,9 +1408,8 @@ class Profile extends Managed_DataObject // check for a local user first $user = User::getKV('id', $this->id); - - if (!empty($user)) { - $uri = $user->uri; + if ($user instanceof User) { + $uri = $user->getUri(); } Event::handle('EndGetProfileUri', array($this, &$uri)); diff --git a/classes/User.php b/classes/User.php index d0eba7f75b..55e5277245 100644 --- a/classes/User.php +++ b/classes/User.php @@ -132,6 +132,11 @@ class User extends Managed_DataObject return $this->_profile; } + public function getUri() + { + return $this->uri; + } + function isSubscribed(Profile $other) { return $this->getProfile()->isSubscribed($other); diff --git a/lib/accountmover.php b/lib/accountmover.php index 429b6c0465..83314b4997 100644 --- a/lib/accountmover.php +++ b/lib/accountmover.php @@ -86,7 +86,7 @@ class AccountMover extends QueueHandler $qm = QueueManager::get(); foreach ($acts as $act) { - $qm->enqueue(array($act, $sink, $user->uri, $remote), 'actmove'); + $qm->enqueue(array($act, $sink, $user->getUri(), $remote), 'actmove'); } $this->log(LOG_INFO, diff --git a/lib/activityimporter.php b/lib/activityimporter.php index 1c34b64d35..27f89225c2 100644 --- a/lib/activityimporter.php +++ b/lib/activityimporter.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Class comment @@ -104,13 +100,13 @@ class ActivityImporter extends QueueHandler $other = $activity->actor; $otherUser = User::getKV('uri', $other->id); - if (!empty($otherUser)) { - $otherProfile = $otherUser->getProfile(); - } else { + if (!$otherUser instanceof User) { // TRANS: Client exception thrown when trying to force a remote user to subscribe. throw new Exception(_('Cannot force remote user to subscribe.')); } + $otherProfile = $otherUser->getProfile(); + // XXX: don't do this for untrusted input! Subscription::start($otherProfile, $profile); @@ -141,7 +137,7 @@ class ActivityImporter extends QueueHandler $group = User_group::getKV('uri', $uri); - if (empty($group)) { + if (!$group instanceof User_group) { $oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]); if (!$oprofile->isGroup()) { // TRANS: Client exception thrown when trying to join a remote group that is not a group. @@ -170,7 +166,7 @@ class ActivityImporter extends QueueHandler $notice = Notice::getKV('uri', $sourceUri); - if (!empty($notice)) { + if ($notice instanceof Notice) { common_log(LOG_INFO, "Notice {$sourceUri} already exists."); @@ -180,8 +176,8 @@ class ActivityImporter extends QueueHandler $uri = $profile->getUri(); - if ($uri == $author->id) { - common_log(LOG_INFO, "Updating notice author from $author->id to $user->uri"); + if ($uri === $author->id) { + common_log(LOG_INFO, sprintf('Updating notice author from %s to %s', $author->id, $user->getUri())); $orig = clone($notice); $notice->profile_id = $user->id; $notice->update($orig); @@ -244,9 +240,8 @@ class ActivityImporter extends QueueHandler // Maintain direct reply associations // @fixme what about conversation ID? if (!empty($activity->context->replyToID)) { - $orig = Notice::getKV('uri', - $activity->context->replyToID); - if (!empty($orig)) { + $orig = Notice::getKV('uri', $activity->context->replyToID); + if ($orig instanceof Notice) { $options['reply_to'] = $orig->id; } } diff --git a/lib/activitymover.php b/lib/activitymover.php index d5edab5caa..0493750d08 100644 --- a/lib/activitymover.php +++ b/lib/activitymover.php @@ -121,7 +121,7 @@ class ActivityMover extends QueueHandler } break; case ActivityVerb::FOLLOW: - if ($act->actor->id == $user->uri) { + if ($act->actor->id === $user->getUri()) { $this->log(LOG_INFO, "Moving subscription to {$act->objects[0]->id} by ". "{$act->actor->id} to {$remote->nickname}."); diff --git a/lib/useractivitystream.php b/lib/useractivitystream.php index 246bdb5d90..ce3e373724 100644 --- a/lib/useractivitystream.php +++ b/lib/useractivitystream.php @@ -154,7 +154,7 @@ class UserActivityStream extends AtomUserNoticeFeed try { if ($format == Feed::ATOM) { // Only show the author sub-element if it's different from default user - $act->outputTo($this, false, ($act->actor->id != $this->user->uri)); + $act->outputTo($this, false, ($act->actor->id != $this->user->getUri())); } else { if ($haveOne) { fwrite($handle, ","); diff --git a/lib/util.php b/lib/util.php index ac1938e844..aa6a59c9aa 100644 --- a/lib/util.php +++ b/lib/util.php @@ -2048,7 +2048,7 @@ function common_profile_uri($profile) if (Event::handle('StartCommonProfileURI', array($profile, &$uri))) { $user = User::getKV('id', $profile->id); if ($user instanceof User) { - $uri = $user->uri; + $uri = $user->getUri(); } Event::handle('EndCommonProfileURI', array($profile, &$uri)); } diff --git a/plugins/AutoSandbox/AutoSandboxPlugin.php b/plugins/AutoSandbox/AutoSandboxPlugin.php index 9e930c0cc4..bffb840572 100644 --- a/plugins/AutoSandbox/AutoSandboxPlugin.php +++ b/plugins/AutoSandbox/AutoSandboxPlugin.php @@ -75,10 +75,12 @@ class AutoSandboxPlugin extends Plugin if (isset($this->contact)) { $contactuser = User::getKV('nickname', $this->contact); - if (!empty($contactuser)) { - $contactlink = "@uri\">$contactuser->nickname"; + if ($contactuser instanceof User) { + $contactlink = sprintf('@%s', + htmlspecialchars($contactuser->getProfile()->getUrl()), + htmlspecialchars($contactuser->getProfile()->getNickname())); // TRANS: User instructions after registration. - // TRANS: %s is a clickable e-mailaddress. + // TRANS: %s is a clickable OStatus profile URL. $instr = sprintf(_m('Note you will initially be "sandboxed" so your posts will not appear in the public timeline. '. 'Send a message to %s to speed up the unsandboxing process.'),$contactlink); } diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 296fd6c6c7..383b42b147 100644 --- a/plugins/OStatus/actions/usersalmon.php +++ b/plugins/OStatus/actions/usersalmon.php @@ -91,9 +91,9 @@ class UsersalmonAction extends SalmonAction throw new ClientException(_m('In reply to a notice not by this user and not mentioning this user.')); } } else if (!empty($context->attention)) { - if (!array_key_exists($this->user->uri, $context->attention) && + if (!array_key_exists($this->user->getUri(), $context->attention) && !array_key_exists(common_profile_url($this->user->nickname), $context->attention)) { - common_log(LOG_ERR, "{$this->user->uri} not in attention list (".implode(',', array_keys($context->attention)).')'); + common_log(LOG_ERR, $this->user->getUri() . "not in attention list (".implode(',', array_keys($context->attention)).')'); // TRANS: Client exception. throw new ClientException(_m('To the attention of user(s), not including this one.')); } @@ -103,9 +103,8 @@ class UsersalmonAction extends SalmonAction } $existing = Notice::getKV('uri', $this->activity->objects[0]->id); - - if (!empty($existing)) { - common_log(LOG_ERR, "Not saving notice '{$existing->uri}'; already exists."); + if ($existing instanceof Notice) { + common_log(LOG_ERR, "Not saving notice '".$existing->getUri()."'; already exists."); return; } @@ -120,7 +119,7 @@ class UsersalmonAction extends SalmonAction { $oprofile = $this->ensureProfile(); if ($oprofile) { - common_log(LOG_INFO, "Setting up subscription from remote {$oprofile->uri} to local {$this->user->nickname}"); + common_log(LOG_INFO, sprintf('Setting up subscription from remote %s to local %s', $oprofile->getUri(), $this->user->getNickname())); Subscription::start($oprofile->localProfile(), $this->user->getProfile()); } else { @@ -138,7 +137,7 @@ class UsersalmonAction extends SalmonAction { $oprofile = $this->ensureProfile(); if ($oprofile) { - common_log(LOG_INFO, "Canceling subscription from remote {$oprofile->uri} to local {$this->user->nickname}"); + common_log(LOG_INFO, sprintf('Canceling subscription from remote %s to local %s', $oprofile->getUri(), $this->user->getNickname())); Subscription::cancel($oprofile->localProfile(), $this->user->getProfile()); } else { common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile"); diff --git a/plugins/OStatus/classes/FeedSub.php b/plugins/OStatus/classes/FeedSub.php index a7a77c6644..0a6abfa1be 100644 --- a/plugins/OStatus/classes/FeedSub.php +++ b/plugins/OStatus/classes/FeedSub.php @@ -198,7 +198,7 @@ class FeedSub extends Managed_DataObject public function subscribe() { if ($this->sub_state && $this->sub_state != 'inactive') { - common_log(LOG_WARNING, "Attempting to (re)start PuSH subscription to {$this->uri} in unexpected state {$this->sub_state}"); + common_log(LOG_WARNING, sprintf('Attempting to (re)start PuSH subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state)); } if (!Event::handle('FeedSubscribe', array($this))) { @@ -235,7 +235,7 @@ class FeedSub extends Managed_DataObject */ public function unsubscribe() { if ($this->sub_state != 'active') { - common_log(LOG_WARNING, "Attempting to (re)end PuSH subscription to {$this->uri} in unexpected state {$this->sub_state}"); + common_log(LOG_WARNING, sprintf('Attempting to (re)end PuSH subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state)); } if (!Event::handle('FeedUnsubscribe', array($this))) { @@ -278,10 +278,10 @@ class FeedSub extends Managed_DataObject Event::handle('FeedSubSubscriberCount', array($this, &$count)); if ($count) { - common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->uri); + common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->getUri()); return false; } else { - common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->uri); + common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->getUri()); return $this->unsubscribe(); } } @@ -331,7 +331,7 @@ class FeedSub extends Managed_DataObject 'hub.verify_token' => 'Deprecated-since-PuSH-0.4', // TODO: rm! 'hub.secret' => $this->secret, - 'hub.topic' => $this->uri); + 'hub.topic' => $this->getUri()); $client = new HTTPClient(); if ($this->huburi) { $hub = $this->huburi; @@ -359,7 +359,7 @@ class FeedSub extends Managed_DataObject } } catch (Exception $e) { // wtf! - common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to $this->uri"); + common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to " . $this->getUri()); $orig = clone($this); $this->sub_state = 'inactive'; @@ -425,10 +425,10 @@ class FeedSub extends Managed_DataObject */ public function receive($post, $hmac) { - common_log(LOG_INFO, __METHOD__ . ": packet for \"$this->uri\"! $hmac $post"); + common_log(LOG_INFO, __METHOD__ . ": packet for \"" . $this->getUri() . "\"! $hmac $post"); if ($this->sub_state != 'active') { - common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed $this->uri (in state '$this->sub_state')"); + common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed " . $this->getUri() . " (in state '$this->sub_state')"); return; } @@ -483,9 +483,9 @@ class FeedSub extends Managed_DataObject if ($tempfile) { file_put_contents($tempfile, $post); } - common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed $this->uri on $this->huburi; saved to $tempfile"); + common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed " . $this->getUri() . " on $this->huburi; saved to $tempfile"); } else { - common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed $this->uri on $this->huburi"); + common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed " . $this->getUri() . " on $this->huburi"); } } else { common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bogus HMAC '$hmac'"); diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index b05d1755ca..59eccc52d0 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -76,6 +76,11 @@ class Ostatus_profile extends Managed_DataObject ); } + public function getUri() + { + return $this->uri; + } + /** * Fetch the StatusNet-side profile for this feed * @return Profile @@ -165,10 +170,10 @@ class Ostatus_profile extends Managed_DataObject return true; } else if ($this->group_id && ($this->profile_id || $this->peopletag_id)) { // TRANS: Server exception. %s is a URI - throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->uri)); + throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->getUri())); } else { // TRANS: Server exception. %s is a URI - throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->uri)); + throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->getUri())); } } @@ -183,10 +188,10 @@ class Ostatus_profile extends Managed_DataObject return true; } else if ($this->peopletag_id && ($this->profile_id || $this->group_id)) { // TRANS: Server exception. %s is a URI - throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->uri)); + throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->getUri())); } else { // TRANS: Server exception. %s is a URI - throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->uri)); + throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->getUri())); } } @@ -954,7 +959,7 @@ class Ostatus_profile extends Managed_DataObject $groups[] = $oprofile->group_id; } else { // may be canonicalized or something - $replies[] = $oprofile->uri; + $replies[] = $oprofile->getUri(); } continue; } catch (Exception $e) { @@ -1227,7 +1232,7 @@ class Ostatus_profile extends Managed_DataObject throw new ServerException(sprintf( // TRANS: Server exception. %s is a URI. _m('Tried to update avatar for unsaved remote profile %s.'), - $this->uri)); + $this->getUri())); } // @todo FIXME: This should be better encapsulated @@ -1459,7 +1464,7 @@ class Ostatus_profile extends Managed_DataObject } $user = User::getKV('uri', $homeuri); - if ($user) { + if ($user instanceof User) { // TRANS: Exception. throw new Exception(_m('Local user cannot be referenced as remote.')); } @@ -1914,7 +1919,7 @@ class Ostatus_profile extends Managed_DataObject $oprofile = Ostatus_profile::getKV('uri', 'acct:'.$addr); if ($oprofile instanceof Ostatus_profile) { - self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri); + self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri()); return $oprofile; } @@ -1952,7 +1957,7 @@ class Ostatus_profile extends Managed_DataObject try { common_log(LOG_INFO, "Discovery on acct:$addr with feed URL " . $hints['feedurl']); $oprofile = self::ensureFeedURL($hints['feedurl'], $hints); - self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri); + self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri()); return $oprofile; } catch (Exception $e) { common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage()); @@ -1965,7 +1970,7 @@ class Ostatus_profile extends Managed_DataObject try { common_log(LOG_INFO, "Discovery on acct:$addr with profile URL $profileUrl"); $oprofile = self::ensureProfileURL($hints['profileurl'], $hints); - self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri); + self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri()); return $oprofile; } catch (OStatusShadowException $e) { // We've ended up with a remote reference to a local user or group. @@ -2029,7 +2034,7 @@ class Ostatus_profile extends Managed_DataObject throw new Exception(sprintf(_m('Could not save OStatus profile for "%s".'),$addr)); } - self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri); + self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri()); return $oprofile; } @@ -2133,7 +2138,7 @@ class Ostatus_profile extends Managed_DataObject // Groups can't post notices in StatusNet. common_log(LOG_WARNING, "OStatus: skipping post with group listed ". - "as author: $oprofile->uri in feed from $this->uri"); + "as author: " . $oprofile->getUri() . " in feed from " . $this->getUri()); return false; } } else { @@ -2141,7 +2146,7 @@ class Ostatus_profile extends Managed_DataObject if (empty($actor)) { // OK here! assume the default - } else if ($actor->id == $this->uri || $actor->link == $this->uri) { + } else if ($actor->id == $this->getUri() || $actor->link == $this->getUri()) { $this->updateFromActivityObject($actor); } else if ($actor->id) { // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner. @@ -2150,7 +2155,7 @@ class Ostatus_profile extends Managed_DataObject // Most likely this is a plain ol' blog feed of some kind which // doesn't match our expectations. We'll take the entry, but ignore // the info. - common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}"); + common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for " . $this->getUri()); } else { // Plain without ActivityStreams actor info. // We'll just ignore this info for now and save the update under the feed's identity. diff --git a/plugins/OStatus/scripts/fixup-shadow.php b/plugins/OStatus/scripts/fixup-shadow.php index 45e2d8c0b0..ffaae5588d 100644 --- a/plugins/OStatus/scripts/fixup-shadow.php +++ b/plugins/OStatus/scripts/fixup-shadow.php @@ -47,7 +47,7 @@ $count = $user->N; echo "Found $count...\n"; while ($user->fetch()) { - $uri = $user->uri; + $uri = $user->getUri(); echo "user $user->id ($user->nickname) hidden by $uri"; if ($dry) { echo " - skipping\n"; @@ -71,7 +71,7 @@ $count = $group->N; echo "Found $count...\n"; while ($group->fetch()) { - $uri = $group->uri; + $uri = $group->getUri(); echo "group $group->id ($group->nickname) hidden by $uri"; if ($dry) { echo " - skipping\n"; @@ -106,7 +106,7 @@ $count = $group->N; echo "Found $count...\n"; while ($group->fetch()) { - $uri = $group->uri; + $uri = $group->getUri(); if (preg_match('!/group/(\d+)/id!', $uri, $matches)) { $id = intval($matches[1]); $local = Local_group::getKV('group_id', $id); @@ -152,8 +152,8 @@ $count = $oprofile->N; echo "Found $count...\n"; while ($oprofile->fetch()) { - $uri = $oprofile->uri; - if (preg_match('!/group/(\d+)/id!', $oprofile->uri, $matches)) { + $uri = $oprofile->getUri(); + if (preg_match('!/group/(\d+)/id!', $oprofile->getUri(), $matches)) { $id = intval($matches[1]); $group = Local_group::getKV('group_id', $id); if ($group) { diff --git a/tests/ActivityGenerationTests.php b/tests/ActivityGenerationTests.php index 4c4db6148a..c9f27cbde0 100644 --- a/tests/ActivityGenerationTests.php +++ b/tests/ActivityGenerationTests.php @@ -81,7 +81,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $element = $this->_entryToElement($entry, false); - $this->assertEquals($notice->uri, ActivityUtils::childContent($element, 'id')); + $this->assertEquals($notice->getUri(), ActivityUtils::childContent($element, 'id')); $this->assertEquals($notice->content, ActivityUtils::childContent($element, 'title')); $this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content')); $this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published'))); @@ -210,8 +210,8 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $author = ActivityUtils::child($element, 'author'); - $this->assertEquals($this->author1->nickname, ActivityUtils::childContent($author, 'name')); - $this->assertEquals($this->author1->uri, ActivityUtils::childContent($author, 'uri')); + $this->assertEquals($this->author1->getNickname(), ActivityUtils::childContent($author, 'name')); + $this->assertEquals($this->author1->getUri(), ActivityUtils::childContent($author, 'uri')); } /** @@ -247,8 +247,8 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $irt = ActivityUtils::child($element, 'in-reply-to', 'http://purl.org/syndication/thread/1.0'); $this->assertNotNull($irt); - $this->assertEquals($orig->uri, $irt->getAttribute('ref')); - $this->assertEquals($orig->bestUrl(), $irt->getAttribute('href')); + $this->assertEquals($orig->getUri(), $irt->getAttribute('ref')); + $this->assertEquals($orig->getUrl(), $irt->getAttribute('href')); } public function testReplyAttention() @@ -263,7 +263,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $element = $this->_entryToElement($entry, true); - $this->assertEquals($this->targetUser1->uri, ActivityUtils::getLink($element, 'mentioned')); + $this->assertEquals($this->targetUser1->getUri(), ActivityUtils::getLink($element, 'mentioned')); } public function testMultipleReplyAttention() @@ -292,8 +292,8 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $hrefs[] = $link->getAttribute('href'); } - $this->assertTrue(in_array($this->targetUser1->uri, $hrefs)); - $this->assertTrue(in_array($this->targetUser2->uri, $hrefs)); + $this->assertTrue(in_array($this->targetUser1->getUri(), $hrefs)); + $this->assertTrue(in_array($this->targetUser2->getUri(), $hrefs)); $links = ActivityUtils::getLinks($element, 'mentioned'); @@ -305,8 +305,8 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $hrefs[] = $link->getAttribute('href'); } - $this->assertTrue(in_array($this->targetUser1->uri, $hrefs)); - $this->assertTrue(in_array($this->targetUser2->uri, $hrefs)); + $this->assertTrue(in_array($this->targetUser1->getUri(), $hrefs)); + $this->assertTrue(in_array($this->targetUser2->getUri(), $hrefs)); } public function testGroupPostAttention() @@ -319,7 +319,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $element = $this->_entryToElement($entry, true); - $this->assertEquals($this->targetGroup1->uri, ActivityUtils::getLink($element, 'mentioned')); + $this->assertEquals($this->targetGroup1->getUri(), ActivityUtils::getLink($element, 'mentioned')); } public function testMultipleGroupPostAttention() @@ -342,8 +342,8 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $hrefs[] = $link->getAttribute('href'); } - $this->assertTrue(in_array($this->targetGroup1->uri, $hrefs)); - $this->assertTrue(in_array($this->targetGroup2->uri, $hrefs)); + $this->assertTrue(in_array($this->targetGroup1->getUri(), $hrefs)); + $this->assertTrue(in_array($this->targetGroup2->getUri(), $hrefs)); $links = ActivityUtils::getLinks($element, 'mentioned'); @@ -355,8 +355,8 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $hrefs[] = $link->getAttribute('href'); } - $this->assertTrue(in_array($this->targetGroup1->uri, $hrefs)); - $this->assertTrue(in_array($this->targetGroup2->uri, $hrefs)); + $this->assertTrue(in_array($this->targetGroup1->getUri(), $hrefs)); + $this->assertTrue(in_array($this->targetGroup2->getUri(), $hrefs)); } public function testRepeatLink() @@ -371,7 +371,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $forward = ActivityUtils::child($element, 'forward', "http://ostatus.org/schema/1.0"); $this->assertNotNull($forward); - $this->assertEquals($notice->uri, $forward->getAttribute('ref')); + $this->assertEquals($notice->getUri(), $forward->getAttribute('ref')); $this->assertEquals($notice->bestUrl(), $forward->getAttribute('href')); } -- 2.39.5