diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-08 08:16:54 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-08 08:16:54 +0000 |
commit | f06ed4f6707b40b2eaa16523a8f777418c1db547 (patch) | |
tree | 58bdfaa95e1bc9a1704a38c72cd4a03729173be0 | |
parent | c4e1242e92f3bcedc15a663821e080dcea4be4b8 (diff) | |
download | brdo-f06ed4f6707b40b2eaa16523a8f777418c1db547.tar.gz brdo-f06ed4f6707b40b2eaa16523a8f777418c1db547.tar.bz2 |
#300993 follow-up by Dave Reid: Remove cruft from tests now that we have a real permissions API.
-rw-r--r-- | modules/comment/comment.test | 75 | ||||
-rw-r--r-- | modules/contact/contact.test | 39 |
2 files changed, 40 insertions, 74 deletions
diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 216b41aa5..79e54c516 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -8,13 +8,10 @@ class CommentHelperCase extends DrupalWebTestCase { function setUp() { parent::setUp('comment', 'search'); - // Create users. - $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer permissions', 'administer blocks')); + // Create users and test node. + $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks')); $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content')); - - $this->drupalLogin($this->web_user); - $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); - $this->drupalLogout(); + $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid)); } /** @@ -162,25 +159,6 @@ class CommentHelperCase extends DrupalWebTestCase { } /** - * Set anonymous comment setting. - * - * @param boolean $access_comments - * Allow anonymous access to comments. - * @param boolean $post_comments - * Allow anonymous posting of comments. - * @param boolean $without_approval - * Allow anonymous commenting without approval. - */ - function setAnonymousUserComment($access_comments, $post_comments, $without_approval) { - $edit = array(); - $edit['1[access comments]'] = $access_comments; - $edit['1[post comments]'] = $post_comments; - $edit['1[post comments without approval]'] = $without_approval; - $this->drupalPost('admin/config/people/permissions', $edit, t('Save permissions')); - $this->assertText(t('The changes have been saved.'), t('Anonymous user comments ' . ($access_comments ? 'access comments' : 'not access comments'). '.')); - } - - /** * Check for contact info. * * @return boolean Contact info is available. @@ -401,7 +379,7 @@ class CommentPreviewTest extends CommentHelperCase { $this->assertFieldByName('subject', $edit['subject'], t('Subject field displayed.')); $this->assertFieldByName('comment', $edit['comment'], t('Comment field displayed.')); } - + /** * Test comment edit and preview. */ @@ -412,7 +390,7 @@ class CommentPreviewTest extends CommentHelperCase { $this->setCommentForm(TRUE); $this->setCommentSubject(TRUE); $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.')); - + $edit = array(); $edit['subject'] = $this->randomName(8); $edit['comment'] = $this->randomName(16); @@ -421,7 +399,7 @@ class CommentPreviewTest extends CommentHelperCase { $expected_date = format_date(strtotime($edit['date'])); $comment = $this->postComment($this->node, $edit['subject'], $edit['comment'], TRUE); $this->drupalPost('comment/edit/' . $comment->id, $edit, t('Preview')); - + // Check that the preview is displaying the subject, comment, author and date correctly. $this->assertTitle(t('Preview comment | Drupal'), t('Page title is "Preview comment".')); $this->assertText($edit['subject'], t('Subject displayed.')); @@ -453,7 +431,11 @@ class CommentAnonymous extends CommentHelperCase { function testAnonymous() { $this->drupalLogin($this->admin_user); // Enabled anonymous user comments. - $this->setAnonymousUserComment(TRUE, TRUE, TRUE); + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => TRUE, + 'post comments' => TRUE, + 'post comments without approval' => TRUE, + )); $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info. $this->drupalLogout(); @@ -513,15 +495,18 @@ class CommentAnonymous extends CommentHelperCase { $this->drupalGet('admin/content/comment'); $this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', t('Comment was deleted.')); + $this->drupalLogout(); // Reset. - $this->drupalLogin($this->admin_user); - $this->setAnonymousUserComment(FALSE, FALSE, FALSE); + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => FALSE, + 'post comments' => FALSE, + 'post comments without approval' => FALSE, + )); // Attempt to view comments while disallowed. // NOTE: if authenticated user has permission to post comments, then a // "Login or register to post comments" type link may be shown. - $this->drupalLogout(); $this->drupalGet('node/' . $this->node->nid); $this->assertNoPattern('/<div ([^>]*?)id="comments"([^>]*?)>/', t('Comments were not displayed.')); $this->assertNoLink('Add new comment', t('Link to add comment was found.')); @@ -532,9 +517,11 @@ class CommentAnonymous extends CommentHelperCase { $this->assertNoFieldByName('subject', '', t('Subject field not found.')); $this->assertNoFieldByName('comment', '', t('Comment field not found.')); - $this->drupalLogin($this->admin_user); - $this->setAnonymousUserComment(TRUE, FALSE, FALSE); - $this->drupalLogout(); + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => TRUE, + 'post comments' => FALSE, + 'post comments without approval' => FALSE, + )); $this->drupalGet('node/' . $this->node->nid); $this->assertPattern('/<div ([^>]*?)id="comments"([^>]*?)>/', t('Comments were displayed.')); $this->assertLink('Login', 1, t('Link to login was found.')); @@ -642,10 +629,13 @@ class CommentApprovalTest extends CommentHelperCase { * Test comment approval functionality through admin/content/comment. */ function testApprovalAdminInterface() { - $this->drupalLogin($this->admin_user); - // Set anonymous comments to require approval. - $this->setAnonymousUserComment(TRUE, TRUE, FALSE); + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => TRUE, + 'post comments' => TRUE, + 'post comments without approval' => FALSE, + )); + $this->drupalLogin($this->admin_user); $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info. $this->drupalLogout(); @@ -676,10 +666,13 @@ class CommentApprovalTest extends CommentHelperCase { * Test comment approval functionality through node interface. */ function testApprovalNodeInterface() { - $this->drupalLogin($this->admin_user); - // Set anonymous comments to require approval. - $this->setAnonymousUserComment(TRUE, TRUE, FALSE); + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => TRUE, + 'post comments' => TRUE, + 'post comments without approval' => FALSE, + )); + $this->drupalLogin($this->admin_user); $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info. $this->drupalLogout(); diff --git a/modules/contact/contact.test b/modules/contact/contact.test index 381dbffb5..300142836 100644 --- a/modules/contact/contact.test +++ b/modules/contact/contact.test @@ -22,7 +22,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { */ function testSiteWideContact() { // Create and login administrative user. - $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions', 'administer users')); + $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer users')); $this->drupalLogin($admin_user); $flood_limit = 3; @@ -39,7 +39,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { $this->deleteCategories(); // Ensure that the contact form won't be shown without categories. - $this->setPermission('anonymous user', array('access site-wide contact form' => TRUE)); + user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertResponse(404); @@ -80,7 +80,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { $this->assertRaw(t('Category %category has been updated.', array('%category' => $category)), t('Category successfully updated.')); // Ensure that the contact form is shown without a category selection input. - $this->setPermission('anonymous user', array('access site-wide contact form' => TRUE)); + user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your e-mail address'), t('Contact form is shown when there is one category.')); @@ -98,19 +98,15 @@ class ContactSitewideTestCase extends DrupalWebTestCase { db_delete('flood')->execute(); $num_records_after = db_query("SELECT COUNT(*) FROM {flood}")->fetchField(); $this->assertIdentical($num_records_after, '0', t('Flood table emptied.')); - - // Check to see that anonymous user cannot see contact page without permission. - $this->setPermission('anonymous user', array('access site-wide contact form' => FALSE)); $this->drupalLogout(); + // Check to see that anonymous user cannot see contact page without permission. + user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalGet('contact'); $this->assertResponse(403, t('Access denied to anonymous user without permission.')); // Give anonymous user permission and see that page is viewable. - $this->drupalLogin($admin_user); - $this->setPermission('anonymous user', array('access site-wide contact form' => TRUE)); - $this->drupalLogout(); - + user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalGet('contact'); $this->assertResponse(200, t('Access granted to anonymous user with permission.')); @@ -272,29 +268,6 @@ class ContactSitewideTestCase extends DrupalWebTestCase { $categories = db_query('SELECT cid FROM {contact}')->fetchCol(); return $categories; } - - /** - * Set permission. - * - * @param string $role User role to set permissions for. - * @param array $permissions Key-value array of permissions to set. - */ - function setPermission($role, $permissions) { - // Get role id (rid) for specified role. - $rid = db_query("SELECT rid FROM {role} WHERE name = :name", array(':name' => $role))->fetchField(); - if ($rid === FALSE) { - $this->fail(t(' [permission] Role "' . $role . '" not found.')); - } - - // Create edit array from permission. - $edit = array(); - foreach ($permissions as $name => $value) { - $edit[$rid . '[' . $name . ']'] = $value; - } - - $this->drupalPost('admin/config/people/permissions', $edit, t('Save permissions')); - $this->assertText(t('The changes have been saved.'), t(' [permission] Saved changes.')); - } } /** |