Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.46
diff -u -p -r1.46 comment.test
--- modules/comment/comment.test	29 Sep 2009 15:31:14 -0000	1.46
+++ modules/comment/comment.test	7 Oct 2009 02:05:46 -0000
@@ -8,13 +8,10 @@ class CommentHelperCase extends DrupalWe
 
   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 DrupalWe
   }
 
   /**
-   * 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 Comment
     $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 Comment
     $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 Comment
     $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 CommentHe
   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 CommentHe
 
     $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 CommentHe
     $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 Commen
    * 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 Commen
    * 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();
 
Index: modules/contact/contact.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact/contact.test,v
retrieving revision 1.31
diff -u -p -r1.31 contact.test
--- modules/contact/contact.test	26 Sep 2009 00:13:19 -0000	1.31
+++ modules/contact/contact.test	7 Oct 2009 02:05:46 -0000
@@ -22,7 +22,7 @@ class ContactSitewideTestCase extends Dr
    */
   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 Dr
     $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 Dr
     $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 Dr
     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 Dr
     $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.'));
-  }
 }
 
 /**
