public function LoginTest::setUp in Lightweight Directory Access Protocol (LDAP) 8.4
Overrides KernelTestBase::setUp
File
- ldap_authentication/
tests/ src/ Kernel/ LoginTest.php, line 47
Class
- LoginTest
- Login tests.
Namespace
Drupal\Tests\ldap_authentication\KernelCode
public function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('ldap_server');
$this
->installSchema('externalauth', [
'authmap',
]);
$this
->installSchema('system', 'sequences');
/** @var \Drupal\Core\Entity\EntityTypeManager $manager */
$manager = $this->container
->get('entity_type.manager');
/** @var \Drupal\ldap_servers\Entity\Server $server */
$server = $manager
->getStorage('ldap_server')
->create([
'id' => 'test',
'timeout' => 30,
'encryption' => 'none',
'address' => 'example',
'port' => 963,
'basedn' => [
'ou=people,dc=hogwarts,dc=edu',
],
'user_attr' => 'cn',
'unique_persistent_attr' => 'uid',
'status' => TRUE,
'mail_attr' => 'mail',
]);
$server
->save();
$this
->config('ldap_authentication.settings')
->set('sids', [
$server
->id(),
])
->set('excludeIfTextInDn', [])
->set('allowOnlyIfTextInDn', [])
->save();
$this
->config('ldap_user.settings')
->set('acctCreation', LdapUserAttributesInterface::ACCOUNT_CREATION_LDAP_BEHAVIOUR)
->set('drupalAcctProvisionServer', $server
->id())
->set('ldapUserSyncMappings', [
'drupal' => [],
'ldap' => [],
])
->set('drupalAcctProvisionTriggers', [
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_AUTHENTICATION,
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_ON_MANUAL_CREATION,
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_UPDATE_CREATE,
])
->save();
$this->container
->get('config.factory')
->reset();
$bridge = new FakeBridge($this->container
->get('logger.channel.ldap_servers'), $this->container
->get('entity_type.manager'));
$bridge
->setServer($server);
$ldap = $bridge
->get();
$collection = [
'(cn=hpotter)' => new FakeCollection([
new Entry('cn=hpotter,ou=people,dc=hogwarts,dc=edu', [
'cn' => [
'hpotter',
],
'uid' => [
'123',
],
'mail' => [
'hpotter@example.com',
],
]),
]),
];
$ldap
->setQueryResult($collection);
$this->container
->set('ldap.bridge', $bridge);
$this->validator = new LoginValidatorLoginForm($this->container
->get('config.factory'), $this->container
->get('ldap.detail_log'), $this->container
->get('logger.channel.ldap_authentication'), $this->container
->get('entity_type.manager'), $this->container
->get('module_handler'), $this->container
->get('ldap.bridge'), $this->container
->get('externalauth.authmap'), $this->container
->get('ldap_authentication.servers'), $this->container
->get('ldap.user_manager'), $this->container
->get('messenger'), $this->container
->get('ldap.drupal_user_processor'));
}