Skip to:
Content

BuddyPress.org

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#7234 closed enhancement (fixed)

Implement get_object_by_id() method in message factory

Reported by: jdgrimes Owned by: boonebgorges
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Cc:

Description

Otherwise the create_and_get() method doesn't work.

Introduced in [8504].

Attachments (3)

7234.diff (546 bytes) - added by jdgrimes 3 years ago.
7234.2.diff (915 bytes) - added by jdgrimes 3 years ago.
7234.3.diff (1.2 KB) - added by jdgrimes 3 years ago.

Download all attachments as: .zip

Change History (14)

@jdgrimes
3 years ago

#1 @jdgrimes
3 years ago

  • Keywords has-patch added

I haven't attempted to implement update_object() as well, because I'm not sure how to update a message (fairly new to BuddyPress's codebase).

@jdgrimes
3 years ago

#2 @jdgrimes
3 years ago

I've discovered that the factory really doesn't work at all (it doesn't generate any default values). It always fails (silently) because the $default_generation_definitions are only allowed to contain scalar values or WP_UnitTest_Generator_Sequence instances, but 'recipients' is included in the defaults there as array(). The solution is to omit the default for 'recipients', as it really isn't needed there. I've done this in 7234.2.diff. Better yet, the defaults for the recipients could be set in create_object() instead, with a recipient created on the fly if none are specified, since messages_new_message() requires that there be a recipient of the message.

@jdgrimes
3 years ago

#3 @jdgrimes
3 years ago

7234.3.diff updates the create_object() method to create a sender and recipient on the fly if these values are empty. I think that this is the correct behavior for the factory, because if either of these values are empty the message won't be created by messages_new_message().

Note that the sender does default to the current user, but this value is not always set during the unit tests (actually, I think that it is unset by default as of now).

This ticket was mentioned in Slack in #buddypress by boone. View the logs.


3 years ago

#5 @DJPaul
3 years ago

  • Milestone changed from Awaiting Review to 2.7

Sounds like we need tests for our tests. ;) ;)

This looks good and is an improvement over what we have. Let's get @boonebgorges' input in case he remembers something pertinent from 2 years ago about this, but I think we can commit this.

#6 @boonebgorges
3 years ago

@jdgrimes Thanks for the patch!

The technique you've used for fetching the message ID after creation is not quite right. messages_new_message() returns a *thread* ID. In fact, I don't think there's a way to get the ID of the created message from the return value of messages_new_message(). Needless to say, this is truly awful. But we can fix the factory by fetching the last item in the thread's messages array (end()). Let's maybe try to break messages_new_message() into pieces in a different thread (no pun intended).

#7 @boonebgorges
3 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 11042:

Tests: Fix message factory create/get methods.

Previously, message creation was failing because no 'sender_id' or
'recipients' were set. We now create senders and recipients when none
are passed to the create() method.

This changeset also fixes the return value of create_object(), so that
create_and_get() works for messages.

Props jdgrimes.
Fixes #7234.

#8 @jdgrimes
3 years ago

@boonebgorges I'd just noticed that and was getting ready to correct the patch. :-) [11042] looks great. Thanks for the quick work on this.

#9 @boonebgorges
3 years ago

Oy, this broke some tests that relied on the thread_id rather than the message ID being returned from the factory. These are tests that @r-a-y introduced in [9846], [9186]. I am going to guess that no one else in the universe has ever looked at these factory methods, so the backward compatibility break seems OK, and I'm going to fix the tests. If anyone disagrees, speak now, etc.

#10 @r-a-y
3 years ago

Go ahead and fix the tests! :)

#11 @boonebgorges
3 years ago

In 11044:

Update Messages tests to work after the changes in [11042].

See #7234.

Note: See TracTickets for help on using tickets.