Problem/Motivation
Multiple tests are using the language configuration forms to change the configuration.
Except for a few exceptions that are actually testing those forms, for all the rest that is not really needed.
Steps to reproduce
One way to find instances of this is to use the following command.
$ git grep -e 'admin/config/regional/content-language' --and -e 'drupalGet' | wc -l
28
Naturally, removing the last part shows exactly where the instances are.
Proposed resolution
Change tests using language forms to change language settings to use API calls directly when the test is not testing the language forms.
Use re-usable code for that configuration manipulation, e.g. traits.
Remaining tasks
Review.
User interface changes
N.A.
API changes
Two new traits are introduced to help tests that want to change language configuration.
LanguageTestTrait, providing methods general tolanguagemodule.ContentTranslationTestTrait, extending the previous trait to makecontent_translationmodule related configuration changes.
Data model changes
N.A.
Release notes snippet
N.A.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3384936
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joachim commentedComment #3
vbouchetComment #4
smustgrave commentedThis is a larger file but see a few other instances we could probably replace. Probably a few more then the ones I posted.
Comment #5
vbouchetI will give a check. As the ticket title mentioned "to setup language", I restricted my check to this only.
Comment #6
vbouchetFrom my point of view, the others form submit look legit as they serve the purpose of the tests (testing the moderation form).
Comment #7
smustgrave commentedBut it’s not really asserting anything. It’s just going to the node edit form to update a state. Think that could be done directly on the node and saved without visiting the form.
Comment #8
smustgrave commentedCan see if the committers want to change it. Could argue it's out of scope slightly but seems like small enough changes to me.
Comment #9
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #10
smustgrave commentedThis only had one patch so think it's clear what was reviewed.
Comment #11
xjmComment #12
xjmI agree that the language configuration form is not what's under test, so it makes sense to do this with the API.
That said, there's also an entire freaking container rebuild after these lines, which is even more expensive. Makes one question if this should be done inside the test method at all?
It's also super a lot of API calls in a row for a single test method, and something that it seems like a single test trait or the like should provide.
Finally, I reviewed a different issue that was around lines with the same form-based translation setup in a test of not-the-translation-form elsewhere. In fact, core uses this exact pattern in 26 other places:
So, if we're fixing this one spot, we should probably fix all the rest as well, in a consistent way. We should check whether there is an existing trait to set up a language via the API with a single method call, and if not, add one. We also should have that happen in
setUp()rather than individual test methods. (We might need to split up some tests if there are other methods in the same class not requiring a language.)NW to expand the scope of this. Thanks!
Comment #13
joachim commented> That said, there's also an entire freaking container rebuild after these lines, which is even more expensive. Makes one question if this should be done inside the test method at all?
Doing it via the form incurs a container rebuild as well AFAIK -- the container has to be set to be multilingual.
> So, if we're fixing this one spot, we should probably fix all the rest as well, in a consistent way. We should check whether there is an existing trait to set up a language via the API with a single method call, and if not, add one. We also should have that happen in setUp() rather than individual test methods. (We might need to split up some tests if there are other methods in the same class not requiring a language.)
There are separate issues. The places to change this were identified in #3355787: Identify which browser tests should be running the language settings form and add a @covers to document it.
Comment #14
xjmOne issue per file is not the correct way to scope this. It needs an API.
As a Drupal core release manager, I have discretion over issue scope, so please don't revert my scoping decisions.
I will comment on #3305376: [Meta] Perform set-up tasks in Browser tests using API calls rather than browser requests.
Comment #15
xjmComment #18
marvil07 commentedI have started with the patch at #3 as the initial commit.
@xjm, I have started to follow the suggestion to use something separate to unify these groups of API calls.
Currently, it is using traits on the test namespace, but if enough useful and generalizable enough, it may become an actual new API surface.
Keeping it on the trait, since it may not be generic enough now.
I have been changing the code added on related issues, i.e. #3355604: ContentTranslationLanguageChangeTest should perform setup tasks using API calls not form submissions, #3384935: ContactLanguageTest should use API to set up language, #3385837: PathContentModerationTest should use API to set up language, and #3385834: MenuUiNodeTest should use API to set up language; since those cases are not matching the grep.
I also included changes from #3385815: ImageOnTranslatedEntityTest should use API to set up language, and then modified them to use the created traits.
New commits on new 3384936-use-lang-api-instead-of-form topic branch and related new MR #5485 created with the following commits.
- bf992c5553 #3384936-3: Use API to set up languages in ModerationFormTest test
- ec28e72357 Add a language trait helper
- 9709759d3b Start using the language trait on ModerationFormTest
- b01c84b5ad Add enable bundle translation helper to language trait
- 6317ec7a73 Add a content translation test trait helper, extending language test trait helper
- 589ae61595 Move content translation manager actions to the content translation test trait
- e0edafbf50 Use content translation test trait on MenuUiNodeTest
- 1560fb1410 Use content translation test trait on PathContentModerationTest
- 965cfbfcc1 Use language test trait on ContactLanguageTest
- 101a903ac4 Use content translation test trait on ContentTranslationLanguageChangeTest
- 799c1d49e5 Apply patch from #3385815-4 by vbouchet, ayush.khare: ImageOnTranslatedEntityTest should use API to set up language
- 3dffbc3a33 Use content translation test trait on ImageOnTranslatedEntityTest
- e41d0c318a Add a helper to set a field translation status on tests
- 42cf800493 Use new setFieldTranslatable method on ImageOnTranslatedEntityTest
- 0a757c5fee Use language test trait on ContentTranslationUntranslatableFieldsTest
- 95df2e0802 Fix phpcs issues on changed lines :sweat_smile:
- b3fe756f21 Use content translation test trait on ModerationContentTranslationTest
- 8dd7b2b5af Use content translation test trait on ModerationLocaleTest
- 3d2ae9633c Use content translation test trait on ContentTranslationContextualLinksTest
- 474a791068 Use content translation test trait on EntityReferenceFieldTranslatedReferenceViewTest
- aeec7bc391 Remove unused use statement
Changes are growing, but they still feel similar.
Also, many of the grep matches are actually relevant to be using the UI, most of the set at
core/modules/content_translation/tests/src/Functional/\*Test.php.Here an alternative grep, via git.
The missing match at
EntityReferenceFieldTranslatedReferenceViewTestis a disable translation case.I have not yet figured out the right way TM to do it correctly via API, suggestions are welcomed.
Next steps are likely to continue wit the list above starting at
FileOnTranslatedEntityTest.Comment #19
marvil07 commentedComment #20
joachim commented> Also, many of the grep matches are actually relevant to be using the UI, most of the set at core/modules/content_translation/tests/src/Functional/\*Test.php.
The tests that make a form submission of that page as part of testing the actual form were identified and marked with a @covers annotation.
Comment #21
marvil07 commented@joachim, thanks for mentioning that!
It was useful to be more confident on where to change things.
I only see now that you actually linked to #3355787: Identify which browser tests should be running the language settings form and add a @covers to document it on comment #13 above.
I think I got to the end of the list!
The missing set of matches are relevant to keep for the following reasons.
ContentTranslationDisableSettingTest,ContentTranslationEnableTest,ContentTranslationSettingsTest,ContentTranslationUISkipTest: they are expected to use the UI, as identified on its covers annotation, added at #3355787: Identify which browser tests should be running the language settings form and add a @covers to document it.EntityTypeWithoutLanguageFormTestandLanguageSelectorTranslatableTestare actually the same case, but they were not annotated. The first is checking hiding behavior of the form, and the second is checking the behavior of the setting page translated and when the content_translation module is not installed.ContentTranslationSyncImageTestis using the form to verify if translation synchronization has been saved correctly, and it is actually testing that feature, which is implemented oncontent_translation_form_language_content_settings_submit(), extending that is setup from\_content_translation_form_language_content_settings_form_alter, so I added a covers annotation instead, following the pattern from other cases like this.Changes from the original point are not few, but highly related, so it likely made sense to follow @xjm suggestion from comment #12.
Locally I have seen some performance improvements on most of the changed tests.
I did not made a fully performance review, but I have seen 3s improvements on multiple tests, which is great.
New commits on 3384936-use-lang-api-instead-of-form topic branch and related MR #5485 are the following.
- 8a461eeb03 Add a way to disable a given entity bundle translation from the language test trait
- 70d76a317c Use language translation test trait on ContentTranslationOperationsTest
- 08b4010835 Use disableBundleTranslation on EntityReferenceFieldTranslatedReferenceViewTest
- 0b1a618951 Use content translation test trait on FileOnTranslatedEntityTest
- b006797e17 Use content translation test trait on PrivateFileOnTranslatedEntityTest
- 4c178eff02 Use language test trait on LanguageSelectorTranslatableTest
- 091254e831 Use language test trait on MenuUiContentTranslationTest
- 8b6f4ecfe1 Use language test trait on NodeTranslationUITest
- 63124ebc88 Skip UI on node article translation setup for NodeTranslationUITest
- 18b99dbda8 Use content translation test trait on PathLanguageTest
- 283a4a7099 Use content translation test trait on DisplayFeedTranslationTest
- b56db49d11 Use language test trait on SearchMultilingualTest
- 3972484183 Use content translation test trait on PathWorkspacesTest
- 5bb538b3dd Use content translation test trait on RouteCachingLanguageTest
- f3cb974759 Use content translation test trait on ContentTranslationContextualLinksTest
- 2f650a931e Add covers pointing to content language settings form on EntityTypeWithoutLanguageFormTest
- 29faaea3f6 Add covers pointing to content language settings form on LanguageSelectorTranslatableTest
- bda937f13b Add covers pointing to relevant form alter on ContentTranslationSyncImageTest
At this point, this is ready for review, marking it accordingly on the issue status.
Comment #22
smustgrave commentedNot fully reviewed but proposed solution mentions changing API but API changes section is empty.
Also believe with an API change a change record needed to be included.
Comment #23
marvil07 commented@smustgrave, indeed the IS really needed an update, now changed.
Right, I have just created a related change record at New traits to modifying language configuration during testing.
Comment #24
smustgrave commentedThanks! CR reads fantastic
Refactor of the tests seem to have broken anything so think this should be good to go.
Comment #25
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #26
marvil07 commentedI manually tried to merge from mainline, i.e. 11.x, into the topic branch, no merge conflicts.
I also tried the other way around, merging the topic branch into mainline, and no merge conflict there either.
I am moving the issue back to its previous state, and the "no-needs-review-bot" tag to avoid the bot.
Comment #27
marvil07 commentedAdding an extra tag, given the indirect improvement I noticed locally over the time to run for multiple of the changed tests.
Comment #28
xjmSaving reviewer credits.
Comment #30
xjmGreat work and research on this.
I made some changes to the CR to better describe when the traits should be used. (I also removed the verbose method list since the example code explains it better anyway.)
Tagging for FM review of the proposed API design.
Meanwhile, I posted a number of minor things to fix on the MR.
Thanks again!
Comment #31
marvil07 commented@xjm, thanks for the thorough review 👍
I appreciate a lot that you used the suggestions feature in gitlab for the set of direct syntactic/semantic suggestion.
I see the related change mentioned about strict typing in trait at b70dfff449a278e2248f42dc5bd6623093c41e0e.
It is nice to see that pattern starting to make its way into core.
I have modified the topic branch to have clear type hints, along with declaring strict typing on the new traits.
I also added a few small changes here and there, trying to use a bit more the added traits.
I added a follow-up about the to-do item in the added code at #3408046: API to disable bundle translation in one operation.
The following commits were added.
- 1f6db0a809 Add some extra type hints
- 64f7f64292 Improve syntax on multiple new docblocks
- e7d677b53c Improve two docblock parameter type docs
- 56a07e912b Get strict types declaration on traits from mainline
- 490f463719 Fix a couple LanguageTestTrait return values
- c6c4bf7d03 Use strict types on the new test traits
- 4e745b61fb Use static keyword to call new traits static methods
- 30a347274d Use create language trait method a bit more
- 5ed5cc94db Unify a couple of comments
- a7f5cbaeaf fix typo
- 05bc830064 Link follow-up on one-operation entity language disable
Back to NR now.
Comment #32
catchHard to quantify, but this may be knocking as much as thirty seconds off NodeTranslationUiTest, which is also one of the very slowest functional tests:
https://git.drupalcode.org/project/drupal/-/jobs/561732
vs.
https://git.drupalcode.org/issue/drupal-3384936/-/jobs/471819
Bumping to major.
Also looks like we could make NodeTranslationUiTest use the testing profile - is there already an issue for that?
Comment #33
smustgrave commentedBrought this up in #needs-review-queue-initative channel and @catch said the approach seems good enough for an outside reivew. Going to leave tag for now.
Applying the MR and searched for $this->drupalGet('admin/config/regional/content-language and found 12 instances now. But reviewing those they appear to be checking settings and the form itself, so valid.
Comment #36
catchThis looks great. Makes things a lot more concise as well as the speed-up. Committed/pushed to 11.x and cherry-picked to 10.2.x, thanks!
Comment #37
quietone commentedPublish the CR