-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from City-of-Helsinki/UHF-9466
UHF-9466: Exclude Tunnistamo users from User Expire, automatic phpcs fixes
- Loading branch information
Showing
7 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\helfi_tunnistamo\Kernel; | ||
|
||
use Drupal\helfi_api_base\Features\FeatureManager; | ||
use Drupal\helfi_api_base\UserExpire\UserExpireManager; | ||
use Drupal\Tests\user\Traits\UserCreationTrait; | ||
use Drupal\user\Entity\User; | ||
|
||
/** | ||
* Tests API Base's user expiration feature with Tunnistamo. | ||
* | ||
* @group helfi_tunnistamo | ||
*/ | ||
class UserExpireTest extends KernelTestBase { | ||
|
||
use UserCreationTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() : void { | ||
parent::setUp(); | ||
|
||
/** @var \Drupal\helfi_api_base\Features\FeatureManager $featureManager */ | ||
$featureManager = $this->container->get(FeatureManager::class); | ||
$featureManager->enableFeature(FeatureManager::USER_EXPIRE); | ||
} | ||
|
||
/** | ||
* Gets the SUT. | ||
* | ||
* @return \Drupal\helfi_api_base\UserExpire\UserExpireManager | ||
* The SUT. | ||
*/ | ||
public function getSut() : UserExpireManager { | ||
return $this->container->get(UserExpireManager::class); | ||
} | ||
|
||
/** | ||
* Tests the expired users. | ||
*/ | ||
public function testTunnistamoUsers() : void { | ||
/** @var \Drupal\user\UserInterface[] $users */ | ||
$users = [ | ||
'1' => $this->createUser(), | ||
'2' => $this->createUser(), | ||
]; | ||
|
||
foreach ($users as $user) { | ||
// Make sure users have never logged in. | ||
$this->assertEquals(0, $user->getLastAccessedTime()); | ||
$this->assertTrue($user->getCreatedTime() > 0); | ||
// Set access time over the threshold. | ||
$user->setLastAccessTime(strtotime('-7 months')) | ||
->save(); | ||
} | ||
// Make sure both users are marked as expired. | ||
$expired = $this->getSut()->getExpiredUserIds(); | ||
$this->assertEquals([1 => 1, 2 => 2], $expired); | ||
|
||
/** @var \Drupal\externalauth\ExternalAuthInterface $externalAuth */ | ||
$externalAuth = $this->container->get('externalauth.externalauth'); | ||
$externalAuth->linkExistingAccount('123', 'openid_connect.tunnistamo', $users['2']); | ||
|
||
// Make sure user 2 is not marked as expired after logging in using | ||
// Tunnistamo. | ||
$expired = $this->getSut()->getExpiredUserIds(); | ||
$this->assertArrayNotHasKey(2, $expired); | ||
|
||
$this->getSut()->cancelExpiredUsers(); | ||
|
||
$this->assertTrue(User::load(1)->isBlocked()); | ||
$this->assertFalse(User::load(2)->isBlocked()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters