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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lendude created an issue. See original summary.

Lendude’s picture

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

michielnugter’s picture

Status: Active » Needs review
Issue tags: +DevDaysSeville
FileSize
12.67 KB
4 KB

I 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.

Lendude’s picture

Status: Needs review » Needs work

Nice! Mostly nitpicks:

  1. +++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
    @@ -0,0 +1,84 @@
    + * @see \Drupal\simpletest\WebTestBase
    

    No need to reference this right?

  2. +++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
    @@ -0,0 +1,84 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    

    can just be an {@inheritdoc} right?

  3. +++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
    @@ -0,0 +1,84 @@
    +  /**
    +   * @param bool $import_test_views
    +   */
    +  protected function setUp($import_test_views = TRUE) {
    

    Not quite a proper docblock

  4. +++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
    @@ -0,0 +1,84 @@
    +  protected function enableViewsTestModule() {
    ...
    +  protected function schemaDefinition() {
    ...
    +  protected function viewsData() {
    ...
    +  protected function dataSet() {
    

    Can we/should we move these to a trait?

  5. +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/UITestBase.php
    @@ -0,0 +1,52 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    

    can just be an {@inheritdoc} right?

  6. +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/UITestBase.php
    @@ -0,0 +1,52 @@
    +  protected function setUp($import_test_views = TRUE) {
    

    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.

michielnugter’s picture

Status: Needs work » Needs review
FileSize
14.68 KB
12.64 KB

I 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.

Lendude’s picture

Starting 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!).

  1. +++ b/core/modules/views/src/Tests/ViewCreationTrait.php
    @@ -0,0 +1,60 @@
    +trait ViewCreationTrait {
    

    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?)

  2. +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/UITestBase.php
    @@ -0,0 +1,70 @@
    +  public static $modules = ['node', 'views', 'views_test_config', 'views_ui'];
    

    Any way to leave 'node' out of this? Really don't want to always have that enabled.

michielnugter’s picture

Ok, 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:

    // Disable automatic live preview to make the sequence of calls clearer.
    \Drupal::configFactory()->getEditable('views.settings')->set('ui.show.advanced_column', TRUE)->save();

It's not the live preview setting that is changed.. Should I open up a separate issue or can I fix it here?

michielnugter’s picture

Lendude’s picture

Issue summary: View changes

@michielnugter sweet! I really love all the red in that patch, it's really cleaning this up nicely!

Should I open up a separate issue or can I fix it here?

Lets put both those points in follow ups, this is getting big enough as it is.

  1. +++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
    @@ -0,0 +1,62 @@
    +  public static $modules = ['node', 'views', 'views_test_config'];
    

    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.

  2. +++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
    @@ -0,0 +1,62 @@
    +  protected function setUp($import_test_views = TRUE, $create_user = TRUE) {
    
    +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/UITestBase.php
    @@ -0,0 +1,63 @@
    +  protected function setUp($import_test_views = TRUE, $enable_test_views_module = TRUE, $disable_auto_preview = TRUE, $create_user = TRUE) {
    

    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())

michielnugter’s picture

Ok, 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.

Lendude’s picture

+++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
@@ -0,0 +1,83 @@
+    if (self::$createUser) {

+++ b/core/modules/views_ui/tests/src/FunctionalJavascript/UITestBase.php
@@ -0,0 +1,66 @@
+    if (self::$enableTestViewsModule) {
...
+    if (self::$disableAutoPreview) {

I 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.

michielnugter’s picture

Good one, fixed!

Lendude’s picture

Title: Create a ViewsUIFunctionalJavascriptTestBase class » Create a Views and ViewsUI FunctionalJavascriptTestBase class
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Once #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!

dawehner’s picture

@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?

Lendude’s picture

Status: Reviewed & tested by the community » Needs work

Sorry about taking so long to answer, had a bit of a think about this, and discussed it a little bit with @michielnugter offline.

I would have said the base classes are maybe not needed, but the traits are helpful, given its special code.

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?

michielnugter’s picture

I 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:

  1. +++ b/core/modules/views/tests/src/FunctionalJavascript/ViewTestBase.php
    @@ -0,0 +1,83 @@
    +    ViewTestData::createTestViews(get_class($this), ['views_test_config']);
    

    Let's leave this for each test.

  2. +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/UITestBase.php
    @@ -0,0 +1,66 @@
    +  public static $adminUserPermissions = [
    +    'administer views',
    +  ];
    

    I think we should drop the user creation functionality and permissions definition? Just leave the user creation and login to the tests themselves.

  3. +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/UITestBase.php
    @@ -0,0 +1,66 @@
    +    if (static::$disableAutoPreview) {
    +      \Drupal::configFactory()
    +        ->getEditable('views.settings')
    +        ->set('ui.always_live_preview', FALSE)
    +        ->save();
    +    }
    

    This will make each Views UI test far less prone to random failure. Should we keep this somehow?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

dww’s picture

Based 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

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.