? log.txt ? modules/simpletest/tests/343502.test ? modules/simpletest/tests/path.test ? modules/system/system.http.inc Index: modules/comment/comment.test =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v retrieving revision 1.20 diff -u -p -r1.20 comment.test --- modules/comment/comment.test 28 Nov 2008 09:34:42 -0000 1.20 +++ modules/comment/comment.test 6 Dec 2008 04:54:13 -0000 @@ -9,12 +9,9 @@ class CommentHelperCase extends DrupalWe function setUp() { parent::setUp('comment'); // Create users. - $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer permissions')); + $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments')); $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)); } /** @@ -160,23 +157,6 @@ class CommentHelperCase extends DrupalWe } /** - * Set anonymous comment setting. - * - * @param boolean $enabled - * Allow anonymous commenting. - * @param boolean $without_approval - * Allow anonymous commenting without approval. - */ - function setAnonymousUserComment($enabled, $without_approval) { - $edit = array(); - $edit['1[access comments]'] = $enabled; - $edit['1[post comments]'] = $enabled; - $edit['1[post comments without approval]'] = $without_approval; - $this->drupalPost('admin/user/permissions', $edit, t('Save permissions')); - $this->assertText(t('The changes have been saved.'), t('Anonymous user comments ' . ($enabled ? 'enabled' : 'disabled') . '.')); - } - - /** * Check for contact info. * * @return boolean Contact info is available. @@ -387,7 +367,7 @@ class CommentAnonymous extends CommentHe function testAnonymous() { $this->drupalLogin($this->admin_user); // Enabled anonymous user comments. - $this->setAnonymousUserComment(TRUE, TRUE); + $this->drupalSetPermissions('anonymous user', array('access content', 'access comments', 'post comments', 'post comments without approval')); $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info. $this->drupalLogout(); @@ -447,16 +427,16 @@ 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); + // Reset permissions. + $this->drupalSetPermissions('anonymous user', array('access content')); // 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->assertTrue(FALSE, htmlspecialchars($this->drupalGetContent())); $this->assertNoRaw('
', t('Comments were not displayed.')); $this->assertNoLink('Add new comment', t('Link to add comment was found.')); @@ -483,8 +463,8 @@ class CommentApprovalTest extends Commen function testApprovalAdminInterface() { $this->drupalLogin($this->admin_user); - // Set anonymouse comments to require approval. - $this->setAnonymousUserComment(TRUE, FALSE); + // Set anonymous comments to require approval. + $this->drupalSetPermissions('anonymous user', array('access content', 'access comments', 'post comments')); $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info. $this->drupalLogout(); @@ -517,8 +497,8 @@ class CommentApprovalTest extends Commen function testApprovalNodeInterface() { $this->drupalLogin($this->admin_user); - // Set anonymouse comments to require approval. - $this->setAnonymousUserComment(TRUE, FALSE); + // Set anonymous comments to require approval. + $this->drupalSetPermissions('anonymous user', array('access content', 'access comments', 'post comments')); $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.13 diff -u -p -r1.13 contact.test --- modules/contact/contact.test 25 Nov 2008 13:14:26 -0000 1.13 +++ modules/contact/contact.test 6 Dec 2008 04:54:14 -0000 @@ -22,7 +22,7 @@ class ContactSitewideTestCase extends Dr */ function testSiteWideContact() { // Create and login administative user. - $admin_user = $this->drupalCreateUser(array('administer site-wide contact form', 'administer permissions')); + $admin_user = $this->drupalCreateUser(array('administer site-wide contact form')); $this->drupalLogin($admin_user); // Set settings. @@ -38,7 +38,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)); + $this->drupalSetPermissions('anonymous user', array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('The contact form has not been configured.'), t('Contact form will not work without categories configured.')); @@ -73,7 +73,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)); + $this->drupalSetPermissions('anonymous user', array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText($contact_form_information, t('Contact form is shown when there is one category.')); @@ -91,17 +91,14 @@ class ContactSitewideTestCase extends Dr $this->assertTrue(db_query('DELETE FROM {flood}'), 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->drupalSetPermissions('anonymous user', array()); $this->drupalLogout(); $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(); - + $this->drupalSetPermissions('anonymous user', array('access site-wide contact form')); $this->drupalGet('contact'); $this->assertResponse(200, t('Access granted to anonymous user with permission.')); @@ -227,29 +224,6 @@ class ContactSitewideTestCase extends Dr } 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_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", array($role))); - 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/user/permissions', $edit, t('Save permissions')); - $this->assertText(t('The changes have been saved.'), t(' [permission] Saved changes.')); - } } /** Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.67 diff -u -p -r1.67 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 3 Dec 2008 16:32:22 -0000 1.67 +++ modules/simpletest/drupal_web_test_case.php 6 Dec 2008 04:54:17 -0000 @@ -622,9 +622,9 @@ class DrupalWebTestCase { * A fully loaded user object with pass_raw property, or FALSE if account * creation fails. */ - protected function drupalCreateUser($permissions = NULL) { + protected function drupalCreateUser(array $permissions = array('access comments', 'access content', 'post comments', 'post comments without approval')) { // Create a role with the given permission set. - if (!($rid = $this->_drupalCreateRole($permissions))) { + if (!($rid = $this->drupalCreateRole($permissions))) { return FALSE; } @@ -649,35 +649,64 @@ class DrupalWebTestCase { } /** - * Internal helper function; Create a role with specified permissions. + * Assign permissions to a user role. * + * @param $role + * The user role to assign permissions. * @param $permissions * Array of permission names to assign to role. * @return - * Role ID of newly created role, or FALSE if role creation failed. + * TRUE if the role is a valid role and the permissions have been + * assigned, otherwise FALSE. */ - protected function _drupalCreateRole(array $permissions = NULL) { - // Generate string version of permissions list. - if ($permissions === NULL) { - $permissions = array('access comments', 'access content', 'post comments', 'post comments without approval'); + protected function drupalSetPermissions($role, array $permissions = array()) { + $rid = db_query("SELECT rid FROM {role} WHERE name = :name", array(':name' => $role))->fetchField(); + if ($rid === FALSE) { + $this->fail(t('Role %role not found.', array('%role' => $role))); + return FALSE; } if (!$this->checkPermissions($permissions)) { return FALSE; } + // Clear permissions for role. + db_delete('role_permission') + ->condition('rid', $rid) + ->execute(); + + // Assign permissions to role. + foreach ($permissions as $permission_string) { + db_insert('role_permission') + ->fields(array( + 'rid' => $rid, + 'permission' => $permission_string, + )) + ->execute(); + } + + $count = db_query("SELECT COUNT(*) FROM {role_permission} WHERE rid = :rid", array(':rid' => $rid))->fetchField(); + $result = $count == count($permissions); + $this->assertTrue($result, t('Assigned permissions to role %role: @perms', array('%role' => $role, '@perms' => implode(', ', $permissions))), t('Role')); + + return $result; + } + + /** + * Create a role with specified permissions. + * + * @param $permissions + * Array of permission names to assign to role. + * @return + * Role ID of newly created role, or FALSE if role creation failed. + */ + protected function drupalCreateRole(array $permissions = array()) { // Create new role. $role_name = $this->randomName(); db_query("INSERT INTO {role} (name) VALUES ('%s')", $role_name); $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = '%s'", $role_name)); $this->assertTrue($role, t('Created role of name: @role_name, id: @rid', array('@role_name' => $role_name, '@rid' => (isset($role->rid) ? $role->rid : t('-n/a-')))), t('Role')); - if ($role && !empty($role->rid)) { - // Assign permissions to role and mark it for clean-up. - foreach ($permissions as $permission_string) { - db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", $role->rid, $permission_string); - } - $count = db_result(db_query("SELECT COUNT(*) FROM {role_permission} WHERE rid = %d", $role->rid)); - $this->assertTrue($count == count($permissions), t('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), t('Role')); + if ($role && !empty($role->rid) && $this->drupalSetPermissions($role->name, $permissions)) { return $role->rid; } else { @@ -729,7 +758,7 @@ class DrupalWebTestCase { } if (!isset($user)) { - $user = $this->_drupalCreateRole(); + $user = $this->drupalCreateUser(); } $edit = array( @@ -821,10 +850,10 @@ class DrupalWebTestCase { } /** - * This method is called by DrupalWebTestCase::setUp, and preloads the - * registry from the testing site to cut down on the time it takes to - * setup the a clean environment for the current test run. - */ + * This method is called by DrupalWebTestCase::setUp, and preloads the + * registry from the testing site to cut down on the time it takes to + * setup the a clean environment for the current test run. + */ protected function preloadRegistry() { db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry'); db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file'); Index: modules/simpletest/simpletest.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.test,v retrieving revision 1.12 diff -u -p -r1.12 simpletest.test --- modules/simpletest/simpletest.test 2 Dec 2008 20:03:57 -0000 1.12 +++ modules/simpletest/simpletest.test 6 Dec 2008 04:54:17 -0000 @@ -136,7 +136,8 @@ class SimpleTestTestCase extends DrupalW $this->assertAssertion($this->pass, 'Other', 'Pass', 'simpletest.test', 'SimpleTestTestCase->stubTest()'); $this->assertAssertion($this->fail, 'Other', 'Fail', 'simpletest.test', 'SimpleTestTestCase->stubTest()'); - $this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->valid_permission)), 'Role', 'Pass', 'simpletest.test', 'SimpleTestTestCase->stubTest()'); + $this->assertAssertion(t('Assigned permissions to role'), 'Role', 'Pass', 'simpletest.test', 'SimpleTestTestCase->stubTest()'); + $this->assertAssertion(t('@perms', array('@perms' => $this->valid_permission)), 'Role', 'Pass', 'simpletest.test', 'SimpleTestTestCase->stubTest()'); $this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalid_permission)), 'Role', 'Fail', 'simpletest.test', 'SimpleTestTestCase->stubTest()'); // Check that a warning is catched by simpletest.