41 lines
2.2 KiB
PHP
41 lines
2.2 KiB
PHP
<?php
|
|
namespace Tests\Feature;
|
|
use App\Livewire\ContactForm;
|
|
use App\Livewire\Admin\Sections;
|
|
use App\Models\ContactEnquiry;
|
|
use App\Models\SiteSection;
|
|
use App\Models\User;
|
|
use Database\Seeders\SiteContentSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
class SiteExperienceTest extends TestCase {
|
|
use RefreshDatabase;
|
|
public function test_homepage_displays_published_content(): void {
|
|
$this->seed(SiteContentSeeder::class);
|
|
$this->get('/')->assertOk()->assertSee('Digital experiences built to move your business forward.');
|
|
SiteSection::where('key','hero')->update(['is_visible'=>false]);
|
|
$this->get('/')->assertOk()->assertDontSee('Digital experiences built to move your business forward.');
|
|
}
|
|
public function test_contact_form_validates_and_saves_enquiry(): void {
|
|
Livewire::test(ContactForm::class)->set('name','Test Client')->set('email','[email protected]')
|
|
->set('message','Please build a Laravel website for my business.')->call('submit')->assertHasNoErrors();
|
|
$this->assertDatabaseHas('contact_enquiries',['email'=>'[email protected]','is_read'=>false]);
|
|
}
|
|
public function test_guests_cannot_open_admin_dashboard(): void { $this->get('/admin')->assertRedirect(route('login')); }
|
|
public function test_non_admin_cannot_access_admin_pages(): void {
|
|
$this->actingAs(User::factory()->create())->get('/admin')->assertForbidden();
|
|
}
|
|
public function test_admin_can_edit_site_content(): void {
|
|
$admin=User::factory()->create(['is_admin'=>true]); $this->actingAs($admin);
|
|
Livewire::test(Sections::class)->set('key','hero')->set('title','A better digital future')
|
|
->set('body','Custom messaging')->set('is_visible',true)->call('save')->assertHasNoErrors();
|
|
$this->assertDatabaseHas('site_sections',['key'=>'hero','title'=>'A better digital future']);
|
|
}
|
|
public function test_honeypot_rejects_spam(): void {
|
|
Livewire::test(ContactForm::class)->set('name','Spam')->set('email','[email protected]')
|
|
->set('message','Spam message example')->set('website','spambot')->call('submit')->assertHasErrors(['website']);
|
|
$this->assertSame(0,ContactEnquiry::count());
|
|
}
|
|
}
|