|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drupal\Tests\stanford_samlauth\Kernel\EventSubscriber; |
| 4 | + |
| 5 | +use Drupal\Tests\stanford_samlauth\Kernel\StanfordSamlAuthTestBase; |
| 6 | +use Drupal\user\Entity\Role; |
| 7 | +use PHPUnit\Framework\Attributes\TestWith; |
| 8 | + |
| 9 | +/** |
| 10 | + * Test route subscriber. |
| 11 | + */ |
| 12 | +class SamlAuthRouteSubscriberTest extends StanfordSamlAuthTestBase { |
| 13 | + |
| 14 | + /** |
| 15 | + * {@inheritDoc} |
| 16 | + */ |
| 17 | + public function setup(): void { |
| 18 | + parent::setup(); |
| 19 | + $this->installConfig('samlauth'); |
| 20 | + } |
| 21 | + |
| 22 | + #[TestWith(['hide_local_login' => TRUE, 'role_mapping' => TRUE])] |
| 23 | + #[TestWith(['hide_local_login' => FALSE, 'role_mapping' => TRUE])] |
| 24 | + #[TestWith(['hide_local_login' => TRUE, 'role_mapping' => FALSE])] |
| 25 | + #[TestWith(['hide_local_login' => FALSE, 'role_mapping' => FALSE])] |
| 26 | + public function testUserSyncEvent(bool $hide_local_login, bool $role_mapping) { |
| 27 | + $this->config('stanford_samlauth.settings') |
| 28 | + ->set('hide_local_login', $hide_local_login) |
| 29 | + ->save(); |
| 30 | + |
| 31 | + if ($role_mapping) { |
| 32 | + $roles = array_keys(Role::loadMultiple()); |
| 33 | + $this->config('samlauth.authentication') |
| 34 | + ->set('drupal_login_roles', $roles) |
| 35 | + ->save(); |
| 36 | + } |
| 37 | + |
| 38 | + /** @var \Drupal\Core\Routing\Router $router */ |
| 39 | + $router = \Drupal::service('router.no_access_checks'); |
| 40 | + $access = $router->getRouteCollection() |
| 41 | + ->get('user.pass') |
| 42 | + ->getRequirement('_access'); |
| 43 | + |
| 44 | + $expected = $hide_local_login && !$role_mapping ? 'FALSE' : 'TRUE'; |
| 45 | + $this->assertEquals($expected, $access); |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments