Issue #3347012: Empty string for [node:published] on unpublished/unsaved nodes (rebased on 3.x, tightened NULL guards, schema install in kernel test)
Closes #3347012. Builds on @fago's !27.
What this MR does
- Returns an empty string from the
[node:published]and chained[node:published:*]tokens whenpublished_atis NULL (unpublished or unsaved node), instead of lettingDateFormatter::format(NULL, …)raiseInvalidArgumentException: non-numeric timestamp. The exception currently surfaces as a 500 on any page that consumes the token (Metatagarticle:published_time, autosave_form during validation, Acquia Optimize scans, etc.). - Adds a kernel test
PublicationDateTokenTestcovering unpublished saved, unsaved, and published node tokens (both simple and chained).
How it differs from !27
- Rebased on
3.x. !27 reportedhas_conflicts: true; the conflict was inPublicationDateInstallationTestbecause 3.x already swappedrevisionIds()forgetQuery()->allRevisions(). Took the version on 3.x. - Tightened the NULL guards to
!== NULL. The truthy/!empty()form would also short-circuit for a real0timestamp (Unix epoch). Practically nobody publishes at epoch, but the tighter check is free. - Added
#[RunTestsInSeparateProcesses]toPublicationDateTokenTest. Required for Drupal 11.3+ kernel tests; raises a deprecation warning otherwise.
Verified locally
Without the production fix, only the test file added, the test correctly catches the regression:
1) PublicationDateTokenTest::testUnpublishedNodeTokens
InvalidArgumentException: The timestamp must be numeric.
…/publication_date.tokens.inc:47
2) PublicationDateTokenTest::testUnsavedNodeTokens
InvalidArgumentException: The timestamp must be numeric.
…/publication_date.tokens.inc:47
Tests: 3, Errors: 2 (testPublishedNodeTokens passes — happy path).With the fix applied: 3/3 pass.
Suggesting !27 be closed in favour of this one once the pipeline is green here.
cc @fago
Edited by Frank Mably