diff options
Diffstat (limited to 'modules/node/node.test')
-rw-r--r-- | modules/node/node.test | 193 |
1 files changed, 190 insertions, 3 deletions
diff --git a/modules/node/node.test b/modules/node/node.test index 96b93cf4a..f46d2a108 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -8,7 +8,7 @@ /** * Test the node_load_multiple() function. */ -class NodeLoadMultipleUnitTest extends DrupalWebTestCase { +class NodeLoadMultipleTestCase extends DrupalWebTestCase { public static function getInfo() { return array( @@ -821,7 +821,7 @@ class NodeRSSContentTestCase extends DrupalWebTestCase { * @todo Cover hook_node_access in a separate test class. * hook_node_access_records is covered in another test class. */ -class NodeAccessUnitTest extends DrupalWebTestCase { +class NodeAccessTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Node access', @@ -888,7 +888,7 @@ class NodeAccessUnitTest extends DrupalWebTestCase { /** * Test case to verify hook_node_access_records functionality. */ -class NodeAccessRecordsUnitTest extends DrupalWebTestCase { +class NodeAccessRecordsTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Node access records', @@ -2306,3 +2306,190 @@ class NodeTokenReplaceTestCase extends DrupalWebTestCase { } } } + +/** + * Tests user permissions for node revisions. + */ +class NodeRevisionPermissionsTestCase extends DrupalWebTestCase { + protected $node_revisions = array(); + protected $accounts = array(); + + // Map revision permission names to node revision access ops. + protected $map = array( + 'view' => 'view revisions', + 'update' => 'revert revisions', + 'delete' => 'delete revisions', + ); + + public static function getInfo() { + return array( + 'name' => 'Node revision permissions', + 'description' => 'Tests user permissions for node revision operations.', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(); + + // Create a node with several revisions. + $node = $this->drupalCreateNode(); + $this->node_revisions[] = $node; + + for ($i = 0; $i < 3; $i++) { + // Create a revision for the same nid and settings with a random log. + $revision = clone $node; + $revision->revision = 1; + $revision->log = $this->randomName(32); + node_save($revision); + $this->node_revisions[] = $revision; + } + + // Create three users, one with each revision permission. + foreach ($this->map as $op => $permission) { + // Create the user. + $account = $this->drupalCreateUser( + array( + 'access content', + 'edit any page content', + 'delete any page content', + $permission, + ) + ); + $account->op = $op; + $this->accounts[] = $account; + } + + // Create an admin account (returns TRUE for all revision permissions). + $admin_account = $this->drupalCreateUser(array('access content', 'administer nodes')); + $admin_account->is_admin = TRUE; + $this->accounts['admin'] = $admin_account; + + // Create a normal account (returns FALSE for all revision permissions). + $normal_account = $this->drupalCreateUser(); + $normal_account->op = FALSE; + $this->accounts[] = $normal_account; + } + + /** + * Tests the _node_revision_access() function. + */ + function testNodeRevisionAccess() { + $revision = $this->node_revisions[1]; + + $parameters = array( + 'op' => array_keys($this->map), + 'account' => $this->accounts, + ); + + $permutations = $this->generatePermutations($parameters); + foreach ($permutations as $case) { + if (!empty($case['account']->is_admin) || $case['op'] == $case['account']->op) { + $this->assertTrue(_node_revision_access($revision, $case['op'], $case['account']), "{$this->map[$case['op']]} granted."); + } + else { + $this->assertFalse(_node_revision_access($revision, $case['op'], $case['account']), "{$this->map[$case['op']]} not granted."); + } + } + + // Test that access is FALSE for a node administrator with an invalid $node + // or $op parameters. + $admin_account = $this->accounts['admin']; + $this->assertFalse(_node_revision_access(FALSE, 'view', $admin_account), '_node_revision_access() returns FALSE with an invalid node.'); + $this->assertFalse(_node_revision_access($revision, 'invalid-op', $admin_account), '_node_revision_access() returns FALSE with an invalid op.'); + + // Test that the $account parameter defaults to the "logged in" user. + $original_user = $GLOBALS['user']; + $GLOBALS['user'] = $admin_account; + $this->assertTrue(_node_revision_access($revision, 'view'), '_node_revision_access() returns TRUE when used with global user.'); + $GLOBALS['user'] = $original_user; + } +} + +/** + * Tests pagination with a node access module enabled. + */ +class NodeAccessPagerTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Node access pagination', + 'description' => 'Test access controlled node views have the right amount of comment pages.', + 'group' => 'Node', + ); + } + + public function setUp() { + parent::setUp('node_access_test', 'comment', 'forum'); + node_access_rebuild(); + $this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'node test view')); + } + + /** + * Tests the comment pager for nodes with multiple grants per realm. + */ + public function testCommentPager() { + // Create a node. + $node = $this->drupalCreateNode(); + + // Create 60 comments. + for ($i = 0; $i < 60; $i++) { + $comment = new stdClass(); + $comment->cid = 0; + $comment->pid = 0; + $comment->uid = $this->web_user->uid; + $comment->nid = $node->nid; + $comment->subject = $this->randomName(); + $comment->comment_body = array( + LANGUAGE_NONE => array( + array('value' => $this->randomName()), + ), + ); + comment_save($comment); + } + + $this->drupalLogin($this->web_user); + + // View the node page. With the default 50 comments per page there should + // be two pages (0, 1) but no third (2) page. + $this->drupalGet('node/' . $node->nid); + $this->assertText($node->title, t('Node title found.')); + $this->assertText(t('Comments'), t('Has a comments section.')); + $this->assertRaw('page=1', t('Secound page exists.')); + $this->assertNoRaw('page=2', t('No third page exists.')); + } + + /** + * Tests the forum node pager for nodes with multiple grants per realm. + */ + public function testForumPager() { + // Lookup the forums vocabulary vid. + $vid = variable_get('forum_nav_vocabulary', 0); + $this->assertTrue($vid, t('Forum navigation vocabulary found.')); + + // Lookup the general discussion term. + $tree = taxonomy_get_tree($vid, 0, 1); + $tid = reset($tree)->tid; + $this->assertTrue($tid, t('General discussion term found.')); + + // Create 30 nodes. + for ($i = 0; $i < 30; $i++) { + $this->drupalCreateNode(array( + 'nid' => NULL, + 'type' => 'forum', + 'taxonomy_forums' => array( + LANGUAGE_NONE => array( + array('tid' => $tid, 'vid' => $vid, 'vocabulary_machine_name' => 'forums'), + ), + ), + )); + } + + // View the general discussion forum page. With the default 25 nodes per + // page there should be two pages for 30 nodes, no more. + $this->drupalLogin($this->web_user); + $this->drupalGet('forum/' . $tid); + $this->assertRaw('page=1', t('Secound page exists.')); + $this->assertNoRaw('page=2', t('No third page exists.')); + } +} |