diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index 97cc6be..4898c66 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -659,7 +659,6 @@ class ForumIndexTestCase extends WebTestBase { /** * Tests forum block view for private node access. */ - class ForumNodeAccessTestCase extends WebTestBase { protected $access_user; protected $admin_user; @@ -674,15 +673,15 @@ class ForumNodeAccessTestCase extends WebTestBase { } function setUp() { - $modules = array('node','comment','forum','taxonomy','tracker','node_access_test','block'); - parent::setUp($modules); + parent::setUp(array('node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block')); node_access_rebuild(); variable_set('node_access_test_private', TRUE); } /** * Creates some users and creates a public node and a private node. - * Adds both Active forum topics and new forum topics blocks to the sidebar. + * + * Adds both active forum topics and new forum topics blocks to the sidebar. * Tests to ensure private node/public node access is respected on blocks. */ function testForumNodeAccess() { @@ -701,9 +700,9 @@ class ForumNodeAccessTestCase extends WebTestBase { "body[$langcode][0][value]" => $this->randomName(200), 'private' => TRUE, ); - $this->drupalPost('node/add/forum/1',$edit, t('Save')); + $this->drupalPost('node/add/forum/1', $edit, t('Save')); $private_node = $this->drupalGetNodeByTitle($private_node_title); - $this->assertTrue(!empty($private_node). 'New private forum node found in database.'); + $this->assertTrue(!empty($private_node), 'New private forum node found in database.'); // Create a public node. $public_node_title = $this->randomName(20); @@ -711,23 +710,23 @@ class ForumNodeAccessTestCase extends WebTestBase { 'title' => $public_node_title, "body[$langcode][0][value]" => $this->randomName(200), ); - $this->drupalPost('node/add/forum/1',$edit, t('Save')); + $this->drupalPost('node/add/forum/1', $edit, t('Save')); $public_node = $this->drupalGetNodeByTitle($public_node_title); - $this->assertTrue(!empty($public_node). 'New public forum node found in database.'); + $this->assertTrue(!empty($public_node), 'New public forum node found in database.'); // Enable the active forum block. $edit = array(); $edit['blocks[forum_active][region]'] = 'sidebar_second'; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); $this->assertResponse(200); - $this->assertText(t('The block settings have been updated.'), t('Active forum topics forum block was enabled')); + $this->assertText(t('The block settings have been updated.'), 'Active forum topics forum block was enabled'); // Enable the new forum block. $edit = array(); $edit['blocks[forum_new][region]'] = 'sidebar_second'; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); $this->assertResponse(200); - $this->assertText(t('The block settings have been updated.'), t('[New forum topics] Forum block was enabled')); + $this->assertText(t('The block settings have been updated.'), '[New forum topics] Forum block was enabled'); // Test for $access_user. $this->drupalLogin($access_user); diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php new file mode 100644 index 0000000..cb74f02 --- /dev/null +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php @@ -0,0 +1,67 @@ + 'Tracker Node Access Tests', + 'description' => 'Tests for private node access on /tracker.', + 'group' => 'Tracker', + ); + } + + public function setUp() { + parent::setUp(array('node', 'comment', 'tracker', 'node_access_test')); + node_access_rebuild(); + variable_set('node_access_test_private', TRUE); + } + + + /** + * Ensure private node on /tracker is only visible to users with permission. + */ + function testTrackerNodeAccess() { + // Create user with node test view permission. + $access_user = $this->drupalCreateUser(array('node test view')); + + // Create user without node test view permission. + $no_access_user = $this->drupalCreateuser(); + + $this->drupalLogin($access_user); + + // Create some nodes. + $private_node = $this->drupalCreateNode(array( + 'title' => t('Private node test'), + 'private'=> TRUE, + )); + $public_node = $this->drupalCreateNode(array( + 'title' => t('Public node test'), + 'private'=>FALSE, + )); + + // User with access should see both nodes created. + $this->drupalGet('tracker'); + $this->assertText($private_node->title, 'Private node is visible to user with private access.'); + $this->assertText($public_node->title, 'Public node is visible to user with private access.'); + + // User without access should not see private node. + $this->drupalLogin($no_access_user); + $this->drupalGet('tracker'); + $this->assertNoText($private_node->title, 'Private node is not visible to user without private access.'); + $this->assertText($public_node->title, 'Public node is visible to user without private access.'); + } +}