Add analytics test with real data to cover visitor/pageview chart loops
Creates AnalyticsUniqId and AnalyticsEvent records in DB so the daily chart aggregation loops (visitorsPerDay, pageviewsPerDay, allDays merge, DateTimeInterface check) are fully exercised. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1210,6 +1210,42 @@ class AdminControllerTest extends WebTestCase
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testAnalyticsWithData(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$visitor = new \App\Entity\AnalyticsUniqId();
|
||||
$visitor->setUid('test-'.uniqid());
|
||||
$visitor->setHash(hash('sha256', 'test'));
|
||||
$visitor->setIpHash(hash('sha256', '127.0.0.1'));
|
||||
$visitor->setUserAgent('PHPUnit Test Browser');
|
||||
$visitor->setDeviceType('desktop');
|
||||
$visitor->setOs('Linux');
|
||||
$visitor->setBrowser('Chrome');
|
||||
$em->persist($visitor);
|
||||
|
||||
$event = new \App\Entity\AnalyticsEvent();
|
||||
$event->setVisitor($visitor);
|
||||
$event->setUrl('/test-page');
|
||||
$event->setTitle('Test Page');
|
||||
$event->setReferrer('https://google.com');
|
||||
$em->persist($event);
|
||||
|
||||
$event2 = new \App\Entity\AnalyticsEvent();
|
||||
$event2->setVisitor($visitor);
|
||||
$event2->setUrl('/another-page');
|
||||
$em->persist($event2);
|
||||
|
||||
$em->flush();
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('GET', '/admin/analytics?period=7d');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testAnalyticsDeniedForNonRoot(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
Reference in New Issue
Block a user