diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php deleted file mode 100644 index 2245958..0000000 --- a/tests/ExampleTest.php +++ /dev/null @@ -1,12 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/StaticCacheManagerTest.php b/tests/StaticCacheManagerTest.php new file mode 100644 index 0000000..b8e2964 --- /dev/null +++ b/tests/StaticCacheManagerTest.php @@ -0,0 +1,76 @@ +assertFileExists(base_path('public/static/_.html')); + $this->assertFileExists(base_path('public/static/about_.html')); + $this->assertFileExists(base_path('public/static/contact_.html')); + + $this + ->actingAs(User::make()->makeSuper()->save()) + ->post(cp_route('utilities.static-cache-manager.clear'), [ + 'paths' => '/about', + ]); + + $this->assertFileExists(base_path('public/static/_.html')); + $this->assertFileExists(base_path('public/static/contact_.html')); + $this->assertFileDoesNotExist(base_path('public/static/about_.html')); + } + + #[Test] public function it_clears_statically_cached_pages_with_a_wildcard() + { + $this->assertFileExists(base_path('public/static/contact_.html')); + $this->assertFileExists(base_path('public/static/contact/corporate-office_.html')); + $this->assertFileExists(base_path('public/static/contact/scranton-office_.html')); + + $this + ->actingAs(User::make()->makeSuper()->save()) + ->post(cp_route('utilities.static-cache-manager.clear'), [ + 'paths' => '/contact/*', + ]); + + $this->assertFileExists(base_path('public/static/contact_.html')); + $this->assertFileDoesNotExist(base_path('public/static/contact/corporate-office_.html')); + $this->assertFileDoesNotExist(base_path('public/static/contact/scranton-office_.html')); + } + + #[Test] public function it_clears_multiple_statically_cached_pages() + { + $this->assertFileExists(base_path('public/static/_.html')); + $this->assertFileExists(base_path('public/static/about_.html')); + $this->assertFileExists(base_path('public/static/contact_.html')); + + $this + ->actingAs(User::make()->makeSuper()->save()) + ->post(cp_route('utilities.static-cache-manager.clear'), [ + 'paths' => '/about' . PHP_EOL . '/contact', + ]); + + $this->assertFileExists(base_path('public/static/_.html')); + $this->assertFileDoesNotExist(base_path('public/static/contact_.html')); + $this->assertFileDoesNotExist(base_path('public/static/about_.html')); + } +} diff --git a/tests/__fixtures__/.gitignore b/tests/__fixtures__/.gitignore new file mode 100644 index 0000000..5347237 --- /dev/null +++ b/tests/__fixtures__/.gitignore @@ -0,0 +1 @@ +users \ No newline at end of file diff --git a/tests/__fixtures__/public/static/_.html b/tests/__fixtures__/public/static/_.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/__fixtures__/public/static/about_.html b/tests/__fixtures__/public/static/about_.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/__fixtures__/public/static/contact/corporate-office_.html b/tests/__fixtures__/public/static/contact/corporate-office_.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/__fixtures__/public/static/contact/scranton-office_.html b/tests/__fixtures__/public/static/contact/scranton-office_.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/__fixtures__/public/static/contact_.html b/tests/__fixtures__/public/static/contact_.html new file mode 100644 index 0000000..e69de29