From e2e184363962b10ddbcd6f04d28f83d92ba67b7c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 11 Dec 2009 13:53:09 -0800 Subject: slight cleanup for a bit in Notice.php where a var was reused for different types, confusing tracking down a bug --- classes/Notice.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 4aec4ed55..01ed4e7f4 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -966,6 +966,9 @@ class Notice extends Memcached_DataObject return true; } + /** + * @return array of integer profile IDs + */ function saveReplies() { // Alternative reply format @@ -1044,8 +1047,8 @@ class Notice extends Memcached_DataObject $recipientIds = array_keys($replied); - foreach ($recipientIds as $recipient) { - $user = User::staticGet('id', $recipient); + foreach ($recipientIds as $recipientId) { + $user = User::staticGet('id', $recipientId); if ($user) { mail_notify_attn($user, $this); } -- cgit v1.2.3-54-g00ecf From 00fb5feff8f2552f63f1ddc7b1bef25ebd408507 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 15 Dec 2009 13:05:05 -0800 Subject: Cleanup undefined variable notice: set a couple more null defaults for new params in Notice::saveNew(). Fixes this notice seen while using AJAX repeat button: Notice: Undefined variable: uri in classes/Notice.php on line 243 --- classes/Notice.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 01ed4e7f4..2205279e8 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -176,12 +176,13 @@ class Notice extends Memcached_DataObject } static function saveNew($profile_id, $content, $source, $options=null) { + $defaults = array('uri' => null, + 'reply_to' => null, + 'repeat_of' => null); if (!empty($options)) { + $options = $options + $defaults; extract($options); - if (!isset($reply_to)) { - $reply_to = NULL; - } } if (empty($is_local)) { -- cgit v1.2.3-54-g00ecf From a998bda4a57014d0a319fd0bc31552705f0887ed Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 15 Dec 2009 14:49:53 -0800 Subject: Fix UserRightsTest unit tests --- classes/User.php | 2 +- tests/UserRightsTest.php | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'classes') diff --git a/classes/User.php b/classes/User.php index d04f7d679..c62314d50 100644 --- a/classes/User.php +++ b/classes/User.php @@ -329,7 +329,7 @@ class User extends Memcached_DataObject $profile->query('COMMIT'); - if ($email && !$user->email) { + if (!empty($email) && !$user->email) { mail_confirm_address($user, $confirm->code, $profile->nickname, $email); } diff --git a/tests/UserRightsTest.php b/tests/UserRightsTest.php index 6544ee53d..d24a172f6 100644 --- a/tests/UserRightsTest.php +++ b/tests/UserRightsTest.php @@ -16,14 +16,26 @@ class UserRightsTest extends PHPUnit_Framework_TestCase function setUp() { + $user = User::staticGet('nickname', 'userrightstestuser'); + if ($user) { + // Leftover from a broken test run? + $profile = $user->getProfile(); + $user->delete(); + $profile->delete(); + } $this->user = User::register(array('nickname' => 'userrightstestuser')); + if (!$this->user) { + throw new Exception("Couldn't register userrightstestuser"); + } } function tearDown() { - $profile = $this->user->getProfile(); - $this->user->delete(); - $profile->delete(); + if ($this->user) { + $profile = $this->user->getProfile(); + $this->user->delete(); + $profile->delete(); + } } function testInvalidRole() @@ -33,7 +45,8 @@ class UserRightsTest extends PHPUnit_Framework_TestCase function standardRoles() { - return array('admin', 'moderator'); + return array(array('admin'), + array('moderator')); } /** @@ -54,6 +67,6 @@ class UserRightsTest extends PHPUnit_Framework_TestCase function testGrantedRole($role) { $this->user->grantRole($role); - $this->assertFalse($this->user->hasRole($role)); + $this->assertTrue($this->user->hasRole($role)); } } \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 0ca80f78fbb07ebaaa1509c65021eb5f26cf5c99 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 15 Dec 2009 18:27:03 -0500 Subject: Add doc comments listing the array parameters for User::register() and Notice::saveNew() --- classes/Notice.php | 29 +++++++++++++++++++++++++++++ classes/User.php | 21 +++++++++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 2205279e8..7651d8bd5 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -175,6 +175,35 @@ class Notice extends Memcached_DataObject } } + /** + * Save a new notice and push it out to subscribers' inboxes. + * Poster's permissions are checked before sending. + * + * @param int $profile_id Profile ID of the poster + * @param string $content source message text; links may be shortened + * per current user's preference + * @param string $source source key ('web', 'api', etc) + * @param array $options Associative array of optional properties: + * string 'created' timestamp of notice; defaults to now + * int 'is_local' source/gateway ID, one of: + * Notice::LOCAL_PUBLIC - Local, ok to appear in public timeline + * Notice::REMOTE_OMB - Sent from a remote OMB service; + * hide from public timeline but show in + * local "and friends" timelines + * Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline + * Notice::GATEWAY - From another non-OMB service; + * will not appear in public views + * float 'lat' decimal latitude for geolocation + * float 'lon' decimal longitude for geolocation + * int 'location_id' geoname identifier + * int 'location_ns' geoname namespace to interpret location_id + * int 'reply_to'; notice ID this is a reply to + * int 'repeat_of'; notice ID this is a repeat of + * string 'uri' permalink to notice; defaults to local notice URL + * + * @return Notice + * @throws ClientException + */ static function saveNew($profile_id, $content, $source, $options=null) { $defaults = array('uri' => null, 'reply_to' => null, diff --git a/classes/User.php b/classes/User.php index c62314d50..ae709b46b 100644 --- a/classes/User.php +++ b/classes/User.php @@ -180,6 +180,27 @@ class User extends Memcached_DataObject return $result; } + /** + * Register a new user account and profile and set up default subscriptions. + * If a new-user welcome message is configured, this will be sent. + * + * @param array $fields associative array of optional properties + * string 'bio' + * string 'email' + * bool 'email_confirmed' pass true to mark email as pre-confirmed + * string 'fullname' + * string 'homepage' + * string 'location' informal string description of geolocation + * float 'lat' decimal latitude for geolocation + * float 'lon' decimal longitude for geolocation + * int 'location_id' geoname identifier + * int 'location_ns' geoname namespace to interpret location_id + * string 'nickname' REQUIRED + * string 'password' (may be missing for eg OpenID registrations) + * string 'code' invite code + * ?string 'uri' permalink to notice; defaults to local notice URL + * @return mixed User object or false on failure + */ static function register($fields) { // MAGICALLY put fields into current scope -- cgit v1.2.3-54-g00ecf