Cannot create user with permissions for contrib modules.
jtsnow - August 14, 2008 - 23:22
| Project: | SimpleTest |
| Version: | 6.x-2.1 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
I cannot create a user with permissions for contrib modules. For example:
<?php
function setUp() {
parent::setUp();
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($admin_user);
}
/**
* Test
*/
function testSourceEnable() {
$this->drupalGet('admin/build/testing', array());
$this->assertText(t('Run all tests (WARNING, this may take a long time)'), t('Test page accessed.'));
}
?>Running that test gives the following error:
Invalid permission administer unit tests. Role drupal_web_test_case.php 514 checkPermissions
Plus additional errors because the user could not be logged in.
Creating a user with core permissions works great.

#1
From looking at the code it would appear that it is running as to be expected.
The code doesn't enable the simpletest module which contains that permission. The code it would appear you copied comes from simpletest.test:
<?php
parent::setUp('simpletest');
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($admin_user);
?>
it checks against the list of permissions available for the enabled modules.
Try enabling the simpletest module and see if it works.
Make sure you enable your contrib modules in the tests you write.
You can specify a list:
<?phpparrent::setUp('module1', 'module2');
?>
#2
Ah... that fixes the problem. Thanks! I asked for help in #drupal several times today, but couldn't get help. Issue closed.
#3
Sorry... re-opening!
It seems that if only one permission is specified like in your example, then the error doesn't occur.
If multiple permissions are specified, like in the CCK module's tests, the error does occur:
<?php
?>
Gives the error:
Created permissions: access content, administer content types, administer nodes, administer filters Role drupal_web_test_case.php 476 _drupalCreateRoleAt least, it appears to be an error because the row is red and it as the red X icon.
This is not limited to contrib module permissions:
<?php
function setUp() {
parent::setUp();
// Create and login user
$admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
$this->drupalLogin($admin_user);
}
?>
Gives the error:
Created permissions: access content, administer blocks Role drupal_web_test_case.php 476 _drupalCreateRole#4
Please make sure your using the latest development release. It fixed a bug related to permission system. I run that code and it works.
Once a patch I've been waiting for gets into core I will backport it and make a new release of this module with the bug fix and other changes.
#5
Ok, thanks! Latest dev version works.
#6
Automatically closed -- issue fixed for two weeks with no activity.
#7
Thanks.
#8
Sorry to reopen this, but it looks like my problem.
I uninstalled ST, downloaded the -dev about an hour ago, re-installed ST, ran update.php, and this still fails.
function setUp() {// This installs the Weblinks module, which is the module this suite is testing.
parent::setUp('weblinks', 'node', 'menu');
// module_disable(array('taxonomy'));
function testWeblinksCreate() {// @TODO: add a test for "user's links"
// Prepare a user to do the stuff.
$user = $this->drupalCreateUser(array('access content', 'access web links', 'create weblinks', 'edit own weblinks'));
$this->drupalLogin($user);
I get:
#9
It won't show the screen shot, so here it is again.
#10
According to the assertions it properly created the user. It would seem somehting else is wrong. Try out the new verbose mode by enabling it in the settings, running the test, and then viewing what the browser saw when trying to submit that form.
#11
BTW, an additional problem I see, if it gives you any insight, is that "module_load_include" does not seem to be working; I have to actually copy the included code into the module.
Other errors occurred this time, but farther down. Let's deal with these first.
#12
This issue seems unrelated to creating the user, rather it has to to do with loggin in. If you still have this issue please make a new issue and post a full tests or something I can use to re-create. Any test I run does not encounter this.
#13
Automatically closed -- issue fixed for 2 weeks with no activity.