Skip to content

test: tests for KnowledgeGraph::onSidebarBeforeOutput() and ensureKnowledgeGraphOptionsPageExists() #75

Description

@gesinn-it-gea

Goal

Two hook-adjacent methods with no test coverage.

Test scenarios

onSidebarBeforeOutput() (includes/KnowledgeGraph.php:195-206)

  • $wgKnowledgeGraphShowSidebarLink is false/empty → early return, $sidebar remains unchanged.
  • $wgKnowledgeGraphShowSidebarLink is true$sidebar['TOOLBOX'][] receives an entry with the correct text (from wfMessage('knowledgegraph-knowledgegraphdesigner-label')) and href (URL of the KnowledgeGraphDesigner special page).

ensureKnowledgeGraphOptionsPageExists() (includes/KnowledgeGraph.php:148-181, private, currently only reachable indirectly via onBeforePageDisplay())

  • The page MediaWiki:KnowledgeGraphOptions already exists → no write happens (saveRevision is not called).
  • The page is missing → it is created from data/KnowledgeGraphOptions.js (content model CONTENT_MODEL_JAVASCRIPT, author is the MediaWiki default system user).
  • The template file is missing (file_exists() returns false) → the method aborts without error (only a debug log).

Mocking pattern

Integration test (MediaWikiIntegrationTestCase) recommended, since real page creation (WikiPage::newPageUpdater) is involved. ensureKnowledgeGraphOptionsPageExists() is private — test it via the public onBeforePageDisplay() hook, or via reflection (ReflectionMethod::setAccessible).

Part of the "raise PHP coverage to ~70%" effort.

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsPHPUnit coverage work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions