Test login using OpenID.
function testLogin() {
$this
->drupalLogin($this->web_user);
// Use a User-supplied Identity that is the URL of an XRDS document.
$identity = url('openid-test/yadis/xrds', array(
'absolute' => TRUE,
));
$this
->addIdentity($identity);
$response = state()
->get('openid_test.hook_openid_response_response');
$account = state()
->get('openid_test.hook_openid_response_account');
$this
->assertEqual($response['openid.claimed_id'], $identity, 'hook_openid_response() was invoked.');
$this
->assertEqual($account->uid, $this->web_user->uid, 'Proper user object passed to hook_openid_response().');
$this
->drupalLogout();
// Test logging in via the login block on the front page.
state()
->delete('openid_test.hook_openid_response_response');
state()
->delete('openid_test.hook_openid_response_account');
$this
->submitLoginForm($identity);
$this
->assertLink(t('Log out'), 0, 'User was logged in.');
$response = state()
->get('openid_test.hook_openid_response_response');
$account = state()
->get('openid_test.hook_openid_response_account');
$this
->assertEqual($response['openid.claimed_id'], $identity, 'hook_openid_response() was invoked.');
$this
->assertEqual($account->uid, $this->web_user->uid, 'Proper user object passed to hook_openid_response().');
$this
->drupalLogout();
// Test logging in via the user/login/openid page.
$edit = array(
'openid_identifier' => $identity,
);
$this
->drupalPost('user/login/openid', $edit, t('Log in'));
// Check we are on the OpenID redirect form.
$this
->assertTitle(t('OpenID redirect'), 'OpenID redirect page was displayed.');
// Submit form to the OpenID Provider Endpoint.
$this
->drupalPost(NULL, array(), t('Send'));
$this
->assertLink(t('Log out'), 0, 'User was logged in.');
// Verify user was redirected away from user/login/openid to an accessible
// page.
$this
->assertResponse(200);
$this
->drupalLogout();
// Tell openid_test.module to alter the checkid_setup request.
$new_identity = 'http://example.com/' . $this
->randomName();
state()
->set('openid_test.identity', $new_identity);
state()
->set('openid_test.request_alter', array(
'checkid_setup' => array(
'openid.identity' => $new_identity,
),
));
$this
->submitLoginForm($identity);
$this
->assertLink(t('Log out'), 0, 'User was logged in.');
$response = state()
->get('openid_test.hook_openid_response_response');
$this
->assertEqual($response['openid.identity'], $new_identity, 'hook_openid_request_alter() were invoked.');
$this
->drupalLogout();
// Use a User-supplied Identity that is the URL of an XRDS document.
// Tell the test module to add a doctype. This should fail.
$identity = url('openid-test/yadis/xrds', array(
'absolute' => TRUE,
'query' => array(
'doctype' => 1,
),
));
// Test logging in via the login block on the front page.
$edit = array(
'openid_identifier' => $identity,
);
$this
->drupalPost('', $edit, t('Log in'), array(), array(), 'openid-login-form');
$this
->assertRaw(t('Sorry, that is not a valid OpenID. Ensure you have spelled your ID correctly.'), 'XML with DOCTYPE was rejected.');
}