From 2e2352dcaef38d2ba21eda725ff25d2720722322 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Sat, 8 Jun 2024 16:10:35 +0100 Subject: [PATCH 1/2] Add tests --- tests/ExampleTest.php | 12 --- tests/StaticCacheManagerTest.php | 76 +++++++++++++++++++ tests/__fixtures__/public/static/_.html | 0 tests/__fixtures__/public/static/about_.html | 0 .../static/contact/corporate-office_.html | 0 .../static/contact/scranton-office_.html | 0 .../__fixtures__/public/static/contact_.html | 0 tests/__fixtures__/users/.yaml | 2 + 8 files changed, 78 insertions(+), 12 deletions(-) delete mode 100644 tests/ExampleTest.php create mode 100644 tests/StaticCacheManagerTest.php create mode 100644 tests/__fixtures__/public/static/_.html create mode 100644 tests/__fixtures__/public/static/about_.html create mode 100644 tests/__fixtures__/public/static/contact/corporate-office_.html create mode 100644 tests/__fixtures__/public/static/contact/scranton-office_.html create mode 100644 tests/__fixtures__/public/static/contact_.html create mode 100644 tests/__fixtures__/users/.yaml 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__/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 diff --git a/tests/__fixtures__/users/.yaml b/tests/__fixtures__/users/.yaml new file mode 100644 index 0000000..48b1d72 --- /dev/null +++ b/tests/__fixtures__/users/.yaml @@ -0,0 +1,2 @@ +super: true +id: 5d1ff460-7433-46d5-b68f-a06453292f3b From 6edcd5e792092a37b511483fca5259d55e21be98 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Sat, 8 Jun 2024 16:11:28 +0100 Subject: [PATCH 2/2] Delete users directory in fixtures --- tests/__fixtures__/.gitignore | 1 + tests/__fixtures__/users/.yaml | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 tests/__fixtures__/.gitignore delete mode 100644 tests/__fixtures__/users/.yaml 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__/users/.yaml b/tests/__fixtures__/users/.yaml deleted file mode 100644 index 48b1d72..0000000 --- a/tests/__fixtures__/users/.yaml +++ /dev/null @@ -1,2 +0,0 @@ -super: true -id: 5d1ff460-7433-46d5-b68f-a06453292f3b