function ProfileAttachTest::testUserRegisterForm in Profile 2 8
Test user registration integration.
File
- src/
Tests/ ProfileAttachTest.php, line 75 - Contains \Drupal\profile\Tests\ProfileAttachTest.
Class
- ProfileAttachTest
- Tests attaching of profile entity forms to other forms.
Namespace
Drupal\profile\TestsCode
function testUserRegisterForm() {
$id = $this->type
->id();
$field_name = $this->field->field_name;
// Allow registration without administrative approval and log in user
// directly after registering.
\Drupal::config('user.settings')
->set('register', USER_REGISTER_VISITORS)
->set('verify_mail', 0)
->save();
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
'view own test profile',
));
// Verify that the additional profile field is attached and required.
$name = $this
->randomMachineName();
$pass_raw = $this
->randomMachineName();
$edit = array(
'name' => $name,
'mail' => $this
->randomMachineName() . '@example.com',
'pass[pass1]' => $pass_raw,
'pass[pass2]' => $pass_raw,
);
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertRaw(format_string('@name field is required.', array(
'@name' => $this->instance->label,
)));
// Verify that we can register.
$edit["entity_" . $id . "[{$field_name}][0][value]"] = $this
->randomMachineName();
$this
->drupalPostForm(NULL, $edit, t('Create new account'));
$this
->assertText(format_string('Registration successful. You are now logged in.'));
$new_user = user_load_by_name($name);
$this
->assertTrue($new_user
->isActive(), 'New account is active after registration.');
// Verify that a new profile was created for the new user ID.
$profiles = entity_load_multiple_by_properties('profile', array(
'uid' => $new_user
->id(),
'type' => $this->type
->id(),
));
$profile = reset($profiles);
$this
->assertEqual($profile
->get($field_name)->value, $edit["entity_" . $id . "[{$field_name}][0][value]"], 'Field value found in loaded profile.');
// Verify that the profile field value appears on the user account page.
$this
->drupalGet('user');
$this
->assertText($edit["entity_" . $id . "[{$field_name}][0][value]"], 'Field value found on user account page.');
}