You are here

public function TrackerTest::assertHistoryMetadata in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::assertHistoryMetadata()
  2. 9 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::assertHistoryMetadata()

Passes if the appropriate history metadata exists.

Verify the data-history-node-id, data-history-node-timestamp and data-history-node-last-comment-timestamp attributes, which are used by the drupal.tracker-history library to add the appropriate "new" and "updated" indicators, as well as the "x new" replies link to the tracker. We do this in JavaScript to prevent breaking the render cache.

@internal

Parameters

int $node_id: A node ID, that must exist as a data-history-node-id attribute

int $node_timestamp: A node timestamp, that must exist as a data-history-node-timestamp attribute.

int $node_last_comment_timestamp: A node's last comment timestamp, that must exist as a data-history-node-last-comment-timestamp attribute.

bool $library_is_present: Whether the drupal.tracker-history library should be present or not.

File

core/modules/tracker/tests/src/Functional/TrackerTest.php, line 483

Class

TrackerTest
Create and delete nodes and check for their display in the tracker listings.

Namespace

Drupal\Tests\tracker\Functional

Code

public function assertHistoryMetadata(int $node_id, int $node_timestamp, int $node_last_comment_timestamp, bool $library_is_present = TRUE) : void {
  $settings = $this
    ->getDrupalSettings();
  $this
    ->assertSame($library_is_present, isset($settings['ajaxPageState']) && in_array('tracker/history', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.tracker-history library is present.');
  $this
    ->assertCount(1, $this
    ->xpath('//table/tbody/tr/td[@data-history-node-id="' . $node_id . '" and @data-history-node-timestamp="' . $node_timestamp . '"]'), 'Tracker table cell contains the data-history-node-id and data-history-node-timestamp attributes for the node.');
  $this
    ->assertCount(1, $this
    ->xpath('//table/tbody/tr/td[@data-history-node-last-comment-timestamp="' . $node_last_comment_timestamp . '"]'), 'Tracker table cell contains the data-history-node-last-comment-timestamp attribute for the node.');
}