From 9dad7ab939691bde77406f2dc56f5be96e3f3f93 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Sat, 7 Nov 2026 14:17:45 +0100 Subject: [PATCH] Fix settings form being sent as PUT FormHelper adds a hidden _method=PUT for persisted entities, which the POST-only admin:settings route rejected with a MissingRouteException. Co-Authored-By: Claude Opus 5.5 --- templates/Admin/index.php | 2 +- tests/TestCase/Controller/AdminControllerTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/templates/Admin/index.php b/templates/Admin/index.php index 1ca752a..9300f12 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -127,7 +127,7 @@ $url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $ad

- Form->create($poll, ['url' => $url('admin:settings')]) ?> + Form->create($poll, ['url' => $url('admin:settings'), 'type' => 'post']) ?> Form->control('title', ['label' => __('Titel'), 'maxlength' => 200]) ?> Form->control('is_active', [ 'type' => 'checkbox', diff --git a/tests/TestCase/Controller/AdminControllerTest.php b/tests/TestCase/Controller/AdminControllerTest.php index 8da0ba6..72d58ed 100644 --- a/tests/TestCase/Controller/AdminControllerTest.php +++ b/tests/TestCase/Controller/AdminControllerTest.php @@ -49,6 +49,17 @@ class AdminControllerTest extends TestCase $this->assertHeaderContains('X-Robots-Tag', 'noindex'); } + public function testSettingsFormPostsAndSaves(): void + { + [$poll, $token] = $this->createPoll('Alt'); + $this->get("/admin/$token"); + $this->assertResponseNotContains('name="_method" value="PUT"', 'settings form must not override method'); + + $this->post("/admin/$token/settings", ['title' => 'Neu', 'is_active' => '1', 'show_results_to_participants' => '0']); + $this->assertRedirect(['_name' => 'admin', 'token' => $token]); + $this->assertSame('Neu', $this->pollsTable()->get($poll->id)->title); + } + public function testTokenOfOtherPollCannotAccessSlides(): void { [$pollA] = $this->createPoll('A');