X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ftracker%2Ftests%2Fsrc%2FFunctional%2FTrackerNodeAccessTest.php;fp=web%2Fcore%2Fmodules%2Ftracker%2Ftests%2Fsrc%2FFunctional%2FTrackerNodeAccessTest.php;h=2b320ae4b6dfde17118310d8128ee9b3d45b7a71;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/tracker/tests/src/Functional/TrackerNodeAccessTest.php b/web/core/modules/tracker/tests/src/Functional/TrackerNodeAccessTest.php new file mode 100644 index 000000000..2b320ae4b --- /dev/null +++ b/web/core/modules/tracker/tests/src/Functional/TrackerNodeAccessTest.php @@ -0,0 +1,75 @@ +drupalCreateContentType(['type' => 'page']); + node_access_test_add_field(NodeType::load('page')); + $this->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN); + \Drupal::state()->set('node_access_test.private', TRUE); + } + + /** + * Ensure private node on /tracker is only visible to users with permission. + */ + public function testTrackerNodeAccess() { + // Create user with node test view permission. + $access_user = $this->drupalCreateUser(['node test view', 'access user profiles']); + + // Create user without node test view permission. + $no_access_user = $this->drupalCreateUser(['access user profiles']); + + $this->drupalLogin($access_user); + + // Create some nodes. + $private_node = $this->drupalCreateNode([ + 'title' => t('Private node test'), + 'private' => TRUE, + ]); + $public_node = $this->drupalCreateNode([ + 'title' => t('Public node test'), + 'private' => FALSE, + ]); + + // User with access should see both nodes created. + $this->drupalGet('activity'); + $this->assertText($private_node->getTitle(), 'Private node is visible to user with private access.'); + $this->assertText($public_node->getTitle(), 'Public node is visible to user with private access.'); + $this->drupalGet('user/' . $access_user->id() . '/activity'); + $this->assertText($private_node->getTitle(), 'Private node is visible to user with private access.'); + $this->assertText($public_node->getTitle(), 'Public node is visible to user with private access.'); + + // User without access should not see private node. + $this->drupalLogin($no_access_user); + $this->drupalGet('activity'); + $this->assertNoText($private_node->getTitle(), 'Private node is not visible to user without private access.'); + $this->assertText($public_node->getTitle(), 'Public node is visible to user without private access.'); + $this->drupalGet('user/' . $access_user->id() . '/activity'); + $this->assertNoText($private_node->getTitle(), 'Private node is not visible to user without private access.'); + $this->assertText($public_node->getTitle(), 'Public node is visible to user without private access.'); + } + +}