I'm working on test cases and having issues with creating users. My setUp function looks like this:
function setUp() {
parent::setUp('my_module');
$this->admin_user = $this->drupalCreateUser(array('administer users'));
// ...
}
On the line with $this->drupalCreateUser, I am getting a PDOException halting testing because, essentially, when user_save tries to save the new roles, it gets a primary key conflict. Apparently the new user already has the new role in the database?
Because this is a test case, only my module is installed on top of the base system. However my module doesn't do anything with roles. It does however have several user-related hook implementations to control certain information stored in $account->data. Does anybody know what's going on? Did I mess up role handling without explicitly dealing with roles at all?
Comments
Comment #1
meustrus commentedFigured it out. My hook_user_insert implementation may result in another call to
user_save(because$edithas already been written to the database) which for some reason hasn't been an issue, but even after unsetting$account->is_newit was breaking with roles because the nested call touser_savewrites the roles before the parent call touser_savewrites them. I'm modifying my code to usehook_user_presaveinstead now.