function TrackerTest::assertHistoryMetadata

Same name in other branches
  1. 8.9.x core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::assertHistoryMetadata()
  2. 10 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::assertHistoryMetadata()
  3. 11.x 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.

1 call to TrackerTest::assertHistoryMetadata()
TrackerTest::testTrackerHistoryMetadata in core/modules/tracker/tests/src/Functional/TrackerTest.php
Tests the metadata for the "new"/"updated" indicators.

File

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

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->assertSession()
        ->elementsCount('xpath', '//table/tbody/tr/td[@data-history-node-id="' . $node_id . '" and @data-history-node-timestamp="' . $node_timestamp . '"]', 1);
    $this->assertSession()
        ->elementsCount('xpath', '//table/tbody/tr/td[@data-history-node-last-comment-timestamp="' . $node_last_comment_timestamp . '"]', 1);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.