cms/tests/Feature/AnalyticsTrackerTest.php

34 lines
829 B
PHP
Raw Permalink Normal View History

<?php
namespace Tests\Feature;
use App\Models\Page;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AnalyticsTrackerTest extends TestCase
{
use RefreshDatabase;
public function test_tracks_page_views(): void
{
// Use a route that exists (the home route '/')
$response = $this->get('/');
$response->assertStatus(200);
$this->assertEquals(1, \App\Models\PageView::count());
$this->assertDatabaseHas('page_views', [
'path' => '/',
]);
}
public function test_does_not_track_admin_views(): void
{
$response = $this->get(env('ADMIN_PATH', 'loom') . '/dashboard');
$this->assertDatabaseMissing('page_views', [
'path' => '/' . env('ADMIN_PATH', 'loom') . '/dashboard',
]);
}
}