MNT Skip tests when session-manager module is installed

This commit is contained in:
Steve Boyd 2021-08-24 11:31:06 +12:00 committed by Maxime Rainville
parent 4c51d89798
commit 1fcbcc8368
2 changed files with 23 additions and 10 deletions

View File

@ -27,6 +27,7 @@ use SilverStripe\Security\Permission;
use SilverStripe\Security\RememberLoginHash;
use SilverStripe\Security\Security;
use SilverStripe\Security\Tests\MemberTest\FieldsExtension;
use SilverStripe\SessionManager\Models\LoginSession;
class MemberTest extends FunctionalTest
{
@ -1198,18 +1199,21 @@ class MemberTest extends FunctionalTest
]
);
$this->assertEquals(
RememberLoginHash::get()->filter(['MemberID'=>$m1->ID, 'DeviceID'=>$firstHash->DeviceID])->count(),
1
1,
RememberLoginHash::get()->filter(['MemberID'=>$m1->ID, 'DeviceID'=>$firstHash->DeviceID])->count()
);
// Logging out from any device when all login hashes should be removed
RememberLoginHash::config()->update('logout_across_devices', true);
Injector::inst()->get(IdentityStore::class)->logIn($m1, true);
$this->get('Security/logout', $this->session());
$this->assertEquals(
RememberLoginHash::get()->filter('MemberID', $m1->ID)->count(),
0
);
// If session-manager module is installed then logout_across_devices is modified so skip
if (!class_exists(LoginSession::class)) {
// Logging out from any device when all login hashes should be removed
RememberLoginHash::config()->update('logout_across_devices', true);
Injector::inst()->get(IdentityStore::class)->logIn($m1, true);
$this->get('Security/logout', $this->session());
$this->assertEquals(
0,
RememberLoginHash::get()->filter('MemberID', $m1->ID)->count()
);
}
}
public function testCanDelete()

View File

@ -5,6 +5,7 @@ namespace SilverStripe\Security\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
use SilverStripe\Security\RememberLoginHash;
use SilverStripe\SessionManager\Models\LoginSession;
class RememberLoginHashTest extends SapphireTest
{
@ -49,6 +50,10 @@ class RememberLoginHashTest extends SapphireTest
*/
public function testClear(bool $logoutAcrossDevices, string $deviceId, array $expected, array $unexpected)
{
// If session-manager module is installed then logout_across_devices is modified so skip
if (class_exists(LoginSession::class)) {
$this->markTestSkipped();
}
RememberLoginHash::config()->set('logout_across_devices', $logoutAcrossDevices);
RememberLoginHash::clear(
@ -75,6 +80,10 @@ class RememberLoginHashTest extends SapphireTest
public function testGetSetLogoutAcrossDevices()
{
// If session-manager module is installed then logout_across_devices is modified so skip
if (class_exists(LoginSession::class)) {
$this->markTestSkipped();
}
// set config directly
RememberLoginHash::config()->set('logout_across_devices', true);
$this->assertTrue(RememberLoginHash::getLogoutAcrossDevices());