From 619065237822b2b763533a6602cc2ce7aa3b30b4 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Wed, 22 Nov 2023 11:31:39 -0500 Subject: [PATCH] apply to file test --- tests/StaticCaching/FileCacherTest.php | 31 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/StaticCaching/FileCacherTest.php b/tests/StaticCaching/FileCacherTest.php index 0a3f479d8c..dbbafa0fd0 100644 --- a/tests/StaticCaching/FileCacherTest.php +++ b/tests/StaticCaching/FileCacherTest.php @@ -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; @@ -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';