3 namespace Friendica\Test\src\Security\TwoFactor\Factory;
5 use Friendica\Security\TwoFactor\Factory\TrustedBrowser;
6 use Friendica\Util\DateTimeFormat;
7 use Friendica\Util\Logger\VoidLogger;
8 use Friendica\Util\Strings;
10 class TrustedBrowserTest extends \PHPUnit_Framework_TestCase
12 public function testCreateFromTableRowSuccess()
14 $factory = new TrustedBrowser(new VoidLogger());
17 'cookie_hash' => Strings::getRandomHex(),
19 'user_agent' => 'PHPUnit',
20 'created' => DateTimeFormat::utcNow(),
24 $trustedBrowser = $factory->createFromTableRow($row);
26 $this->assertEquals($row, $trustedBrowser->toArray());
29 public function testCreateFromTableRowMissingData()
31 $this->expectException(\TypeError::class);
33 $factory = new TrustedBrowser(new VoidLogger());
36 'cookie_hash' => null,
43 $trustedBrowser = $factory->createFromTableRow($row);
45 $this->assertEquals($row, $trustedBrowser->toArray());
48 public function testCreateForUserWithUserAgent()
50 $factory = new TrustedBrowser(new VoidLogger());
53 $userAgent = 'PHPUnit';
55 $trustedBrowser = $factory->createForUserWithUserAgent($uid, $userAgent);
57 $this->assertNotEmpty($trustedBrowser->cookie_hash);
58 $this->assertEquals($uid, $trustedBrowser->uid);
59 $this->assertEquals($userAgent, $trustedBrowser->user_agent);
60 $this->assertNotEmpty($trustedBrowser->created);