diff --git a/src/EventSubscriber/EventSubscriber.php b/src/EventSubscriber/EventSubscriber.php index 8de406d81..cf0d6714d 100644 --- a/src/EventSubscriber/EventSubscriber.php +++ b/src/EventSubscriber/EventSubscriber.php @@ -12,7 +12,6 @@ use Drupal\default_content\Event\DefaultContentEvents; use Drupal\default_content\Event\ImportEvent; use Drupal\file\FileInterface; -use Drupal\user\UserInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -76,6 +75,7 @@ public function onEntityInsert(EntityInsertEvent $event) { self::updateSamlauthRoles(); } } + /** * On entity delete event. * @@ -96,14 +96,13 @@ protected static function updateSamlauthRoles() { return; } - $roles = user_role_names(TRUE); - unset($roles[UserInterface::AUTHENTICATED_ROLE]); + $role_ids = array_keys(user_role_names(TRUE)); + $role_ids = array_combine($role_ids, $role_ids); + unset($role_ids[RoleInterface::AUTHENTICATED_ID]); + asort($role_ids); + $config = \Drupal::configFactory()->getEditable('samlauth.authentication'); - ksort($roles); - foreach ($roles as $role_id => &$label) { - $label = $role_id; - } - $config->set('map_users_roles', $roles)->save(); + $config->set('map_users_roles', $role_ids)->save(); } /** diff --git a/tests/src/Kernel/EventSubscriber/EventSubscriberTest.php b/tests/src/Kernel/EventSubscriber/EventSubscriberTest.php index f5f7751b8..dbbf11822 100644 --- a/tests/src/Kernel/EventSubscriber/EventSubscriberTest.php +++ b/tests/src/Kernel/EventSubscriber/EventSubscriberTest.php @@ -87,10 +87,7 @@ protected function setUp(): void { * Test the consumer secret is randomized. */ public function testConsumerSecretRandomized() { - $expected = [ - 'default_content.import' => 'onContentImport', - ]; - $this->assertEquals($expected, StanfordEventSubscriber::getSubscribedEvents()); + $this->assertContains('onContentImport', StanfordEventSubscriber::getSubscribedEvents()); $consumer = Consumer::create([ 'client_id' => 'foobar', 'label' => 'foobar',