Skip to content

test: tests for the main path of KnowledgeGraph::setSemanticDataFromApi() #71

Description

@gesinn-it-gea

Goal

includes/KnowledgeGraph.php:633-811 — the most complex method in the extension (~180 lines). Existing tests (tests/phpunit/Unit/KnowledgeGraphSetSemanticDataFromApiTest.php) only cover the early return cases (maxDepth===0, depth>=maxDepth, title already present). The actual processing path is untested.

Test scenarios

  • Property filtering via $onlyProperties (direct and inverse properties, in_array logic for $propKey/$key).
  • Processing of dataitem type-9 entries (title links): correct namespace resolution via NamespaceInfo::getCanonicalName() and assembly of the linked-title string.
  • Recursion via $pendingRecursiveTitles: linked titles are processed recursively when depth < maxDepth, otherwise not.
  • Duplicate prevention via makeRelationKey()/self::$relationsSeen — the same relation is not processed twice.
  • File namespace special case: $title->getNamespace() === NS_FILE$output['src'] is set via RepoGroup::findFile()->getFullUrl().
  • Categories are populated via getWikiPage()->getCategories().
  • Property metadata enrichment (typeId, canonicalLabel, preferredLabel, typeLabel, description) on first occurrence of a property.
  • SMW API error case ($result['error'] set) → early return without further processing.

Mocking pattern

  • Requires a mock/fixture for the SMW API (FauxRequest/ApiMain, action smwbrowse) — likely an integration test (MediaWikiIntegrationTestCase) rather than a pure unit test, since ApiMain::execute() is involved.
  • Reference for the basic structure: tests/phpunit/Unit/KnowledgeGraphSetSemanticDataFromApiTest.php (reflection-based reset of self::$data).

Note

Related, broader issue: #37. These tests can be implemented independently of that.

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