There is enough common setup to warrant creating a base class for Views UI functional javascript test. Lets keep it basic for now and then we can add more stuff to it as we identify common patterns.
Steps:
- Create a base test class for Views and ViewsUI
- Move existing tests to that base class.
- Create a trait for using ViewsTestData so that can be reused across base classes
Functionality that gets moved to the base classes:
- Setting up test Views
- Setting up test data
- Setting preview auto-refresh to false
- Logging in an admin user so the ViewsUI is accessible
Comment | File | Size | Author |
---|---|---|---|
#14 | 2754171-14.patch | 25.25 KB | michielnugter |
#14 | interdiff-12-14.txt | 1.3 KB | michielnugter |
Comments
Comment #2
LendudeComment #5
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedI created a base class for views and views_ui which is used in the PreviewTest ([#863563]) conversion. I uploaded a version with the PreviewTest to prove the base class works.
Comment #6
LendudeNice! Mostly nitpicks:
No need to reference this right?
can just be an {@inheritdoc} right?
Not quite a proper docblock
Can we/should we move these to a trait?
can just be an {@inheritdoc} right?
Do we want to add the disabling of the 'auto-preview' here too? It gets disabled in most existing Views tests and could get messy when not disabled.
Comment #7
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedI converted the ViewTestBase to a trait, not 100% sure on the name and location of the trait though.
Processed all other nitpicks as well.
Patch includes the PreviewTest for now, will remove if when it's ok for RTBC.
Comment #8
LendudeStarting to look really good! Should we maybe move all the existing javascript tests over to the new test base and use them as a test case for the new base class instead of the preview test? (nice to see that green though!).
ViewTestDataSetupTrait or just ViewTestDataTrait maybe? I think the location is fine, that's where all the other traits live for now (but others might have other ideas?)
Any way to leave 'node' out of this? Really don't want to always have that enabled.
Comment #9
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedOk, bigger change in this patch.
- I created a separate base class for the views module and updated the tests there to use the new base class. Extended UITestBase on the views base class and added the UI specifics there. All tests are green on my machine
- Added $adminUserPermissions based on which a user account will be created (if enabled).
- All behavior in the constructors is configurable from the test itself.
- Renamed the trait as suggested.
- Node module was dropped by default for UITestBase. Removed it from some tests that were not using it.
- PreviewTest dropped from the patch, no extra uncommitable content in the patch anymore.
All Javascript tests in the views and views_ui modules now use the base classes.
Notes:
- There are 3 UI tests in the views module (ContextualFilterTest, FieldTest, GroupedExposedFilterTest), I think they should be moved to the views_ui module as they really only test the admin UI.
- My hands are itching to fix an incorrect comment in ContextualFilterTest:
It's not the live preview setting that is changed.. Should I open up a separate issue or can I fix it here?
Comment #10
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedComment #11
Lendude@michielnugter sweet! I really love all the red in that patch, it's really cleaning this up nicely!
Lets put both those points in follow ups, this is getting big enough as it is.
Is 'node' really needed for every Views test? That would really be a shame. I'd really be for removing it here and just adding public static $modules = ['node']; to the tests that do need it.
Instead of putting a lot of parameters on the setup method wouldn't it be better to just use class properties like you did for protected $adminUserPermissions? I think that makes it much cleaner (and less annoying to override setup())
Comment #12
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedOk, after this has been committed I'll open up follow-ups.
1. It currently really is needed but it might not be in the future, I removed it from the base test.
2. Changed it and it really cleaned up the tests, nice!
I changed the implementation for the permissions to that of the $modules variable in that it appends permissions on those of the parent class. This cleans up the tests nicely as well.
I also updated the $modules to remove duplicates. Everything is back to it's basic requirements and nothing more.
Comment #13
LendudeI think this needs to be static:: not self::, otherwise the base value is always used unless you override the method.
Other then that I think this looks great.
Comment #14
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedGood one, fixed!
Comment #15
LendudeOnce #2863267: Convert web tests of views lands we should probably also use the ViewTestDataTrait on the BrowserTestBase base class
I really like how this looks and how it cleans up all the existing tests!
Comment #16
dawehner@alexpott and myself have been wondering about the following detail: Having a base classes and many levels of traits makes it harder to figure out what is going on.
Having code duplication isn't necessarily wrong or bad, but rather sharing code for the sake of it can be bad. I would have said the base classes are maybe not needed, but the traits are helpful, given its special code. Do you have thoughts about it?
Comment #17
LendudeSorry about taking so long to answer, had a bit of a think about this, and discussed it a little bit with @michielnugter offline.
I'm inclined to agree with this. I do like the amount of duplicate code that the base classes remove, but are they NEEDED, no not really, we manage fine without them, and leaving them out gives us one less thing to maintain. (One of the things I was pondering, was that this is a bit of a deviation from how it was done before, where we had base classes everywhere, even completely empty ones, @see \Drupal\views\Tests\Handler\HandlerTestBase. Not saying that was better, just a different approach).
I agree the traits are really useful though. Great for creating Views tests build on other base classes.
And since #2863267: Convert web tests of views landed, lets use the trait on
\Drupal\Tests\views\Functional\ViewTestBase
@michielnugter maybe any more thoughts on this?
Comment #18
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedI agree with dropping the base classes for now. My reason is that it introduces yet another style of testing in core and I don't think we should do that until we all agree that it's a good idea.
I analyzed the patch and I think creating the ViewTestDataTrait is still a good idea. I think the BrowserTestBase version of ViewsTestBase should be updated to use the trait.
Further points:
Let's leave this for each test.
I think we should drop the user creation functionality and permissions definition? Just leave the user creation and login to the tests themselves.
This will make each Views UI test far less prone to random failure. Should we keep this somehow?
Comment #23
dwwBased on #17, sounds like the direction for this issue has moved on from the original title and summary. Is this still something anyone cares about doing? If so, can we refresh the scope/title/summary to match what we think still wants/needs to happen?
Thanks,
-Derek