#7234 closed enhancement (fixed)
Implement get_object_by_id() method in message factory
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (14)
#2
@
9 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.
#3
@
9 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.
9 years ago
#5
@
9 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
@
9 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
@
9 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from new to closed
In 11042:
#8
@
9 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
@
9 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.
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).