friendica/tests/src/Security/TwoFactor/Model/TrustedBrowserTest.php

48 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace Friendica\Test\src\Security\TwoFactor\Model;
use Friendica\Security\TwoFactor\Model\TrustedBrowser;
2021-04-01 15:19:45 -04:00
use Friendica\Test\MockedTest;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
2021-04-01 15:19:45 -04:00
class TrustedBrowserTest extends MockedTest
{
public function test__construct()
{
$hash = Strings::getRandomHex();
$trustedBrowser = new TrustedBrowser(
$hash,
42,
'PHPUnit',
DateTimeFormat::utcNow()
);
$this->assertEquals($hash, $trustedBrowser->cookie_hash);
$this->assertEquals(42, $trustedBrowser->uid);
$this->assertEquals('PHPUnit', $trustedBrowser->user_agent);
$this->assertNotEmpty($trustedBrowser->created);
}
public function testRecordUse()
{
$hash = Strings::getRandomHex();
$past = DateTimeFormat::utc('now - 5 minutes');
$trustedBrowser = new TrustedBrowser(
$hash,
42,
'PHPUnit',
$past,
$past
);
$trustedBrowser->recordUse();
$this->assertEquals($past, $trustedBrowser->created);
$this->assertGreaterThan($past, $trustedBrowser->last_used);
}
}