fix: scontainers edit saves existing record instead of creating new
Fixes static container admin edit flow by preserving id in hiddenFields and adding route-id fallback during save. Adds regression tests for edit/create id behavior, updates release docs (changelog/testing/CLAUDE), and appends SonarQube open issues to docs/TODO. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,5 +55,38 @@ class ScontainersControllerTest extends TestCase
|
||||
$this->assertEquals('Domain\Scontainers\ScontainersRepository', $params[0]->getType()->getName());
|
||||
$this->assertEquals('Domain\Languages\LanguagesRepository', $params[1]->getType()->getName());
|
||||
}
|
||||
|
||||
public function testBuildFormViewModelStoresIdInHiddenFieldsForEdit(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(ScontainersController::class);
|
||||
$method = $reflection->getMethod('buildFormViewModel');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = [
|
||||
'id' => 9,
|
||||
'status' => 1,
|
||||
'show_title' => 1,
|
||||
'languages' => [],
|
||||
];
|
||||
|
||||
$form = $method->invoke($this->controller, $container, [], null);
|
||||
|
||||
$this->assertArrayHasKey('id', $form->hiddenFields);
|
||||
$this->assertSame(9, (int)$form->hiddenFields['id']);
|
||||
$this->assertSame('/admin/scontainers/save/id=9', $form->action);
|
||||
}
|
||||
|
||||
public function testBuildFormViewModelKeepsCreateFlowWithZeroId(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(ScontainersController::class);
|
||||
$method = $reflection->getMethod('buildFormViewModel');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$form = $method->invoke($this->controller, [], [], null);
|
||||
|
||||
$this->assertArrayHasKey('id', $form->hiddenFields);
|
||||
$this->assertSame(0, (int)$form->hiddenFields['id']);
|
||||
$this->assertSame('/admin/scontainers/save/', $form->action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user