3 namespace Drupal\Tests\tracker\Functional;
5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
6 use Drupal\comment\Tests\CommentTestTrait;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\Tests\BrowserTestBase;
11 * Tests for private node access on /tracker.
15 class TrackerNodeAccessTest extends BrowserTestBase {
24 public static $modules = ['node', 'comment', 'tracker', 'node_access_test'];
26 protected function setUp() {
28 node_access_rebuild();
29 $this->drupalCreateContentType(['type' => 'page']);
30 node_access_test_add_field(NodeType::load('page'));
31 $this->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN);
32 \Drupal::state()->set('node_access_test.private', TRUE);
36 * Ensure private node on /tracker is only visible to users with permission.
38 public function testTrackerNodeAccess() {
39 // Create user with node test view permission.
40 $access_user = $this->drupalCreateUser(['node test view', 'access user profiles']);
42 // Create user without node test view permission.
43 $no_access_user = $this->drupalCreateUser(['access user profiles']);
45 $this->drupalLogin($access_user);
48 $private_node = $this->drupalCreateNode([
49 'title' => t('Private node test'),
52 $public_node = $this->drupalCreateNode([
53 'title' => t('Public node test'),
57 // User with access should see both nodes created.
58 $this->drupalGet('activity');
59 $this->assertText($private_node->getTitle(), 'Private node is visible to user with private access.');
60 $this->assertText($public_node->getTitle(), 'Public node is visible to user with private access.');
61 $this->drupalGet('user/' . $access_user->id() . '/activity');
62 $this->assertText($private_node->getTitle(), 'Private node is visible to user with private access.');
63 $this->assertText($public_node->getTitle(), 'Public node is visible to user with private access.');
65 // User without access should not see private node.
66 $this->drupalLogin($no_access_user);
67 $this->drupalGet('activity');
68 $this->assertNoText($private_node->getTitle(), 'Private node is not visible to user without private access.');
69 $this->assertText($public_node->getTitle(), 'Public node is visible to user without private access.');
70 $this->drupalGet('user/' . $access_user->id() . '/activity');
71 $this->assertNoText($private_node->getTitle(), 'Private node is not visible to user without private access.');
72 $this->assertText($public_node->getTitle(), 'Public node is visible to user without private access.');