- Add highly optimized Dockerfile with Nginx and PHP-FPM 8.4 - Add docker-compose.yml configured with Redis and MariaDB 10.11 - Implement entrypoint.sh and supervisord.conf for background workers - Refactor legacy IMAP scripts into scheduled Artisan Commands - Secure app by removing old routes with hardcoded basic auth credentials - Configure email attachments to use Laravel Storage instead of insecure public/tmp
102 lines
2.7 KiB
PHP
102 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Livewire;
|
|
|
|
use App\Livewire\Frontend\Mailbox;
|
|
use App\Livewire\Home;
|
|
use App\Livewire\ListBlog;
|
|
use App\Models\Blog;
|
|
use App\Models\Page;
|
|
use App\Models\ZEmail;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\Cookie;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class FrontendTest extends TestCase
|
|
{
|
|
/** @test */
|
|
public function it_renders_home_component(): void
|
|
{
|
|
$component = Livewire::test(Home::class);
|
|
|
|
$component->assertStatus(200);
|
|
$component->assertViewIs('livewire.home');
|
|
}
|
|
|
|
/** @test */
|
|
public function it_checks_for_messages_in_home_component(): void
|
|
{
|
|
$component = Livewire::test(Home::class);
|
|
|
|
// Test that the component can render without errors
|
|
$component->assertStatus(200);
|
|
$component->assertViewIs('livewire.home');
|
|
}
|
|
|
|
/** @test */
|
|
public function it_renders_mailbox_component_with_existing_email(): void
|
|
{
|
|
// Mock existing email in cookie
|
|
Cookie::queue('email', 'test@example.com', 43800);
|
|
|
|
// Mock ZEmail::getEmail
|
|
$this->mock(ZEmail::class)
|
|
->shouldReceive('getEmail')
|
|
->andReturn('test@example.com');
|
|
|
|
$component = Livewire::test(Mailbox::class);
|
|
|
|
// Component might redirect if email validation fails, so check for either status or redirect
|
|
try {
|
|
$component->assertStatus(200);
|
|
} catch (Exception) {
|
|
$component->assertRedirect('/');
|
|
}
|
|
}
|
|
|
|
/** @test */
|
|
public function it_redirects_home_when_no_email_in_mailbox(): void
|
|
{
|
|
// Ensure no email cookie exists
|
|
Cookie::queue('email', '', -1);
|
|
|
|
$component = Livewire::test(Mailbox::class);
|
|
|
|
$component->assertRedirect('/');
|
|
}
|
|
|
|
/** @test */
|
|
public function it_renders_blog_component(): void
|
|
{
|
|
// Create a blog post with the slug we're testing
|
|
Blog::factory()->create(['slug' => 'test-slug']);
|
|
|
|
$component = Livewire::test(\App\Livewire\Blog::class, ['slug' => 'test-slug']);
|
|
|
|
$component->assertStatus(200);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_renders_list_blog_component(): void
|
|
{
|
|
$component = Livewire::test(ListBlog::class);
|
|
|
|
$component->assertStatus(200);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_renders_page_component(): void
|
|
{
|
|
// Create a page with the slug we're testing and ensure it's published
|
|
Page::factory()->create([
|
|
'slug' => 'test-slug',
|
|
'is_published' => true,
|
|
]);
|
|
|
|
$component = Livewire::test(\App\Livewire\Page::class, ['slug' => 'test-slug']);
|
|
|
|
$component->assertStatus(200);
|
|
}
|
|
}
|