Chris@0: drupalCreateContentType(['type' => 'page']); Chris@0: node_access_test_add_field(NodeType::load('page')); Chris@0: $this->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN); Chris@0: \Drupal::state()->set('node_access_test.private', TRUE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Ensure private node on /tracker is only visible to users with permission. Chris@0: */ Chris@0: public function testTrackerNodeAccess() { Chris@0: // Create user with node test view permission. Chris@0: $access_user = $this->drupalCreateUser(['node test view', 'access user profiles']); Chris@0: Chris@0: // Create user without node test view permission. Chris@0: $no_access_user = $this->drupalCreateUser(['access user profiles']); Chris@0: Chris@0: $this->drupalLogin($access_user); Chris@0: Chris@0: // Create some nodes. Chris@0: $private_node = $this->drupalCreateNode([ Chris@0: 'title' => t('Private node test'), Chris@0: 'private' => TRUE, Chris@0: ]); Chris@0: $public_node = $this->drupalCreateNode([ Chris@0: 'title' => t('Public node test'), Chris@0: 'private' => FALSE, Chris@0: ]); Chris@0: Chris@0: // User with access should see both nodes created. Chris@0: $this->drupalGet('activity'); Chris@0: $this->assertText($private_node->getTitle(), 'Private node is visible to user with private access.'); Chris@0: $this->assertText($public_node->getTitle(), 'Public node is visible to user with private access.'); Chris@0: $this->drupalGet('user/' . $access_user->id() . '/activity'); Chris@0: $this->assertText($private_node->getTitle(), 'Private node is visible to user with private access.'); Chris@0: $this->assertText($public_node->getTitle(), 'Public node is visible to user with private access.'); Chris@0: Chris@0: // User without access should not see private node. Chris@0: $this->drupalLogin($no_access_user); Chris@0: $this->drupalGet('activity'); Chris@0: $this->assertNoText($private_node->getTitle(), 'Private node is not visible to user without private access.'); Chris@0: $this->assertText($public_node->getTitle(), 'Public node is visible to user without private access.'); Chris@0: $this->drupalGet('user/' . $access_user->id() . '/activity'); Chris@0: $this->assertNoText($private_node->getTitle(), 'Private node is not visible to user without private access.'); Chris@0: $this->assertText($public_node->getTitle(), 'Public node is visible to user without private access.'); Chris@0: } Chris@0: Chris@0: }