- Make sure we can submit the form successfully (#2584627: Autocomplete for search entity doesn't work in RC1)
- Ensure the entity type cannot be changed once a button has been saved (#2587659: Should not be possible to change entity type of a button after it has been created)
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | 2587667-23.patch | 5.91 KB | wim leers |
| #23 | interdiff.txt | 1.82 KB | wim leers |
| #22 | entity-embed-button-creation-test-2587667-22.patch | 5.73 KB | oknate |
| #22 | 2587667-interdiff--17-22.txt | 5.42 KB | oknate |
Comments
Comment #2
dave reidComment #3
wim leersSimilar to #2560787-3: Add tests for entity access.
Comment #4
wim leersNo longer postponed, since #2328659: Convert all existing entity_embed tests from WebTestBase to BrowserTestBase landed a long time ago.
Note that #2466013: Write test for CKEditor integration already added test coverage for using an Entity Embed button: for configuring it for use in CKEditor. See
\Drupal\Tests\entity_embed\FunctionalJavascript\CKEditorIntegrationTest::testIntegration().But this issue is about having tests to verify that the UI at
/admin/config/content/embedis working.Comment #5
wim leersComment #6
oknateI can work on this.
Comment #7
wim leersThanks for stepping up, but I think this is definitely of lesser importance. This is not something that's negatively impacting anybody today, and even when it breaks, it would only affect administrators, not end users.
So: decreasing priority.
I'd much prefer to contribute your valuable and much valued time on issues with higher impact :)
Comment #8
oknateOK, I enjoy writing the functional javascript tests. But I agree this won't get us closer to the goal of media embeds in core.
Comment #9
wim leersIf you enjoy it, feel free to do this of course :D But #3022768: Validate that `alt` and `title` are required attributes for `<drupal-entity>`, and ensure they're added by default for example would have a far higher impact on the community!
Comment #10
oknateYes, I think #2924391: [media entities] Regardless of @EntityEmbedDisplay plugin, Media entities representing a `image/*` MIME type should be able to have a per-embed `alt` and `title` would be a good one to focus on next.
Comment #11
wim leersEhm, yes, that's the one I wanted to link! 😅
Comment #12
oknateI started working on this. I ran into two issues so far:
1) The ajax request that returns the entities fails on testbot. I'm not sure if it's testbot or my config. For now I threw in a hack to continue. The bug is hard to identify, but I'm getting a headers too large error. If I reduce the number of config entities passed to ::getDefinitionOptionsForEntityType() it works. So I think it has to do with something in the testbot configuration.
2) There is a schema error related to entity browser.
I want to document this before I continue, so here's a patch demonstrating the schema error.
Comment #14
oknateThis fixes the schema error. It's just that entity_browser_settings has to be an empty array instead of NULL.
Also, I realize this test won't work on testbot yet, because I was building it on top of the test module in 2924391.
Comment #15
oknateUpdated to verify that when reopening the form, the embed type and entity type fields are disabled.
Also, since I was doing the same thing with slight variations, I added a loop to reduce code duplication.
The one known issue, which is a blocker, is that I'm using a hack to remove the config entities. Without that the test fails. See #12.1 above.
Comment #16
oknateI found a workaround for #12.1 that isn't a hack. While I still don't know what the underlying issue was, I noticed that it was processing parts of the for loop that were unnecessary if the first condition was met. Each condition, when met runs this:
So there's no reason to run the other two conditions if the first is met, and no reason to run the third if the second is met. Perfect situation for some "elseif" conditions.
When I added elseif statements, the failure went away.
Secondly, I accidentally left a sleep() call in my for loop (for testing purposes). The testbot execution in #15 took 40 minutes because of this. Oops!
Comment #17
wim leersComment #18
phenaproximaThis looks really nice, but I have some questions and comments here.
FormStateInterface::getValue() can return a default argument, so this can be collapsed down to one line:
$form_state->setValue('entity_browser_settings', $form_state->getValue('entity_browser_settings', []));Changing from 'if' to 'elseif' is a subtle, but potentially significant, change in logic. if/elseif is basically "case 1 or case 2, but not both", whereas if/if is "case 1 and/or case 2".
Which means the test coverage needs to account for all possible cases. Maybe I'm being overly paranoid here, but I thought I'd point that out.
Nit: $view_mode_storage is not really needed; this can all be one single chain of calls. $this->container->get()->getStorage()->create()->save()
Why is this needed?
Nit: It's a bit more readable to do $page = $this->getSession()->getPage() at the top of the method, then call methods like $page->fillField() and $page->selectFieldOption(). It's cleaner than using $this->assertSession(), and will throw nice exceptions if there are problems.
JsWebAssert::waitForField() returns NULL if the element is not found, so you need to do something like this to prevent potential fatal errors:
Comment #19
oknateFor #18 2, while in general I agree that three ifs do not equal an if and two elseifs, I think in this case they're equivalent, since they perform the same code
Since the operations within the second two conditions do the same thing as the first, if the first condition is met, you can safely skip the second two conditions.
Also if the first condition is not met, but the second condition is met, you can skip the third condition. Having the same line of code within three if statements is essentially the same here as creating an if with two elseifs.
Have I missed something?
Comment #20
oknateFor #18 4, I was originally extending the test base and installing entity_embed_test module, which installed some buttons. I think I can drop this code. Entity Embed has a suggested config for an entity_embed button with name 'node', but I can rework the code so I don't need to delete the existing buttons.
Comment #21
oknateThank you for the review @phenaproxima. Very helpful. I will get a chance to update the patch tonight.
Comment #22
oknateThanks for the dataprovider change in #17, @wimleers. That's cool. It counts as four tests now instead of one!
Responses to @phenaproxima's review in #18:
Comment #23
wim leersThanks, @phenaproxima and @oknate!
80 cols nit.
This change made all these arguments optional, even though they aren't optional.
Comment #25
wim leers🚢
WRT #18.2: this could also just have been expressed by OR'ing all the conditions together and only having a single branch body, since all three branch bodies are identical anyway. That's why the
elseifalready is an improvement: it doesn't try re-executing the same branch body multiple times if a particular entity type matches multiple of the possible reasons for it to be executed. Committed as-is since it's already an improvement anyway.Comment #26
oknateSince there were comments on each condition and the conditions were many characters, I felt leaving the multiple lines was more readable than one big condition.
Comment #27
wim leersYep, I'm just saying that some will probably find that easier to read. I think this is really just a minor matter of preference, which is why I didn't want to spend more brain cycles on this :)
Comment #28
oknateYes! On to the more interesting challenges.