Bugfix Issue 580 TopLevelSuitesBarChart Empty Plan 500 - sebiboga/testlink-upgraded GitHub Wiki
lib/results/topLevelSuitesBarChart.php?tplan_id=<empty-plan>&tproject_id=<pid> dies with HTTP 500:
Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, null given
in lib/functions/testplan.class.php:862
The chart page fails to render when the test plan has no linked test cases.
testplan::getRootTestSuites() at lib/functions/testplan.class.php:859 calls fetchRowsIntoMap() which returns NULL (not empty array) when the SQL returns zero rows on PHP 8. The next line calls array_keys($items) where $items = NULL, which throws a TypeError on PHP 8 (PHP 7 would emit a warning).
Three guards added in lib/functions/testplan.class.php:
-
Line 860-862:
if (empty($items)) { return array(); }— early return whenfetchRowsIntoMap()returns NULL -
Line 870:
if (!empty($xmen))— guardforeach($xmen ...)against null map -
Line 890-892:
if (empty($tlnodes)) { return array(); }— guardarray_keys($tlnodes)against empty map
Applied by CI bot commits 1082c2fe3 and 686c2bc24 (referencing issue #690).
- Browser loads
topLevelSuitesBarChart.php?tplan_id=<empty-plan>→ HTTP 200 (was 500) - No TypeError/Fatal in PHP server log
- No new Error entries in Event Viewer
- Regression test suite:
tmp/TLU_Test_Cases.md— TC-580-01, TC-580-02, TC-580-03
-
lib/functions/testplan.class.php— three null-guard additions ingetRootTestSuites()