You are here

public function FieldProviderTest::testSyncValidatorIsSynced in Lightweight Directory Access Protocol (LDAP) 8.4

Prove that field syncs work and provide the demo data here.

File

ldap_user/tests/src/Kernel/FieldProviderTest.php, line 119

Class

FieldProviderTest
Field Provider tests.

Namespace

Drupal\Tests\ldap_user\Kernel

Code

public function testSyncValidatorIsSynced() : void {
  $container = \Drupal::getContainer();
  $config_factory = $container
    ->get('config.factory');
  $config = $config_factory
    ->getEditable('ldap_user.settings');
  $config
    ->set('ldapUserSyncMappings', $this->data)
    ->set('drupalAcctProvisionTriggers', [
    'drupal_on_login' => 'drupal_on_login',
    'drupal_on_update_create' => 'drupal_on_update_create',
  ])
    ->save();
  $processor = new FieldProvider($config_factory, $container
    ->get('entity_type.manager'), $container
    ->get('module_handler'), $container
    ->get('entity_field.manager'));
  $processor
    ->loadAttributes(LdapUserAttributesInterface::PROVISION_TO_DRUPAL, $this->server);
  $data = $processor
    ->getConfigurableAttributesSyncedOnEvent(LdapUserAttributesInterface::EVENT_CREATE_DRUPAL_USER);
  self::assertCount(2, $data);
  self::assertCount(2, $data['[property.name]']
    ->getProvisioningEvents());
  $data = $processor
    ->getConfigurableAttributesSyncedOnEvent(LdapUserAttributesInterface::EVENT_SYNC_TO_LDAP_ENTRY);
  self::assertEmpty($data);
  $data = $processor
    ->getAttributesSyncedOnEvent(LdapUserAttributesInterface::EVENT_CREATE_DRUPAL_USER);
  self::assertEquals('not configurable', $data['[field.ldap_user_current_dn]']
    ->getNotes());
  self::assertTrue($data['[property.picture]']
    ->isEnabled());
  self::assertEquals('ldap_user', $data['[property.picture]']
    ->getProvisioningModule());
  self::assertEquals('[picture_field]', $data['[property.picture]']
    ->getLdapAttribute());
  self::assertEquals('[mail]', $data['[property.mail]']
    ->getLdapAttribute());
  self::assertTrue($processor
    ->attributeIsSyncedOnEvent('[property.name]', LdapUserAttributesInterface::EVENT_SYNC_TO_DRUPAL_USER));
  self::assertFalse($processor
    ->attributeIsSyncedOnEvent('[field.test_field]', LdapUserAttributesInterface::EVENT_SYNC_TO_DRUPAL_USER));
  self::assertEquals('[guid]', $data['[field.ldap_user_puid]']
    ->getLdapAttribute());
  $this->server
    ->set('mail_template', '[cn]@example.com');
  $processor
    ->loadAttributes(LdapUserAttributesInterface::PROVISION_TO_DRUPAL, $this->server);
  $data = $processor
    ->getAttributesSyncedOnEvent(LdapUserAttributesInterface::EVENT_SYNC_TO_DRUPAL_USER);
  self::assertEquals('[cn]@example.com', $data['[property.mail]']
    ->getLdapAttribute());
}