Issue #3586455: Add kernel tests for requirements hook, entity item cache...

Description

Adds kernel test coverage for four areas of the ai_context module that had no automated tests in 1.0.x:

  1. ai_context_requirements() hook (AiContextRequirementsTest) — verifies that non-runtime phases return empty, that a site with the bundled ai_context_editorial workflow passes, and that a site with no content-moderation workflow covering ai_context_item returns REQUIREMENT_WARNING.
  2. AiContextEntityItemCacheContext (AiContextEntityItemCacheContextTest) — verifies getContext() returns 'none' with no entity, returns 'entity_type:id' when an entity is set, getCacheableMetadata() includes the correct cache tag, and that an unknown entity type is swallowed gracefully rather than crashing the cache system.
  3. AiContextOverviewSettingService (AiContextOverviewSettingServiceTest) — verifies saveShowOverviewPage() persists the value to config, that invalidateIfChanged() is a no-op when the value is unchanged, and that it triggers a menu cache clear and route rebuild when the value changes without leaving the router in a broken state.
  4. ai_context_post_update_0001_remove_canvas_page_from_target_entity_types() (AiContextCanvasPagePostUpdateTest) — verifies canvas_page is removed while other types are preserved, the function is idempotent when canvas_page is absent, returns early when the config object does not exist, and that the resulting array is re-indexed.

All 16 tests pass with no failures. The 21 deprecation notices are pre-existing from the ai module dependency and are not introduced by this MR.

Testing Instructions

Clone the module and check out this branch inside an existing Drupal 11 + ai_context development environment:

cd web/modules/contrib/ai_context git fetch ai_context-3586455 git checkout 3586455-add-automated-ccc-tests-for-remaining-10-coverage-gaps

Run the new kernel tests from the Drupal root:

phpunit -c web/core web/modules/contrib/ai_context/tests/src/Kernel/AiContextRequirementsTest.php phpunit -c web/core web/modules/contrib/ai_context/tests/src/Kernel/AiContextEntityItemCacheContextTest.php phpunit -c web/core web/modules/contrib/ai_context/tests/src/Kernel/AiContextOverviewSettingServiceTest.php phpunit -c web/core web/modules/contrib/ai_context/tests/src/Kernel/AiContextCanvasPagePostUpdateTest.php

Expected result: Tests: 16, Assertions: 125 — all pass. Deprecation notices (from the ai module) are pre-existing and not introduced by this MR.

Checklist

  • I have updated the MR title to use format: Issue #1234: My issue title.
  • I have updated the MR description to include: Closes #1234
  • I have performed a self-review of my own code
  • I have added or updated tests, or explained in the description why this change is not covered by tests
  • I have updated documentation for any new or changed functionality
  • I have written testing instructions and verified them locally
  • I have noted any required post-merge steps (config imports, cache rebuilds, manual changes)
  • This MR contains no breaking API or hook changes, or they are explicitly documented in the description

AI Compliance

Note

Check the one that best describes your usage, or leave all unchecked if AI was not significantly used.

  • AI Assisted Code
    Mainly written by a human; AI used for autocomplete or partial generation under full human supervision.
  • AI Generated Code
    Mainly generated by AI, reviewed and approved by a human before this MR was created.
  • Vibe Coded
    Generated by AI and only functionally reviewed before this MR was created.

Closes #3586455

Edited by Pravesh Poonia

Merge request reports

Loading