Skip to content

Commit

Permalink
apply to file test
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Nov 22, 2023
1 parent 3c23c95 commit 6190652
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions tests/StaticCaching/FileCacherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Event;
use Statamic\Events\UrlInvalidated;
use Statamic\Facades\Site;
use Statamic\StaticCaching\Cacher;
use Statamic\StaticCaching\Cachers\FileCacher;
use Statamic\StaticCaching\Cachers\Writer;
use Tests\TestCase;
Expand Down Expand Up @@ -294,20 +295,38 @@ public function invalidating_a_url_deletes_the_file_and_removes_the_url_when_usi
$this->assertEquals(['one' => '/one'], $cacher->getUrls('http://domain.de')->all());
}

/** @test */
public function invalidating_a_url_fires_url_invalidated_event()
/**
* @test
*
* @dataProvider invalidateEventProvider
*/
public function invalidating_a_url_dispatches_event($domain, $expectedUrl)
{
Event::fake();

$cacher = $this->fileCacher();
$writer = \Mockery::spy(Writer::class);
$cache = app(Repository::class);
$cacher = $this->fileCacher(['base_url' => 'http://base.com'], $writer, $cache);

$cacher->invalidateUrl('/test');
// Put it in the container so that the event can resolve it.
$this->instance(Cacher::class, $cacher);

Event::assertDispatched(UrlInvalidated::class, function ($event) {
return $event->url === '/test';
$cacher->invalidateUrl('/foo', $domain);

Event::assertDispatched(UrlInvalidated::class, function ($event) use ($expectedUrl) {
return $event->url === $expectedUrl;
});
}

public function invalidateEventProvider()
{
return [
'no domain' => [null, 'http://base.com/foo'],
'configured base domain' => ['http://base.com', 'http://base.com/foo'],
'another domain' => ['http://another.com', 'http://another.com/foo'],
];
}

private function cacheKey($domain)
{
return 'static-cache:'.md5($domain).'.urls';
Expand Down

0 comments on commit 6190652

Please sign in to comment.