Skip to content

Commit

Permalink
move to a dedicated test, and test for when no domain is passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Nov 22, 2023
1 parent e264e91 commit f694b6a
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions tests/StaticCaching/ApplicationCacherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Event;
use Statamic\Events\UrlInvalidated;
use Statamic\StaticCaching\Cacher;
use Statamic\StaticCaching\Cachers\ApplicationCacher;
use Tests\TestCase;

Expand Down Expand Up @@ -57,8 +58,6 @@ public function checking_if_page_is_cached_then_retrieving_it_will_only_hit_the_
/** @test */
public function invalidating_a_url_removes_the_html_and_the_url()
{
Event::fake();

$cache = app(Repository::class);
$cacher = new ApplicationCacher($cache, ['base_url' => 'http://example.com']);
$cache->forever('static-cache:'.md5('http://example.com').'.urls', [
Expand All @@ -79,17 +78,11 @@ public function invalidating_a_url_removes_the_html_and_the_url()
$this->assertNull($cache->get('static-cache:responses:one'));
$this->assertNotNull($cache->get('static-cache:responses:onemore'));
$this->assertNotNull($cache->get('static-cache:responses:two'));

Event::assertDispatched(UrlInvalidated::class, function ($event) {
return $event->url === '/one';
});
}

/** @test */
public function invalidating_a_url_will_invalidate_all_query_string_versions_too()
{
Event::fake();

$cache = app(Repository::class);
$cacher = new ApplicationCacher($cache, ['base_url' => 'http://example.com']);
$cache->forever('static-cache:'.md5('http://example.com').'.urls', [
Expand All @@ -113,12 +106,39 @@ public function invalidating_a_url_will_invalidate_all_query_string_versions_too
$this->assertNull($cache->get('static-cache:responses:oneqs'));
$this->assertNotNull($cache->get('static-cache:responses:onemore'));
$this->assertNotNull($cache->get('static-cache:responses:two'));
}

Event::assertDispatched(UrlInvalidated::class, function ($event) {
return $event->url === '/one';
/**
* @test
*
* @dataProvider invalidateEventProvider
*/
public function invalidating_a_url_dispatches_event($domain, $expectedUrl)
{
Event::fake();

$cache = app(Repository::class);
$cacher = new ApplicationCacher($cache, ['base_url' => 'http://base.com']);

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

$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'],
];
}

/** @test */
public function it_flushes()
{
Expand Down

0 comments on commit f694b6a

Please sign in to comment.