You are here

class SyncMappingHelperTests in Lightweight Directory Access Protocol (LDAP) 8.3

@coversDefaultClass \Drupal\ldap_user\Helper\SyncMappingHelper @group ldap

Hierarchy

Expanded class hierarchy of SyncMappingHelperTests

File

ldap_user/tests/src/Unit/SyncMappingHelperTests.php, line 14

Namespace

Drupal\Tests\ldap_user\Unit
View source
class SyncMappingHelperTests extends UnitTestCase implements LdapUserAttributesInterface {
  public $configFactory;
  public $serverFactory;
  public $config;
  public $container;

  /**
   * Prepare the sync mapping tests.
   */
  protected function setUp() {
    parent::setUp();

    /* Mocks the configuration due to detailed watchdog logging. */
    $this->config = $this
      ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
      ->disableOriginalConstructor()
      ->getMock();
    $this->configFactory = $this
      ->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')
      ->disableOriginalConstructor()
      ->getMock();
    $this->configFactory
      ->expects($this
      ->any())
      ->method('get')
      ->with('ldap_user.settings')
      ->willReturn($this->config);
    $this->container = new ContainerBuilder();
    $this->container
      ->set('config.factory', $this->configFactory);
    \Drupal::setContainer($this->container);
  }

  /**
   * Prove that field syncs work and provide the demo data here.
   */
  public function testSyncValidatorIsSynced() {
    $syncTestData = [
      'drupal' => [
        '[field.ldap_user_puid_sid]' => [
          // Actually TranslatableMarkup.
          'name' => 'SID',
          'configurable_to_drupal' => 0,
          'configurable_to_ldap' => 1,
          'notes' => 'not configurable',
          'direction' => 'drupal',
          'enabled' => TRUE,
          'prov_events' => [
            self::EVENT_CREATE_DRUPAL_USER,
          ],
        ],
        '[property.name]' => [
          // Actually TranslatableMarkup.
          'name' => 'Name',
          'source' => '[cn]',
          'direction' => 'drupal',
          'enabled' => TRUE,
          'prov_events' => [
            self::EVENT_CREATE_DRUPAL_USER,
            self::EVENT_SYNC_TO_DRUPAL_USER,
          ],
        ],
      ],
      'ldap' => [
        '[property.name]' => [
          // Actually TranslatableMarkup.
          'name' => 'Name',
          'source' => '',
          'direction' => 'ldap',
          'enabled' => TRUE,
          'prov_events' => [
            self::EVENT_CREATE_LDAP_ENTRY,
            self::EVENT_SYNC_TO_LDAP_ENTRY,
          ],
          'configurable_to_ldap' => TRUE,
        ],
      ],
    ];
    $processor = $this
      ->getMockBuilder('Drupal\\ldap_user\\Helper\\SyncMappingHelper')
      ->setMethods([
      'processSyncMappings',
    ])
      ->disableOriginalConstructor()
      ->getMock();
    $reflection = new ReflectionClass(get_class($processor));
    $method = $reflection
      ->getMethod('setAllSyncMappings');
    $method
      ->setAccessible(TRUE);
    $method
      ->invoke($processor, $syncTestData);

    /** @var \Drupal\ldap_user\Helper\SyncMappingHelper $processor */
    $isSynced = $processor
      ->isSynced('[field.ldap_user_puid_sid]', [
      self::EVENT_CREATE_DRUPAL_USER,
    ], self::PROVISION_TO_DRUPAL);
    $this
      ->assertTrue($isSynced);
    $isSynced = $processor
      ->isSynced('[field.ldap_user_puid_sid]', [
      self::EVENT_CREATE_DRUPAL_USER,
    ], self::PROVISION_TO_LDAP);
    $this
      ->assertFalse($isSynced);
    $isSynced = $processor
      ->isSynced('[field.ldap_user_puid_sid]', [
      self::EVENT_CREATE_LDAP_ENTRY,
    ], self::PROVISION_TO_LDAP);
    $this
      ->assertFalse($isSynced);
    $isSynced = $processor
      ->isSynced('[field.ldap_user_puid_sid]', [
      self::EVENT_CREATE_LDAP_ENTRY,
    ], self::PROVISION_TO_LDAP);
    $this
      ->assertFalse($isSynced);
    $isSynced = $processor
      ->isSynced('[property.name]', [
      self::EVENT_CREATE_LDAP_ENTRY,
    ], self::PROVISION_TO_LDAP);
    $this
      ->assertTrue($isSynced);
    $isSynced = $processor
      ->isSynced('[property.xyz]', [
      self::EVENT_CREATE_DRUPAL_USER,
    ], self::PROVISION_TO_DRUPAL);
    $this
      ->assertFalse($isSynced);

    // TODO: Review behaviour. Should this actually be allowed that one of many
    // events returns true?
    $isSynced = $processor
      ->isSynced('[field.ldap_user_puid_sid]', [
      self::EVENT_CREATE_DRUPAL_USER,
      self::EVENT_SYNC_TO_DRUPAL_USER,
    ], self::PROVISION_TO_DRUPAL);
    $this
      ->assertTrue($isSynced);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LdapUserAttributesInterface::ACCOUNT_CREATION_LDAP_BEHAVIOUR constant
LdapUserAttributesInterface::ACCOUNT_CREATION_USER_SETTINGS_FOR_LDAP constant
LdapUserAttributesInterface::EVENT_CREATE_DRUPAL_USER constant
LdapUserAttributesInterface::EVENT_CREATE_LDAP_ENTRY constant
LdapUserAttributesInterface::EVENT_LDAP_ASSOCIATE_DRUPAL_USER constant
LdapUserAttributesInterface::EVENT_SYNC_TO_DRUPAL_USER constant
LdapUserAttributesInterface::EVENT_SYNC_TO_LDAP_ENTRY constant
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_LDAP_ASSOCIATE constant
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_NO_LDAP_ASSOCIATE constant
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_REJECT constant
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_SHOW_OPTION_ON_FORM constant
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_AUTHENTICATION constant
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_ON_MANUAL_CREATION constant
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_UPDATE_CREATE constant
LdapUserAttributesInterface::PROVISION_LDAP_ENTRY_ON_USER_ON_USER_AUTHENTICATION constant
LdapUserAttributesInterface::PROVISION_LDAP_ENTRY_ON_USER_ON_USER_DELETE constant
LdapUserAttributesInterface::PROVISION_LDAP_ENTRY_ON_USER_ON_USER_UPDATE_CREATE constant
LdapUserAttributesInterface::PROVISION_TO_ALL constant
LdapUserAttributesInterface::PROVISION_TO_DRUPAL constant
LdapUserAttributesInterface::PROVISION_TO_LDAP constant
LdapUserAttributesInterface::PROVISION_TO_NONE constant
LdapUserAttributesInterface::USER_CONFLICT_ATTEMPT_RESOLVE constant
LdapUserAttributesInterface::USER_CONFLICT_LOG constant
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
SyncMappingHelperTests::$config public property
SyncMappingHelperTests::$configFactory public property
SyncMappingHelperTests::$container public property
SyncMappingHelperTests::$serverFactory public property
SyncMappingHelperTests::setUp protected function Prepare the sync mapping tests. Overrides UnitTestCase::setUp
SyncMappingHelperTests::testSyncValidatorIsSynced public function Prove that field syncs work and provide the demo data here.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.