Need reviews on assigning permissions in SimpleTest

Events happening in the community are now at Drupal community events on www.drupal.org.
dave reid's picture

Several core tests (contact, comment, poll) have a need to be to adjust the permissions for anonymous users. We can easily adjust permissions for users by calling drupalCreateUser() with different permissions, but we don't have an easy way to do the same thing for anonymous users. As of now, the tests have to add an admin user with the permission 'administer user permissions' and use drupalPost() to adjust the admin/user/permissions page. This implementation is ugly and wasting effort by duplication.

Since we provide the drupalCreateUser() and drupalCreateRole() methods in DrupalWebTestCase, I proposed adding a drupalSetPermissions() that could be easily reused throughout core tests and would be very handy for a lot of contrib module tests. But it needs more reviews. The changes proposed in the patch so far are the following:

  • Adds a new protected function drupalSetPermissions($role, array $permissions) to drupalWebTestCase to assign permissions to role name $role.
  • Takes the permissions code out of _drupalCreateRole() so it can be reused.
  • Replaces the manual permissions setting in comment.test and contact.test with the more elegant drupalSetPermissions(). The permissions interface is tested throughly in user.test.
  • Renamed _drupalCreateRole() to drupalCreateRole() for standardization.
  • Reworked the default parameters of drupalCreateRole(), drupalSetPermissions(), and drupalCreateUser() for easier use.
  • Reworked the tests in simpletest.test since assertAssertion() uses strpos and not a regex-style string matching. The assertion being checked for is 'Assigned permissions to role %role: @perms'. During simpletest.test, we don't have any way to get the name of the user role created during the test, so we just do two checks. One for 'Assigned permissions to role' and another for $this->valid_permission.
  • Fixed a bug in drupalLogin($user = NULL)! The documentation for the function says specifically "If no user is specified then a new user will be created and logged in."

Please come review the issue at http://drupal.org/node/300993 and provide your input.

Testing and Quality Assurance

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: