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

  1. Returns an empty string from the [node:published] and chained [node:published:*] tokens when published_at is NULL (unpublished or unsaved node), instead of letting DateFormatter::format(NULL, …) raise InvalidArgumentException: non-numeric timestamp. The exception currently surfaces as a 500 on any page that consumes the token (Metatag article:published_time, autosave_form during validation, Acquia Optimize scans, etc.).
  2. Adds a kernel test PublicationDateTokenTest covering unpublished saved, unsaved, and published node tokens (both simple and chained).

How it differs from !27

  • Rebased on 3.x. !27 reported has_conflicts: true; the conflict was in PublicationDateInstallationTest because 3.x already swapped revisionIds() for getQuery()->allRevisions(). Took the version on 3.x.
  • Tightened the NULL guards to !== NULL. The truthy/!empty() form would also short-circuit for a real 0 timestamp (Unix epoch). Practically nobody publishes at epoch, but the tighter check is free.
  • Added #[RunTestsInSeparateProcesses] to PublicationDateTokenTest. 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

Merge request reports

Loading