-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55ddb67
commit 383e477
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |