Implemented a block editor for changing the layout of the page

This commit is contained in:
2026-04-04 01:17:05 +02:00
parent 0800f7664f
commit ff58e82497
41 changed files with 2706 additions and 298 deletions

View File

@@ -7,6 +7,7 @@ namespace Tests\Feature;
use App\Models\PreregistrationPage;
use App\Models\Subscriber;
use App\Models\User;
use App\Services\PreregistrationPageBlockWriter;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
@@ -199,7 +200,7 @@ class PublicPageTest extends TestCase
{
$user = User::factory()->create(['role' => 'user']);
return PreregistrationPage::query()->create(array_merge([
$page = PreregistrationPage::query()->create(array_merge([
'slug' => (string) Str::uuid(),
'user_id' => $user->id,
'title' => 'Test page',
@@ -211,7 +212,36 @@ class PublicPageTest extends TestCase
'start_date' => now()->subHour(),
'end_date' => now()->addMonth(),
'phone_enabled' => false,
'background_image' => null,
'logo_image' => null,
'is_active' => true,
], $overrides));
$writer = app(PreregistrationPageBlockWriter::class);
if (! $page->blocks()->exists()) {
$writer->seedDefaultBlocks($page);
}
$page->refresh();
$hero = $page->getHeroBlock();
if ($hero !== null) {
$c = $hero->content;
$c['headline'] = $page->heading;
$hero->update(['content' => $c]);
}
if (($overrides['phone_enabled'] ?? false) === true) {
$page->load('blocks');
$form = $page->getFormBlock();
if ($form !== null) {
$c = $form->content;
data_set($c, 'fields.phone.enabled', true);
$form->update(['content' => $c]);
}
}
$page->syncLegacyContentColumnsFromBlocks();
return $page->fresh(['blocks']);
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tests\Feature;
use App\Models\PageBlock;
use App\Models\PreregistrationPage;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -19,20 +20,19 @@ class StorePreregistrationPageTest extends TestCase
$response = $this->actingAs($user)->post(route('admin.pages.store'), [
'title' => 'Summer Fest',
'heading' => 'Register',
'intro_text' => null,
'thank_you_message' => null,
'expired_message' => null,
'ticketshop_url' => null,
'start_date' => '2026-06-01T10:00',
'end_date' => '2026-06-30T18:00',
'phone_enabled' => false,
'is_active' => true,
]);
$response->assertRedirect(route('admin.pages.index'));
$this->assertDatabaseCount('preregistration_pages', 1);
$this->assertSame('Summer Fest', PreregistrationPage::query()->first()?->title);
$page = PreregistrationPage::query()->first();
$response->assertRedirect(route('admin.pages.edit', $page));
$this->assertSame('Summer Fest', $page?->title);
$this->assertGreaterThanOrEqual(4, PageBlock::query()->where('preregistration_page_id', $page?->id)->count());
}
public function test_validation_failure_redirects_back_with_input(): void
@@ -41,13 +41,11 @@ class StorePreregistrationPageTest extends TestCase
$response = $this->actingAs($user)->from(route('admin.pages.create'))->post(route('admin.pages.store'), [
'title' => '',
'heading' => 'H',
'start_date' => '2026-06-30T10:00',
'end_date' => '2026-06-01T10:00',
]);
$response->assertRedirect(route('admin.pages.create'));
$response->assertSessionHasErrors('title');
$response->assertSessionHasInput('heading', 'H');
}
}