Koha-clms/t/db_dependent/Circulation
Martin Renvoize 14de13d3ad
Bug 37966: (follow-up) Make empty string handling more explicit in Circulation.pm
This commit improves upon the original fix by making the intent more
explicit when handling empty string date parameters in AddRenewal and
AddIssue functions.

WHY THIS IS BETTER:

The original fix (changing `defined $datedue` to just `$datedue`)
works correctly but relies on Perl's implicit truthy/falsy semantics:

  if ( $datedue && ref $datedue ne 'DateTime' )

This is subtle because:
- Empty string "" is falsy, so parsing is skipped ✓
- But it's not immediately obvious that empty strings are being
  handled specially
- The code doesn't explicitly show its intent

THIS APPROACH:

  if ( defined $datedue && $datedue ne '' && ref $datedue ne 'DateTime' )

Benefits:
1. EXPLICIT: Clearly states "only parse if defined AND not empty
   AND not already a DateTime"
2. SELF-DOCUMENTING: Intent is obvious to future developers
3. NO RELIANCE on truthy/falsy semantics
4. CONSISTENT: Same pattern applied across all date parameter handling

COMPREHENSIVE CHANGES:

1. AddRenewal (C4/Circulation.pm:3449)
   - Made datedue empty string check explicit

2. AddIssue (C4/Circulation.pm:1611)
   - Made datedue empty string check explicit
   - Also updated issuedate handling (line 1616) to explicitly handle
     empty strings

3. Test Coverage (t/db_dependent/Circulation/issue.t)
   - Added test for AddIssue with empty string datedue
   - Added test for AddIssue with empty string issuedate
   - Ensures both functions properly calculate dates from circulation
     rules instead of using "now"

The existing test for AddRenewal already covered empty string datedue
(added in the original Bug 37966 commit). These new tests ensure the
same correct behavior for AddIssue.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-04-29 09:09:10 -06:00
..
Branch.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
CalcDateDue.t Bug 40680: Fix C4::Calendar imports 2025-12-01 08:34:00 -07:00
CalcFine.t
…
CheckIfIssuedToPatron.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
CheckValidBarcode.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
GetHardDueDate.t Bug 3492: (follow-up) Remove last reservefee references 2026-02-09 12:57:57 -07:00
GetPendingOnSiteCheckouts.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
GetTopIssues.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
IsItemIssued.t Bug 40136: (follow-up) Fix IsItemIssued.t mock_userenv 2026-03-25 12:30:38 +01:00
MarkIssueReturned.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
NoIssuesChargeGuarantees.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
OfflineCirculation.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
OfflineOperation.t
…
ReturnClaims.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Returns.t Bug 28530: Fix tests 2026-02-10 10:51:38 -07:00
StoreLastBorrower.t Bug 26993: (follow-up) Rename last_returned_by_all as last_borrowers 2026-01-22 14:16:04 -07:00
SwitchOnSiteCheckouts.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
TooMany.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
_CalculateAndUpdateFine.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
dateexpiry.t Bug 40680: Fix t tests 2025-12-01 08:34:01 -07:00
issue.t Bug 37966: (follow-up) Make empty string handling more explicit in Circulation.pm 2026-04-29 09:09:10 -06:00
maxsuspensiondays.t Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
transferbook.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
transfers.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00