Problem/Motivation
\Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::testPost()
calls getNormalizedPostEntity()
twice in order to get two valid representations of an entity for POST testing:
$parseable_valid_request_body = $this->serializer->encode($this->getNormalizedPostEntity(), static::$format);
$parseable_valid_request_body_2 = $this->serializer->encode($this->getNormalizedPostEntity(), static::$format);
and there are two class variables $firstCreatedEntityId
and $secondCreatedEntityId
where we can specify the IDs for those two entities.
The problem is that calling getNormalizedPostEntity()
twice without any possibility of returning different IDs per invocation assumes that the IDs are automatically generated by the DB layer. However, that's not the case for entity types with string IDs, where they are actually specified by the code which saves the entity (e.g. the entity form).
Proposed resolution
Add a EntityResourceTestBase::getSecondNormalizedPostEntity()
method which allows test classes to specify a different, pre-determined ID for the second POST entity.
Remaining tasks
Review.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2935076-8.patch | 2.08 KB | amateescu |
#6 | 2935076-6-combined.patch | 23.74 KB | amateescu |
#3 | 2935076-3-combined.patch | 24.73 KB | amateescu |
#3 | 2935076-3.patch | 2.08 KB | amateescu |
Comments
Comment #2
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThis patch touches the same code as #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002), which is already RTBC, so I think it's easier if I just make the initial patch depend on it.
Btw, this is a blocker for #2784921: Add Workspaces experimental module.
Comment #3
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOops, wrong patches, I forgot include a hunk.
Comment #6
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThis is what happens when you don't check what branch you're working on :/ Maybe it would've been easier to not depend on #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002)..
Comment #7
Wim LeersLGTM!
But it's blocked on #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002), so marking instead of .
Comment #8
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe blocker is in, re-uploading #3 and setting to RTBC per #7.
Comment #10
catchCommitted/pushed to 8.6.x and cherry-picked to 8.5.x. Thanks!
Comment #13
catch