Problem/Motivation
Calling generateSampleValue() on a UUID field does not return a proper UUID.
Proposed resolution
Implement generateSampleValue() in UuidItem. Use \Drupal::service('uuid') to fetch the UUID generator and call generate() on it to generate the UUID.
Remaining tasks
| Task | Novice task? | Contributor instructions | Complete? |
|---|---|---|---|
| Create a patch | Instructions | ||
| Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions |
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | interdiff-2827748-5-13.txt | 769 bytes | faline |
| #13 | interdiff-2827748-10-13.txt | 501 bytes | faline |
| #13 | uuiditem_should-2827748-13.patch | 1.76 KB | faline |
| #13 | test_only-uuiditem_should-2827748-13.patch | 921 bytes | faline |
| #10 | uuiditem_should-2827748-10.patch | 1.76 KB | faline |
Comments
Comment #2
tstoecklerComment #3
felribeiro commentedComment #5
felribeiro commentedComment #6
tstoecklerThank you, the patch is perfect!
We now need to add a test that this works properly. I found
\Drupal\Tests\field\Kernel\String\UuidFormatterTestwhich you could use as inspiration for a newUuidItemTestwith atestRandomValue()method.Comment #8
faline commented@tstoeckler I never write a test before, but I give a try.
Could you please take a look if is this ok?
Comment #9
tstoecklerThe test looks great, very nice. And quite impressive if that's your first test!!! Nice work, @faline
Some notes:
I think we should just say "Tests the UUID field." so it still makes sense when we add some more tests to this at some point.
I know I suggested this method name, so this is my fault, but the method we are testing is
generateSampleValue()so I think the test method should betestSampleValue()(I think we can leave the UUID part out of the method name as that is in the class name).I think we shouldn't really care about saving the entity. I think
or something like that would be a more precise assertion for what we are testing here.
Comment #10
faline commented@tstoeckler thank you for your help! and thank you @felribeiro for supporting =)
I've change the test as suggestions in #9.
Please, could you take a look if it is ok?
Comment #11
faline commentedComment #12
tstoecklerPerfect, the test looks great.
In the future it would be nice if you could generate an interdiff along with your patch, so it is visible what changed between two patches. See https://www.drupal.org/documentation/git/interdiff for more information. In this case it's not that big of a deal, because the patch is pretty small, but it's considered a best practice to always provide one.
I have one super minor quibble:
This line is not indented correctly.
Also, it would be awesome if you could upload a "tests-only" patch, i.e. a patch file that only contains the added test. This will fail, but that will prove that your test actually tests what we want it to.
Thanks!
Comment #13
faline commentedSorry for that! I forgot to indent and upload the interdiff.
Follow patch, interdiff (with previous one and with #5) and also test patch only.
tks!
Comment #15
tstoecklerThat's absolutely perfect. Thank you for your persistence!
Comment #16
alexpottCommitted and pushed 759c27c to 8.3.x and 8a75749 to 8.2.x. Thanks!