Skip to content

Commit

Permalink
Add base test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Aug 6, 2024
1 parent 55ddb67 commit 383e477
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/Unit/TrackerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Thoughtco\StatamicCacheTracker\Tests\Unit;

use Illuminate\Support\Facades\Event;
use PHPUnit\Framework\Attributes\Test;
use Thoughtco\StatamicCacheTracker\Events\ContentTracked;
use Thoughtco\StatamicCacheTracker\Facades\Tracker;
use Thoughtco\StatamicCacheTracker\Tests\TestCase;

class TrackerTest extends TestCase
{
#[Test]
public function it_tracks_uncached_pages()
{
Event::fake();

Tracker::addAdditionalTracker(function ($tracker, $next) {
$tracker->addContentTag('test::tag');
});

$this->get('/');

$this->assertSame(['test::tag'], collect(Tracker::all())->first()['tags']);

Event::assertDispatched(ContentTracked::class, 1);
}

#[Test]
public function it_doesnt_track_already_cached_pages()
{
Event::fake();

Tracker::addAdditionalTracker(function ($tracker, $next) {
$tracker->addContentTag('test::tag');
});

$this->get('/');

$this->assertSame(['test::tag'], collect(Tracker::all())->first()['tags']);

$this->get('/');

$this->assertSame(['test::tag'], collect(Tracker::all())->first()['tags']);

Event::assertDispatched(ContentTracked::class, 1);
}

#[Test]
public function it_doesnt_track_pages_already_in_the_manifest()
{
Event::fake();

Tracker::add('/', ['some:thing']);

Tracker::addAdditionalTracker(function ($tracker, $next) {
$tracker->addContentTag('test::tag');
});

$this->get('/');

$this->assertSame(['some:thing'], collect(Tracker::all())->first()['tags']);
}
}

0 comments on commit 383e477

Please sign in to comment.