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

boombatower - August 14, 2008 - 23:50
Status:active» postponed (maintainer needs more info)

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:

<?php
parrent
::setUp('module1', 'module2');
?>

#2

jtsnow - August 15, 2008 - 01:30
Status:postponed (maintainer needs more info)» closed

Ah... that fixes the problem. Thanks! I asked for help in #drupal several times today, but couldn't get help. Issue closed.

#3

jtsnow - August 15, 2008 - 04:12
Status:closed» active

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 _drupalCreateRole
At 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

boombatower - August 15, 2008 - 05:30
Status:active» postponed (maintainer needs more info)

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

jtsnow - August 15, 2008 - 08:35
Status:postponed (maintainer needs more info)» fixed

Ok, thanks! Latest dev version works.

#6

Anonymous (not verified) - August 29, 2008 - 08:42
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#7

kenorb - July 14, 2009 - 14:23

Thanks.

#8

NancyDru - September 20, 2009 - 21:14
Status:closed» active

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

NancyDru - September 20, 2009 - 21:15

It won't show the screen shot, so here it is again.

AttachmentSize
simpletest_error.jpg 161.64 KB

#10

boombatower - September 24, 2009 - 20:57
Category:bug report» support request
Status:active» postponed (maintainer needs more info)

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

NancyDru - September 25, 2009 - 01:46

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.

AttachmentSize
st_error_1.jpg 125.25 KB
st_error_verbose_1.jpg 39.56 KB
st_error_verbose_2.jpg 44.22 KB

#12

boombatower - November 6, 2009 - 21:50
Status:postponed (maintainer needs more info)» fixed

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

System Message - November 20, 2009 - 22:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.