52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use App\Entity\AuditLog;
|
|
use App\Repository\Contract\AuditLogReadRepositoryInterface;
|
|
use App\State\AuditLogProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class AuditLogProviderTest extends TestCase
|
|
{
|
|
public function testProvideExposesForensicFields(): void
|
|
{
|
|
$log = new AuditLog()
|
|
->setUsername('usine')
|
|
->setAction('create')
|
|
->setEntityType('work_hour')
|
|
->setDescription('desc')
|
|
->setIpAddress('203.0.113.7')
|
|
->setUserAgent('UA-string')
|
|
->setDeviceLabel('Mobile · Android · Chrome')
|
|
->setDeviceId('device-abc')
|
|
;
|
|
|
|
$repo = $this->createMock(AuditLogReadRepositoryInterface::class);
|
|
$repo->method('countByFilters')->willReturn(1);
|
|
$repo->method('findByFilters')->willReturn([$log]);
|
|
|
|
$stack = new RequestStack();
|
|
$stack->push(Request::create('/api/audit-logs', 'GET'));
|
|
|
|
$provider = new AuditLogProvider($stack, $repo);
|
|
$response = $provider->provide($this->createMock(Operation::class));
|
|
|
|
$data = json_decode((string) $response->getContent(), true);
|
|
$item = $data['items'][0];
|
|
|
|
self::assertSame('203.0.113.7', $item['ipAddress']);
|
|
self::assertSame('UA-string', $item['userAgent']);
|
|
self::assertSame('Mobile · Android · Chrome', $item['deviceLabel']);
|
|
self::assertSame('device-abc', $item['deviceId']);
|
|
}
|
|
}
|