Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #25

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions tests/ExampleTest.php

This file was deleted.

76 changes: 76 additions & 0 deletions tests/StaticCacheManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace DuncanMcClean\StaticCacheManager\Tests;

use Illuminate\Support\Facades\File;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Config;
use Statamic\Facades\User;

class StaticCacheManagerTest extends TestCase
{
public function setUp(): void
{
parent::setUp();

File::copyDirectory(__DIR__.'/__fixtures__/public/static', base_path('public/static'));
}

public function tearDown(): void
{
File::deleteDirectory(base_path('public/static'));

parent::tearDown();
}

#[Test] public function it_clears_a_statically_cached_page()
{
$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',
]);

$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'));
}
}
1 change: 1 addition & 0 deletions tests/__fixtures__/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
users
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading