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.
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
$onlyProperties(direct and inverse properties,in_arraylogic for$propKey/$key).dataitemtype-9 entries (title links): correct namespace resolution viaNamespaceInfo::getCanonicalName()and assembly of the linked-title string.$pendingRecursiveTitles: linked titles are processed recursively whendepth < maxDepth, otherwise not.makeRelationKey()/self::$relationsSeen— the same relation is not processed twice.$title->getNamespace() === NS_FILE→$output['src']is set viaRepoGroup::findFile()->getFullUrl().getWikiPage()->getCategories().typeId,canonicalLabel,preferredLabel,typeLabel,description) on first occurrence of a property.$result['error']set) → early return without further processing.Mocking pattern
FauxRequest/ApiMain, actionsmwbrowse) — likely an integration test (MediaWikiIntegrationTestCase) rather than a pure unit test, sinceApiMain::execute()is involved.tests/phpunit/Unit/KnowledgeGraphSetSemanticDataFromApiTest.php(reflection-based reset ofself::$data).Note
Related, broader issue: #37. These tests can be implemented independently of that.
Part of the "raise PHP coverage to ~70%" effort.