How can I programmatically create a new user for use during a SimpleTest? The user must have certain custom fields populated during the registration.
I'm using $this->drupalPost('user/register', $edit, 'Create new account');
to create the account currently as I do not see a way to populate custom profile fields with drupalCreateUser()
.
$edit = array(
'name' => $this->randomName(17),
'mail' => $this->randomName(17) . '@example.com',
'field_owner_first_name[und][0][value]' => $this->randomName(17),
'field_owner_last_name[und][0][value]' => $this->randomName(17),
'field_owner_title[und][0][value]' => $this->randomName(8),
'field_business_name[und][0][value]' => $this->randomName(17),
'field_business_phone[und][0][value]' => mt_rand(200, 999) . '-' . mt_rand(200, 999) . '-' . mt_rand(1000, 9999),
'field_business_email[und][0][value]' => $this->randomName(17) . '@example.com',
'field_business_website[und][0][value]' => 'http://' . $this->randomName(17) . '.com',
'field_business_address_1[und][0][value]' => mt_rand(1, 9999) . ' ' . $this->randomName(12) . ' ' . $this->randomName(2),
'field_business_address_2[und][0][value]' => 'Apt ' . mt_rand(1, 999),
'field_city[und][0][value]' => $this->randomName(8),
'field_state[und]' => 'HI',
'field_zip[und][0][value]' => mt_rand(10000, 99999),
'field_request_website[und]' => 'Yes',
);
$this->drupalPost('user/register', $edit, 'Create new account');
The code above successfully completes and posts the registration form.
How can I automatically approve and login as this newly submitted user for testing? Do I need to write tests to login the admin account, find and then approve the user?
Additional Thoughts and Clarification:
Looking at other options, can I somehow use variable_set()
to accomplish the automated user approval above when the setUp()
method is called?