I can't explain this, so I think it's a bug..

  function testCreateUser()
  {
    $recipient1  = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
    $recipient2  = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));

    $this->assertTrue(user_access('write privatemsg', $recipient1));
    $this->assertTrue(user_access('write privatemsg', $recipient2));
  }

On of the assertTrue fails, depending on the order of the drupalCreateUser calls..

Comments

boombatower’s picture

I don't have the module your testing with, but:

    $recipient1  = $this->drupalCreateUser(array('administer blocks'));
    $recipient2  = $this->drupalCreateUser(array('administer blocks'));

    $this->assertTrue(user_access('administer blocks', $recipient1));
    $this->assertTrue(user_access('administer blocks', $recipient2));

works.

Please include your full test and the module your using (link) so I can test.

berdir’s picture

Interesting. I'm having the same or atleast similiar issues on my PC and my Laptop, both have the latest simpletest-6.x-2.x-dev installed.

The tests are part of a patch I'm working on, see #375999-8: #288183 followup: Developer friendlify privatemsg_new_thread API. .

boombatower’s picture

I can't seem to re-create this with anything other than your test and code.

This in D7 which requires a module to be enabled at setup and both permissions provided by that module is an identical case...it works. I'm not sure what to say...seems like some debugging is in order.

    $recipient1  = $this->drupalCreateUser(array('administer url aliases', 'create url aliases'));
    $recipient2  = $this->drupalCreateUser(array('administer url aliases', 'create url aliases'));

    $this->assertTrue(user_access('create url aliases', $recipient1));
    $this->assertTrue(user_access('create url aliases', $recipient2));

Edit: same test works in D6.

berdir’s picture

Ah, I found it.

It works fine if you have only one of those tests. However, If you have multiple of those tests and test directly and not over HTTP, the error happens.

And the reason for this is again the nemesis of tests... static cache. user_access stores the pemissions of each user in a static array, where uid is the key. However, a new test function creates new users in a new database.. and with the same uid's as before.

Suggestion for a workaround: Call user_access('', NULL, TRUE) in setUp() to reset the static cache. This may need to be done for other things too...

Another reason why we need a standardized static cache solution: #254491: Standardize static caching.

boombatower’s picture

Yea it was kinda feeling like that. Good to know...so it would be really nice to the static stuff working.

How would you like to mark this issue?

berdir’s picture

This issue is about 6.x-2.x. And there will never be a centralized static cache solution in D6 so I think we need to add a workaround. It works fine to add the user_access reset call in the test code itself but this is easily forgotten and pretty hard to debug.

I can provide a patch if you like.

boombatower’s picture

Please do.

Thanks

berdir’s picture

Status: Active » Needs review
StatusFileSize
new2.27 KB

I am a bit confused by the DrupalWebTestCase and DrupalWebTestCaseCore classes, both seem to contain the same setUp() functions.

I added the user_access reset to both for now. I also added two simple test functions for the user_access cache, the second one fails without the change in setUp().

boombatower’s picture

The DrupalWebTestCaseCore is a direct copy from Drupal 7.x. The DrupalWebTestCase overrides the methods that require changing for Drupal 6. So only need to add it to the DrupalWebTestCase.

berdir’s picture

StatusFileSize
new1.65 KB

Updated patch, removed change of core class.

boombatower’s picture

Title: Creating two users with same permissions fails » Clear user_access() cache
Status: Needs review » Fixed

Committed.

Thanks.

Status: Fixed » Closed (fixed)

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