Test OpenID auto-registration with a provider that supplies invalid SREG information (a username that is already taken, and no e-mail address).
function testRegisterUserWithInvalidSreg() {
config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'Europe/Brussels')
->save();
// Tell openid_test.module to respond with these SREG fields.
$web_user = $this
->drupalCreateUser(array());
state()
->set('openid_test.response', array(
'openid.sreg.nickname' => $web_user->name,
'openid.sreg.email' => 'mail@invalid#',
'openid.sreg.timezone' => 'Foo/Bar',
'openid.sreg.language' => 'foobar',
));
// Use a User-supplied Identity that is the URL of an XRDS document.
$identity = url('openid-test/yadis/xrds', array(
'absolute' => TRUE,
));
$this
->submitLoginForm($identity);
$this
->assertRaw(t('Account registration using the information provided by your OpenID provider failed due to the reasons listed below. Complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array(
'@login' => url('user/login'),
)), 'User was asked to complete the registration process manually.');
$this
->assertRaw(t('The name %name is already taken.', array(
'%name' => $web_user->name,
)), 'Form validation error for username was displayed.');
$this
->assertRaw(t('The e-mail address %mail is not valid.', array(
'%mail' => 'mail@invalid#',
)), 'Form validation error for e-mail address was displayed.');
$this
->assertTrue(state()
->get('openid_test.hook_openid_response_response'), 'hook_openid_response() was invoked.');
$this
->assertFalse(state()
->get('openid_test.hook_openid_response_account'), 'No user object passed to hook_openid_response().');
// Enter username and e-mail address manually.
state()
->delete('openid_test.hook_openid_response_response');
$edit = array(
'name' => 'john',
'mail' => 'john@example.com',
);
$this
->drupalPost(NULL, $edit, t('Create new account'));
$this
->assertRaw(t('Once you have verified your e-mail address, you may log in via OpenID.'), 'User was asked to verify e-mail address.');
$reset_url = $this
->getPasswordResetURLFromMail();
$user = user_load_by_name('john');
$this
->assertTrue($user, 'User was registered with right username.');
$this
->assertEqual($user->preferred_langcode, language_default()->langcode, 'User language is site default.');
// Follow the one-time login that was sent in the welcome e-mail.
$this
->drupalGet($reset_url);
$this
->drupalPost(NULL, array(), t('Log in'));
$this
->assertFalse(state()
->get('openid_test.hook_openid_response_response'), 'hook_openid_response() was not invoked.');
// The user is taken to user/%uid/edit.
$this
->assertFieldByName('mail', 'john@example.com', 'User was registered with right e-mail address.');
$this
->clickLink(t('OpenID identities'));
$this
->assertRaw($identity, 'OpenID identity was registered.');
}