Problem/Motivation

IndexNowPathProcessor and IndexNowOutboundPathProcessor
have no dedicated unit tests. Both are only exercised indirectly through kernel
tests, which leaves their core logic unverified in isolation:

  • IndexNowPathProcessor::processInbound() rewrites the public
    /{key}.txt path to the internal
    /index_now_api_key/{key} route. The guard conditions (empty
    key, path mismatch) are never explicitly asserted.
  • IndexNowOutboundPathProcessor::processOutbound() overrides
    $options['base_url'] when the index_now option
    and the index_now.base_url setting are both present. The
    combinations where one condition is missing are not tested.

Proposed resolution

Add tests/src/Unit/PathProcessor/IndexNowPathProcessorTest.php
covering:

  • Path is rewritten when the key matches.
  • Path is returned unchanged when the key is empty.
  • Path is returned unchanged when the path does not match the key.

Add tests/src/Unit/PathProcessor/IndexNowOutboundPathProcessorTest.php
covering:

  • base_url is overridden when both the index_now
    option and the index_now.base_url setting are set.
  • Trailing slash is stripped from the configured base URL.
  • base_url is left unchanged when the index_now
    option is absent.
  • base_url is left unchanged when absolute is not
    set.
  • base_url is left unchanged when index_now.base_url
    is not configured.

All dependencies (IndexNowKeyManagerInterface,
Settings) should be mocked or stubbed. No Drupal bootstrap is
required.

Remaining tasks

  • [ ] Write IndexNowPathProcessorTest.php
  • [ ] Write IndexNowOutboundPathProcessorTest.php
  • [ ] Ensure all scenarios listed above pass

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork index_now-3587872

Command icon 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

macsim created an issue. See original summary.

  • macsim committed dc7fbadb on 4.0.x
    Issue #3587872 by macsim: Add unit tests for IndexNowPathProcessor and...
macsim’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

macsim’s picture

Status: Fixed » Closed (fixed)