function OpenIDRegistrationTest::testRegisterUserWithAXButNoSREG

Test OpenID auto-registration with a provider that supplies AX information, but no SREG.

File

drupal/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php, line 234
Definition of Drupal\openid\Tests\OpenIDRegistrationTest.

Class

OpenIDRegistrationTest
Test account registration using Simple Registration and Attribute Exchange.

Namespace

Drupal\openid\Tests

Code

function testRegisterUserWithAXButNoSREG() {
  config('user.settings')
    ->set('verify_mail', FALSE)
    ->save();
  config('system.date')
    ->set('timezone.default', 'Europe/Brussels')
    ->save();

  // Tell openid_test.module to respond with these AX fields.
  state()
    ->set('openid_test.response', array(
    'openid.ns.ext123' => 'http://openid.net/srv/ax/1.0',
    'openid.ext123.type.mail456' => 'http://axschema.org/contact/email',
    'openid.ext123.value.mail456' => 'john@example.com',
    'openid.ext123.type.name789' => 'http://schema.openid.net/namePerson/friendly',
    'openid.ext123.count.name789' => '1',
    'openid.ext123.value.name789.1' => 'john',
    'openid.ext123.type.timezone' => 'http://axschema.org/pref/timezone',
    'openid.ext123.value.timezone' => 'Europe/London',
    'openid.ext123.type.language' => 'http://axschema.org/pref/language',
    'openid.ext123.value.language' => 'pt-PT',
  ));

  // Save Portuguese and Portuguese, Portugal as optional languages. The
  // process should pick 'pt-pt' as the more specific language.
  $language = new Language(array(
    'langcode' => 'pt',
  ));
  language_save($language);
  $language = new Language(array(
    'langcode' => 'pt-pt',
  ));
  language_save($language);

  // 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
    ->assertLink(t('Log out'), 0, 'User was logged in.');
  $user = user_load_by_name('john');
  $this
    ->assertTrue($user, 'User was registered with right username.');
  $this
    ->assertEqual($user->mail, 'john@example.com', 'User was registered with right email address.');
  $this
    ->assertEqual($user->timezone, 'Europe/London', 'User was registered with right timezone.');
  $this
    ->assertEqual($user->preferred_langcode, 'pt-pt', 'User was registered with right language.');
}