You are here

public function NodeViewCountBaseFunctionalityTest::checkTeaserViewMode in Node view count 8

Check nodeviewcount settings on node view for teaser view mode.

Parameters

string $user_role: User role for visiting nodes.

bool $expected_result: TRUE if nodeviewcount scripts and settings should be included.

1 call to NodeViewCountBaseFunctionalityTest::checkTeaserViewMode()
NodeViewCountBaseFunctionalityTest::testNodesWithTeaserViewMode in src/Tests/NodeViewCountBaseFunctionalityTest.php
Tests nodeviewcount settings for nodes in teaser view mode.

File

src/Tests/NodeViewCountBaseFunctionalityTest.php, line 145

Class

NodeViewCountBaseFunctionalityTest
Tests the base functionality of nodeviewcount module.

Namespace

Drupal\nodeviewcount\Tests

Code

public function checkTeaserViewMode($user_role, $expected_result) {
  $user_id = 0;
  if ($user_role !== 'anonymous') {
    $user = $this
      ->createUserWithRole($user_role);
    $user_id = $user
      ->id();
    $this
      ->drupalLogin($user);
  }
  $this
    ->drupalGet('node');
  if ($expected_result) {
    $this
      ->assertRaw('nodeviewcount.js', 'Nodeviewcount statistics library is included.');
    $settings = $this
      ->getDrupalSettings();
    $expectedSettings = [
      $this->firstTestTrackedNode
        ->id() => [
        'nid' => $this->firstTestTrackedNode
          ->id(),
        'uid' => $user_id,
        'uip' => '127.0.0.1',
        'view_mode' => 'teaser',
      ],
      $this->secondTestTrackedNode
        ->id() => [
        'nid' => $this->secondTestTrackedNode
          ->id(),
        'uid' => $user_id,
        'uip' => '127.0.0.1',
        'view_mode' => 'teaser',
      ],
    ];
    $this
      ->assertEqual($expectedSettings, $settings['nodeviewcount']['data'], 'drupalSettings to mark node as read are present.');
  }
  else {
    $this
      ->assertNoRaw('nodeviewcount.js', 'Nodeviewcount statistics library is not included.');
  }
  if ($user_role !== 'anonymous') {
    $this
      ->drupalLogout();
  }
}