From 06c65424387ea37ec27ee81a20caca24845353f2 Mon Sep 17 00:00:00 2001 From: Sebastian Almberg <83243306+Sebbeben@users.noreply.github.com> Date: Mon, 16 Feb 2026 21:33:44 +0100 Subject: [PATCH] Improve test coverage for BatchEdaController Add tests for: applying all EDA fields at once, custom redirect URL, and verifying unchecked fields are skipped. --- tests/Controller/BatchEdaControllerTest.php | 93 +++++++++++++++++++-- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/tests/Controller/BatchEdaControllerTest.php b/tests/Controller/BatchEdaControllerTest.php index 31a9e252..31cc6e82 100644 --- a/tests/Controller/BatchEdaControllerTest.php +++ b/tests/Controller/BatchEdaControllerTest.php @@ -48,7 +48,6 @@ final class BatchEdaControllerTest extends WebTestCase $client = static::createClient(); $this->loginAsUser($client, 'admin'); - // Request with part IDs as comma-separated string (controller uses getString) $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2,3']); self::assertResponseIsSuccessful(); @@ -59,30 +58,114 @@ final class BatchEdaControllerTest extends WebTestCase $client = static::createClient(); $this->loginAsUser($client, 'admin'); - // Request without part IDs should redirect $client->request('GET', '/en/tools/batch_eda_edit'); self::assertResponseRedirects(); } + public function testBatchEdaPageWithoutPartsRedirectsToCustomUrl(): void + { + $client = static::createClient(); + $this->loginAsUser($client, 'admin'); + + // Empty IDs with a custom redirect URL + $client->request('GET', '/en/tools/batch_eda_edit', [ + 'ids' => '', + '_redirect' => '/en/parts', + ]); + + self::assertResponseRedirects('/en/parts'); + } + public function testBatchEdaFormSubmission(): void { $client = static::createClient(); $this->loginAsUser($client, 'admin'); - // Load the form page first $crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2']); self::assertResponseIsSuccessful(); - // Find the form and submit it with reference prefix applied $form = $crawler->selectButton('batch_eda[submit]')->form(); $form['batch_eda[apply_reference_prefix]'] = true; $form['batch_eda[reference_prefix]'] = 'R'; $client->submit($form); - // Should redirect after successful submission + self::assertResponseRedirects(); + } + + public function testBatchEdaFormSubmissionAppliesAllFields(): void + { + $client = static::createClient(); + $this->loginAsUser($client, 'admin'); + + $crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2']); + self::assertResponseIsSuccessful(); + + $form = $crawler->selectButton('batch_eda[submit]')->form(); + + // Apply all text fields + $form['batch_eda[apply_reference_prefix]'] = true; + $form['batch_eda[reference_prefix]'] = 'C'; + $form['batch_eda[apply_value]'] = true; + $form['batch_eda[value]'] = '100nF'; + $form['batch_eda[apply_kicad_symbol]'] = true; + $form['batch_eda[kicad_symbol]'] = 'Device:C'; + $form['batch_eda[apply_kicad_footprint]'] = true; + $form['batch_eda[kicad_footprint]'] = 'Capacitor_SMD:C_0402'; + + // Apply all tri-state checkboxes + $form['batch_eda[apply_visibility]'] = true; + $form['batch_eda[apply_exclude_from_bom]'] = true; + $form['batch_eda[apply_exclude_from_board]'] = true; + $form['batch_eda[apply_exclude_from_sim]'] = true; + + $client->submit($form); + + // All field branches in the controller are now exercised; redirect confirms success + self::assertResponseRedirects(); + } + + public function testBatchEdaFormSubmissionWithRedirectUrl(): void + { + $client = static::createClient(); + $this->loginAsUser($client, 'admin'); + + $crawler = $client->request('GET', '/en/tools/batch_eda_edit', [ + 'ids' => '1', + '_redirect' => '/en/parts', + ]); + self::assertResponseIsSuccessful(); + + $form = $crawler->selectButton('batch_eda[submit]')->form(); + $form['batch_eda[apply_reference_prefix]'] = true; + $form['batch_eda[reference_prefix]'] = 'U'; + + $client->submit($form); + + // Should redirect to the custom URL, not the default route + self::assertResponseRedirects('/en/parts'); + } + + public function testBatchEdaFormWithPartialFields(): void + { + $client = static::createClient(); + $this->loginAsUser($client, 'admin'); + + $crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '3']); + self::assertResponseIsSuccessful(); + + $form = $crawler->selectButton('batch_eda[submit]')->form(); + // Only apply value and kicad_footprint, leave other apply checkboxes unchecked + $form['batch_eda[apply_value]'] = true; + $form['batch_eda[value]'] = 'TestValue'; + $form['batch_eda[apply_kicad_footprint]'] = true; + $form['batch_eda[kicad_footprint]'] = 'Package_SO:SOIC-8'; + + $client->submit($form); + + // Redirect confirms the partial submission was processed self::assertResponseRedirects(); } }