Test Case Linking Fix - sebiboga/testlink-upgraded GitHub Wiki
Test Case Linking Crash Fix
Issue #138
Fixed critical bug: Application crash when linking test cases to requirements with INACTIVE versions.
Problem
When attempting to link a test case to a requirement, the application would crash if the test case's latest version was marked as INACTIVE.
Error
Fatal error: Call to a member function on null
Root Cause
In lib/functions/requirement_mgr.class.php, the assign_to_tcase() function did not validate whether the latest test case version was active before attempting to use it.
The code would:
- Call
get_last_active_version()to retrieve the latest active version - NOT check if the result was null
- Attempt to access properties on a null value â CRASH
Solution
Added early validation to check if the latest test case version is INACTIVE:
// Get Latest Active Test Case Version
$tcv = current($tcMgr->get_last_active_version($testcase_id));
if ($tcv == null) {
// Latest version is Inactive => operation not allowed
return $output;
}
Behavior:
- If latest test case version is INACTIVE â return with no link created
- If latest test case version is ACTIVE â proceed with linking
- No error/exception thrown â graceful handling
Implementation
File Changed
lib/functions/requirement_mgr.class.php- Function:
assign_to_tcase()
Code Pattern
function assign_to_tcase($req_id, $testcase_id, $author_id) {
$tcMgr = new testcase($this->db);
// Check if test case version is active FIRST
if ($testcase_id && $req_id) {
$tcv = current($tcMgr->get_last_active_version($testcase_id));
if ($tcv == null) {
// Latest version is Inactive => operation not allowed
return 0; // Return early, no link created
}
}
// Go ahead with requirement linking...
if ($testcase_id && $req_id) {
// ... rest of linking logic ...
}
}
How to Use
Linking Requirements to Active Test Cases
â
WORKS: Test case latest version is ACTIVE
â Requirement successfully linked
Attempting to Link to Inactive Test Cases
â ī¸ BLOCKED: Test case latest version is INACTIVE
â Operation returns silently (graceful failure)
â No crash
â No link created
User Impact
Before Fix
- â Application crashes
- â Error page displayed
- â Session may be interrupted
After Fix
- â Operation handled gracefully
- â No error message (silent failure)
- â User can continue working
- âšī¸ User should activate test case version first
Related Workflow
Recommended Process
-
Create Test Case
- New test cases are ACTIVE by default
-
Link to Requirement
- Click requirement â "Link to Test Case"
- Select test case
- Link created successfully â
-
Deactivate Test Case (if needed)
- Change test case status to INACTIVE
- Existing requirement links remain
- Cannot create NEW links until reactivated
-
Reactivate Test Case
- Change status back to ACTIVE
- Can link to new requirements again â
Testing
Test Case 1: Link to Active Test Case
Preconditions:
- Test case exists with ACTIVE version
- Requirement exists
Steps:
1. Navigate to requirement
2. Click "Link Test Case"
3. Select active test case
4. Click "Link"
Expected Result:
â
Link created successfully
â
No errors
Test Case 2: Link to Inactive Test Case
Preconditions:
- Test case exists with INACTIVE version
- Requirement exists
Steps:
1. Navigate to requirement
2. Click "Link Test Case"
3. Select inactive test case
4. Click "Link"
Expected Result:
â
Operation completes
â
No crash/error
â
No link created
âšī¸ May show info message (optional enhancement)
Test Case 3: Multiple Versions
Preconditions:
- Test case has multiple versions
- Latest version is INACTIVE
- Earlier versions are ACTIVE
Expected Result:
â
Operation blocked (uses latest version check)
â
User must activate latest version to link
Enhancement Opportunities
Future Improvements
-
User Feedback
if ($tcv == null) { // Add message return ['status' => 'error', 'message' => lang_get('test_case_inactive')]; } -
Automatic Version Activation
- Option to auto-activate when linking
-
UI Indication
- Show INACTIVE status in test case selector
- Disable selection of inactive versions
-
Logging
- Log failed link attempts
- Track inactive test case linking attempts
Related Features
- Test Case Versioning: Developer-Guide
- Requirement Management: File-Import-Export
- Status Management: Test case lifecycle
Technical Details
Affected Function
requirement_mgr::assign_to_tcase()requirement_mgr::create_tc_from_requirement()
Related Methods
testcase::get_last_active_version()- Gets latest ACTIVE versiontestcase::getActiveStatus()- Checks if version is active
Commit Information
- Commit ID: b0dd23a70
- Message: "fix: logic to avoid crash when trying to add req link to a test case that has latest version INACTIVE"
- Status: â Already integrated in sebiboga branch
References
- GitHub Issue: #138
- Original commit (sebiboga_2.0): e57510a84
- Current branch: sebiboga (b0dd23a70)
Status: â
Fixed
Issue: #138
Type: Critical Bug Fix
Severity: High
Impact: Zero breaking changes