getNodeReadTimestamps example


  public function testHistory() {
    $nid = $this->testNode->id();

    // Verify that previews of new entities do not create the history.     $this->drupalGet("node/add/page");
    $this->submitForm(['title[0][value]' => 'Unsaved page'], 'Preview');
    $this->assertArrayNotHasKey('ajaxPageState', $this->getDrupalSettings());

    // Retrieve "last read" timestamp for test node, for the current user.     $response = $this->getNodeReadTimestamps([$nid]);
    $this->assertEquals(200, $response->getStatusCode());
    $json = Json::decode($response->getBody());
    $this->assertSame([1 => 0]$json, 'The node has not yet been read.');

    // View the node.     $this->drupalGet('node/' . $nid);
    $this->assertCacheContext('user.roles:authenticated');
    // JavaScript present to record the node read.     $settings = $this->getDrupalSettings();
    $libraries = explode(',', $settings['ajaxPageState']['libraries']);
    $this->assertContains('history/mark-as-read', $libraries, 'history/mark-as-read library is present.');
    
Home | Imprint | This part of the site doesn't use cookies.