Fix all ConfigExists constraint violations in tests

Created on 24 May 2023, over 1 year ago
Updated 31 July 2023, over 1 year ago

Problem/Motivation

Discovered in 📌 KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate Fixed .

For example:

1) Drupal\Tests\system\Kernel\Action\ActionTest::testDependencies
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for system.action.user_add_role_action.anonymous with the following errors: 0 [dependencies.config.0] The 'user.role.anonymous' config does not exist.

Steps to reproduce

Run Drupal core's test suite with 📌 KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate Fixed applied, and with the lines

      // @see \Drupal\Core\Config\Plugin\Validation\Constraint\ConfigExistsConstraint::$message
      // @todo https://www.drupal.org/project/drupal/issues/3362453
      "The '.*' config does not exist.",

removed from \Drupal\Core\Config\Schema\SchemaCheckTrait::checkConfigSchema().

Proposed resolution

Solution for the example above:

diff --git a/core/modules/system/tests/src/Kernel/Action/ActionTest.php b/core/modules/system/tests/src/Kernel/Action/ActionTest.php
index becf628e64..9bac28f573 100644
--- a/core/modules/system/tests/src/Kernel/Action/ActionTest.php
+++ b/core/modules/system/tests/src/Kernel/Action/ActionTest.php
@@ -34,6 +34,7 @@ protected function setUp(): void {
 
     $this->actionManager = $this->container->get('plugin.manager.action');
     $this->installEntitySchema('user');
+    $this->installConfig(['user']);
     $this->installSchema('system', ['sequences']);
   }

Remaining tasks

Fix all of these failures.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

📌 Task
Status

Fixed

Version

11.0 🔥

Component
Configuration 

Last updated 2 days ago

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @wim leers
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇬🇧United Kingdom ChrisDarke London

    Migrating Pittsburgh 2023 to Pittsburgh2023 tag for cleanup

  • First commit to issue fork.
  • last update over 1 year ago
    24,548 pass, 19 fail
  • @nickdickinsonwilde opened merge request.
  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    24,573 pass, 5 fail
  • last update over 1 year ago
    29,435 pass, 3 fail
  • last update over 1 year ago
    29,435 pass, 3 fail
  • Status changed to Needs work over 1 year ago
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    No longer postponed, can be rerolled.

  • last update over 1 year ago
    29,881 pass, 3 fail
  • Status changed to Needs review over 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    This is a test only change but could lead to some contrib module tests also failing if they don't install everything they need. I think this needs a Change Record, but considering this already a preliminary rtbc.

  • Assigned to wim leers
  • Status changed to Needs work over 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Still at the same exact failures from June 9, when @NickDickinsonWilde was working on this 👍

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    It appears this is surfacing that there's more missing config schema for Views — some of that was fixed fairly recently in 🐛 Missing schema for comment_link_approve views field configuration Fixed .

  • last update over 1 year ago
    29,881 pass, 3 fail
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I was wrong in #11.

    Simply also installing the comment module in TestViewsTest is sufficient to go from

    1) Drupal\Tests\views\Kernel\TestViewsTest::testDefaultConfig
    There should be no errors in configuration 'views.view.test_comment_schema'. Errors:
    Schema key views.view.test_comment_schema:display.default.display_options.fields.subject.settings.link_to_entity failed with: missing schema
    Schema key views.view.test_comment_schema:display.default.display_options.fields.approve_comment.text failed with: missing schema
    
    Failed asserting that Array &0 (
        'views.view.test_comment_schema:display.default.display_options.fields.subject.settings.link_to_entity' => 'missing schema'
        'views.view.test_comment_schema:display.default.display_options.fields.approve_comment.text' => 'missing schema'
    ) is true.
    

    to

    1) Drupal\Tests\views\Kernel\TestViewsTest::testDefaultConfig
    There should be no errors in configuration 'views.view.test_entity_translations_link'. Errors:
    Schema key views.view.test_entity_translations_link:display.default.display_options.fields.translation_link.text failed with: missing schema
    
    Failed asserting that Array &0 (
        'views.view.test_entity_translations_link:display.default.display_options.fields.translation_link.text' => 'missing schema'
    ) is true.
    

    … which just points out the next missing module: content_translation (because translation_link is provided by core/modules/content_translation/config/schema/content_translation.views.schema.yml.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    In HEAD, TestViewsTest checks config schema of the following test views:

    views.view.test_view_block
    views.view.test_view_block2
    views.view.test_view_block_with_context
    views.view.test_block_content_redirect_destination
    views.view.test_block_content_revision_id
    views.view.test_block_content_revision_revision_id
    views.view.test_block_content_revision_user
    views.view.test_block_content_view
    views.view.test_field_filters
    views.view.test_field_type
    views.view.test_book_view
    views.view.test_comment
    views.view.test_comment_count
    views.view.test_comment_field_name
    views.view.test_comment_operations
    views.view.test_comment_row
    views.view.test_comment_rss
    views.view.test_comment_schema
    views.view.test_comment_user_uid
    views.view.test_new_comments
    views.view.test_contact_link
    views.view.test_entity_translations_link
    views.view.test_argument_datetime
    views.view.test_exposed_filter_datetime
    views.view.test_filter_datetime
    views.view.test_sort_datetime
    views.view.dblog_integration_test
    views.view.test_dblog
    views.view.test_view_field_delete
    views.view.test_view_fieldapi
    views.view.file_extension_view
    views.view.test_forum_index
    views.view.test_image_user_image_data
    views.view.test_link_tokens
    views.view.test_media_revision_uid
    views.view.test_argument_node_uid_revision
    views.view.test_contextual_links
    views.view.test_filter_node_access
    views.view.test_filter_node_uid_revision
    views.view.test_language
    views.view.test_nid_argument
    views.view.test_node_bulk_form
    views.view.test_node_path_plugin
    views.view.test_node_revision_id_argument
    views.view.test_node_revision_links
    views.view.test_node_revision_nid
    views.view.test_node_revision_timestamp
    views.view.test_node_revision_uid
    views.view.test_node_revision_vid
    views.view.test_node_row_plugin
    views.view.test_node_tokens
    views.view.test_node_view
    views.view.test_node_views_analyze
    views.view.test_status_extra
    views.view.test_options_list_argument_numeric
    views.view.test_options_list_argument_string
    views.view.test_options_list_filter
    views.view.test_excluded_field_token_display
    views.view.test_field_counter_display
    views.view.test_serializer_display_entity
    views.view.test_serializer_display_entity_translated
    views.view.test_serializer_display_field
    views.view.test_serializer_node_display_field
    views.view.test_serializer_node_exposed_filter
    views.view.test_serializer_shared_path
    views.view.test_statistics_integration
    views.view.test_entity_reference_entity_test_mul_view
    views.view.test_entity_reference_entity_test_view
    views.view.test_entity_reference_entity_test_view_long
    views.view.test_entity_reference_group_by_empty_relationships
    views.view.test_entity_reference_reverse_entity_test_mul_view
    views.view.test_entity_reference_reverse_entity_test_view
    views.view.taxonomy_all_terms_test
    views.view.taxonomy_default_argument_test
    views.view.test_argument_taxonomy_index_tid_depth
    views.view.test_argument_taxonomy_vocabulary
    views.view.test_filter_taxonomy_index_tid
    views.view.test_filter_taxonomy_index_tid__non_existing_dependency
    views.view.test_filter_taxonomy_index_tid_depth
    views.view.test_groupwise_term
    views.view.test_taxonomy_exposed_grouped_filter
    views.view.test_taxonomy_name_argument
    views.view.test_taxonomy_node_term_data
    views.view.test_taxonomy_parent
    views.view.test_taxonomy_term_name
    views.view.test_taxonomy_term_relationship
    views.view.test_taxonomy_tid_field
    views.view.test_taxonomy_vid_field
    views.view.test_term_show_entity
    views.view.test_tracker_user_uid
    views.view.test_access_perm
    views.view.test_access_role
    views.view.test_field_permission
    views.view.test_filter_current_user
    views.view.test_filter_permission
    views.view.test_groupwise_user
    views.view.test_plugin_argument_default_current_user
    views.view.test_user_bulk_form
    views.view.test_user_bulk_form_combine_filter
    views.view.test_user_changed
    views.view.test_user_data
    views.view.test_user_fields_access
    views.view.test_user_name
    views.view.test_user_relationship
    views.view.test_user_roles_rid
    views.view.test_user_uid_argument
    views.view.test_view_argument_validate_user
    views.view.test_view_argument_validate_username
    views.view.test_views_handler_field_role
    views.view.test_views_handler_field_user_name
    views.view.base_and_revision
    views.view.computed_field_view
    views.view.entity_test_fields
    views.view.entity_test_row
    views.view.node_id_argument
    views.view.numeric_test
    views.view.test_access_none
    views.view.test_aggregate_count
    views.view.test_aggregate_count_function
    views.view.test_ajax_view
    views.view.test_alias
    views.view.test_area_messages
    views.view.test_area_order
    views.view.test_area_result
    views.view.test_area_title
    views.view.test_area_view
    views.view.test_argument
    views.view.test_argument_date
    views.view.test_argument_default_current_user
    views.view.test_argument_default_fixed
    views.view.test_argument_default_node
    views.view.test_argument_default_query_param
    views.view.test_argument_dependency
    views.view.test_argument_transform_term
    views.view.test_argument_validation
    views.view.test_argument_validator_term
    views.view.test_attached_disabled
    views.view.test_attachment_ui
    views.view.test_block_exposed_ajax
    views.view.test_block_exposed_ajax_with_page
    views.view.test_boolean_grouped_filter_view
    views.view.test_cache
    views.view.test_click_sort
    views.view.test_click_sort_ajax
    views.view.test_content_ajax
    views.view.test_destroy
    views.view.test_disabled_display
    views.view.test_display
    views.view.test_display_attachment
    views.view.test_display_defaults
    views.view.test_display_empty
    views.view.test_display_entity_reference
    views.view.test_display_feed
    views.view.test_display_invalid
    views.view.test_display_more
    views.view.test_distinct_click_sorting
    views.view.test_dropbutton
    views.view.test_duplicate_field_handlers
    views.view.test_entity_area
    views.view.test_entity_field_renderered_entity
    views.view.test_entity_field_renderers
    views.view.test_entity_multivalue_basefield
    views.view.test_entity_operations
    views.view.test_entity_row
    views.view.test_entity_row_renderers
    views.view.test_entity_row_renderers_revisions_base
    views.view.test_entity_test_link
    views.view.test_entity_test_protected_access
    views.view.test_entity_type_filter
    views.view.test_example_area
    views.view.test_example_area_access
    views.view.test_executable_displays
    views.view.test_exposed_admin_ui
    views.view.test_exposed_block
    views.view.test_exposed_form_buttons
    views.view.test_exposed_form_checkboxes
    views.view.test_exposed_form_pager
    views.view.test_exposed_form_sort_items_per_page
    views.view.test_exposed_relationship_admin_ui
    views.view.test_feed_icon
    views.view.test_field_alias_test
    views.view.test_field_argument_tokens
    views.view.test_field_body
    views.view.test_field_classes
    views.view.test_field_config_translation_filter
    views.view.test_field_entity_test_rendered
    views.view.test_field_field_attachment_test
    views.view.test_field_field_complex_test
    views.view.test_field_field_revision_complex_test
    views.view.test_field_field_revision_test
    views.view.test_field_field_test
    views.view.test_field_get_entity
    views.view.test_field_get_entity_null
    views.view.test_field_header
    views.view.test_field_output
    views.view.test_field_tokens
    views.view.test_filter
    views.view.test_filter_date_between
    views.view.test_filter_group_override
    views.view.test_filter_groups
    views.view.test_filter_in_operator_ui
    views.view.test_filter_placeholder_text
    views.view.test_form_multiple
    views.view.test_get_attach_displays
    views.view.test_glossary
    views.view.test_grid
    views.view.test_grid_responsive
    views.view.test_group_by_count
    views.view.test_group_by_count_multicardinality
    views.view.test_group_by_field_not_within_bundle
    views.view.test_group_by_in_filters
    views.view.test_group_rows
    views.view.test_groupwise_term_ui
    views.view.test_handler_relationships
    views.view.test_handler_test_access
    views.view.test_history
    views.view.test_http_status_code
    views.view.test_invalid_tokens
    views.view.test_latest_revision_filter
    views.view.test_latest_translation_affected_revision_filter
    views.view.test_link_base_links
    views.view.test_menu_link
    views.view.test_mini_pager
    views.view.test_mini_pager_ajax
    views.view.test_month_date_plugin
    views.view.test_page_display
    views.view.test_page_display_arguments
    views.view.test_page_display_menu
    views.view.test_page_display_path
    views.view.test_page_display_route
    views.view.test_page_view
    views.view.test_pager_full
    views.view.test_pager_full_ajax
    views.view.test_pager_none
    views.view.test_pager_some
    views.view.test_plugin_dependencies
    views.view.test_preprocess
    views.view.test_preview
    views.view.test_preview_error
    views.view.test_redirect_view
    views.view.test_relationship_dependency
    views.view.test_remember_selected
    views.view.test_row_render_cache
    views.view.test_row_render_cache_none
    views.view.test_search
    views.view.test_simple_argument
    views.view.test_store_pager_settings
    views.view.test_style_html_list
    views.view.test_style_mapping
    views.view.test_summary
    views.view.test_table
    views.view.test_tag_cache
    views.view.test_taxonomy_glossary
    views.view.test_token_view
    views.view.test_tokens
    views.view.test_ungroup_rows
    views.view.test_user_path
    views.view.test_user_role_contextual_filter
    views.view.test_view
    views.view.test_view_argument_validate_numeric
    views.view.test_view_broken
    views.view.test_view_delete
    views.view.test_view_display_template
    views.view.test_view_embed
    views.view.test_view_empty
    views.view.test_view_entity_test
    views.view.test_view_entity_test_additional_base_field
    views.view.test_view_entity_test_data
    views.view.test_view_entity_test_revision
    views.view.test_view_handler_weight
    views.view.test_view_pager_full_zero_items_per_page
    views.view.test_view_render
    views.view.test_view_sort_translation
    views.view.test_view_status
    views.view.test_view_storage
    views.view.test_views_groupby_save
    views.view.test_access_static
    views.view.formatter_timestamp_as_time_diff
    

    I verified that the exact same set of test views is being validated after the patch too.

    Then I went ahead and figured out what the missing config is for each, but in many cases the necessary config is created in a specific test 😬 So I had to simulate recreating it exactly.

    This is obviously non-ideal, but then again, \Drupal\Tests\views\Kernel\TestViewsTest is a highly unusual test. This is AFAICT the best possible solution: keep all existing tests unchanged, and do whatever it takes to make this one unusual test pass.

  • last update over 1 year ago
    29,882 pass, 2 fail
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I eventually found a work-around. But I lost an hour over this.

    Now that I can run functional JS tests, I see that this is the output LayoutBuilderOptInTest is crashing on:

    Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for core.entity_view_display.node.before.default with the following errors: 0 [dependencies.config.1] The 'field.field.node.before.layout_builder__layout' config does not exist. in Drupal\Core\Config\Development\ConfigSchemaChecker->onConfigSave() (line 94 of core/lib/Drupal/Core/Config/Development/ConfigSchemaChecker.php).
    
  • Assigned to tim.plunkett
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    This is AFAICT a bug in Layout Builder.

    \Drupal\layout_builder\Form\LayoutBuilderDisableForm::submitForm() does:

        $this->sectionStorage->disableLayoutBuilder()->save();
        $this->layoutTempstoreRepository->delete($this->sectionStorage);
    

    That first line indeed disables the use of layout builder in this particular entity view display, but upon saving it (at \Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage::save()), there's still a config dependency on field.field.node.before.layout_builder__layout.


    It appears to be happening in \Drupal\Core\Entity\EntityDisplayBase::calculateDependencies(), specifically:

        // If field.module is enabled, add dependencies on 'field_config' entities
        // for both displayed and hidden fields. We intentionally leave out base
        // field overrides, since the field still exists without them.
        if (\Drupal::moduleHandler()->moduleExists('field')) {
          $components = $this->content + $this->hidden;
          $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
          foreach (array_intersect_key($field_definitions, $components) as $field_definition) {
            if ($field_definition instanceof ConfigEntityInterface && $field_definition->getEntityTypeId() == 'field_config') {
              $this->addDependency('config', $field_definition->getConfigDependencyName());
            }
          }
        }
    

    Assigning to @tim.plunkett for ideas …

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Oh, and you can sprinkle

    $this->assertSame(['field.field.node.before.body', 'node.type.before'], $this->config('core.entity_view_display.node.before.default')->get('dependencies.config'));
    

    all over and you'll never even get to see that field.field.node.before.layout_builder__layout dependency — it really is being added only at that time!

  • 🇺🇸United States tim.plunkett Philadelphia

    tim.plunkett made their first commit to this issue’s fork.

  • last update over 1 year ago
    29,885 pass
  • last update over 1 year ago
    29,885 pass
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Perfect! 🤩

    Thanks so much, @tim.plunkett!

  • Status changed to RTBC over 1 year ago
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    This looks great, the fixes here are actually quite simple.

  • Assigned to wim leers
  • Status changed to Needs work over 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    @lauriii posted an excellent question on the merge request, and in answering that I realized that a simpler solution is possible — stay tuned!

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Done.

    I believe now every question about

    • a module being installed
    • a module's default config being installed
    • additional config being created

    is being answered by a comment explaining why and pointing to at least one of the views that make it necessary.

  • last update over 1 year ago
    29,886 pass
  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Appears all threads have been resolved.

  • last update over 1 year ago
    29,908 pass
    • lauriii committed ad25f53a on 11.x
      Issue #3362453 by NickDickinsonWilde, Wim Leers, tim.plunkett, borisson_...
  • Status changed to Fixed over 1 year ago
  • 🇫🇮Finland lauriii Finland

    Committed ad25f53 and pushed to 11.x. Thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024