Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CachedEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function __construct(string $userAgent, $clientHints, array $values)
$clientHints = $clientHints ? ClientHints::factory($clientHints) : null;
parent::__construct($userAgent, $clientHints);

$this->bot = $values['bot'] ?? '';
$this->bot = $values['bot'] ?? null;
$this->brand = $values['brand'] ?? '';
$this->client = $values['client'] ?? '';
$this->device = $values['device'] ?? '';
$this->client = $values['client'] ?? null;
$this->device = $values['device'] ?? null;
$this->model = $values['model'] ?? '';
$this->os = $values['os'] ?? '';
$this->os = $values['os'] ?? null;

// Or cached entries only use the useragents, so if we have some client hints provided,
// We use some special parsers, which use the cached user agent result and parses it again using client hints
Expand Down
37 changes: 36 additions & 1 deletion tests/Integration/CachedEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,49 @@ public function testConstruct()
$instance = new CachedEntry($userAgent, $clientHints, $values);
$this->assertIsObject($instance);
$this->assertInstanceOf(CachedEntry::class, $instance);
$this->assertSame('', $instance->getBot());
$this->assertSame(null, $instance->getBot());
$this->assertSame($values['brand'], $instance->getBrandName());
$this->assertSame($expectedClient, $instance->getClient());
$this->assertSame($values['device'], $instance->getDevice());
$this->assertSame($values['model'], $instance->getModel());
$this->assertSame($expectedOs, $instance->getOs());
}

public function testConstructDefault()
{
$userAgent = "unknown";

$clientHints = [
'HTTP_SEC_CH_UA_PLATFORM' => '"Windows"',
'HTTP_SEC_CH_UA' => '" Not A;Brand";v="99", "Chromium";v="95", "Microsoft Edge";v="95"',
'HTTP_SEC_CH_UA_MOBILE' => "?0",
'HTTP_SEC_CH_UA_FULL_VERSION' => '"98.0.0.1"',
'HTTP_SEC_CH_UA_PLATFORM_VERSION' => '"14.0.0"',
'HTTP_SEC_CH_UA_ARCH' => "x86",
'HTTP_SEC_CH_UA_BITNESS' => "64",
'HTTP_SEC_CH_UA_MODEL' => ""
];

$expectedOs = [
'name' => 'Windows',
'short_name' => 'WIN',
'version' => '11',
'platform' => 'x64',
'family' => 'Windows',
];


$instance = new CachedEntry($userAgent, $clientHints, []);
$this->assertIsObject($instance);
$this->assertInstanceOf(CachedEntry::class, $instance);
$this->assertSame(null, $instance->getBot());
$this->assertSame('', $instance->getBrandName());
$this->assertSame(null, $instance->getClient());
$this->assertSame(null, $instance->getDevice());
$this->assertSame('', $instance->getModel());
$this->assertSame($expectedOs, $instance->getOs());
}

public function testGetNumCacheFiles_noneCached()
{
$this->assertEquals(0, CachedEntry::getNumEntriesInCacheDir());
Expand Down