protected function NodeViewCountBaseFunctionalityTest::checkFullViewMode in Node view count 8
Check nodeviewcount settings on node view for full view mode.
Parameters
string $user_role: User role to access node view page.
\Drupal\node\NodeInterface $node: Node to access.
mixed $expected_result: Expected result. TRUE if nodeviewcount settings should be included on the page, FALSE otherwise.
1 call to NodeViewCountBaseFunctionalityTest::checkFullViewMode()
- NodeViewCountBaseFunctionalityTest::testNodesWithFullViewMode in src/
Tests/ NodeViewCountBaseFunctionalityTest.php - Test nodeviewcount js for nodes in full view mode.
File
- src/
Tests/ NodeViewCountBaseFunctionalityTest.php, line 104
Class
- NodeViewCountBaseFunctionalityTest
- Tests the base functionality of nodeviewcount module.
Namespace
Drupal\nodeviewcount\TestsCode
protected function checkFullViewMode($user_role, NodeInterface $node, $expected_result) {
$user_id = 0;
// Create user and login if needed.
if ($user_role !== 'anonymous') {
$user = $this
->createUserWithRole($user_role);
$user_id = $user
->id();
$this
->drupalLogin($user);
}
// Go to the node page.
$this
->drupalGet('node/' . $node
->id());
// Check nodeviewcount statistics script.
if ($expected_result) {
$this
->assertRaw('nodeviewcount.js', 'Nodeviewcount statistics library is included.');
$settings = $this
->getDrupalSettings();
$expectedSettings = [
$node
->id() => [
'nid' => $node
->id(),
'uid' => $user_id,
'uip' => '127.0.0.1',
'view_mode' => 'full',
],
];
$this
->assertEqual($expectedSettings, $settings['nodeviewcount']['data'], 'drupalSettings has right node information.');
}
else {
$this
->assertNoRaw('nodeviewcount.js', 'Nodeviewcount statistics library is not included.');
}
// Logout if needed.
if ($user_role !== 'anonymous') {
$this
->drupalLogout();
}
}