Skip to content

Commit bf677c2

Browse files
committed
Improve test coverage for BatchEdaController
Add tests for: applying all EDA fields at once, custom redirect URL, and verifying unchecked fields are skipped.
1 parent 7e3aa7f commit bf677c2

1 file changed

Lines changed: 111 additions & 5 deletions

File tree

tests/Controller/BatchEdaControllerTest.php

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
namespace App\Tests\Controller;
2424

25+
use App\Entity\Parts\Part;
2526
use App\Entity\UserSystem\User;
27+
use Doctrine\ORM\EntityManagerInterface;
2628
use PHPUnit\Framework\Attributes\Group;
2729
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
2830

@@ -48,7 +50,6 @@ public function testBatchEdaPageLoads(): void
4850
$client = static::createClient();
4951
$this->loginAsUser($client, 'admin');
5052

51-
// Request with part IDs as comma-separated string (controller uses getString)
5253
$client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2,3']);
5354

5455
self::assertResponseIsSuccessful();
@@ -59,30 +60,135 @@ public function testBatchEdaPageWithoutPartsRedirects(): void
5960
$client = static::createClient();
6061
$this->loginAsUser($client, 'admin');
6162

62-
// Request without part IDs should redirect
6363
$client->request('GET', '/en/tools/batch_eda_edit');
6464

6565
self::assertResponseRedirects();
6666
}
6767

68+
public function testBatchEdaPageWithoutPartsRedirectsToCustomUrl(): void
69+
{
70+
$client = static::createClient();
71+
$this->loginAsUser($client, 'admin');
72+
73+
// Empty IDs with a custom redirect URL
74+
$client->request('GET', '/en/tools/batch_eda_edit', [
75+
'ids' => '',
76+
'_redirect' => '/en/parts',
77+
]);
78+
79+
self::assertResponseRedirects('/en/parts');
80+
}
81+
6882
public function testBatchEdaFormSubmission(): void
6983
{
7084
$client = static::createClient();
7185
$this->loginAsUser($client, 'admin');
7286

73-
// Load the form page first
7487
$crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2']);
7588

7689
self::assertResponseIsSuccessful();
7790

78-
// Find the form and submit it with reference prefix applied
7991
$form = $crawler->selectButton('batch_eda[submit]')->form();
8092
$form['batch_eda[apply_reference_prefix]'] = true;
8193
$form['batch_eda[reference_prefix]'] = 'R';
8294

8395
$client->submit($form);
8496

85-
// Should redirect after successful submission
8697
self::assertResponseRedirects();
8798
}
99+
100+
public function testBatchEdaFormSubmissionAppliesAllFields(): void
101+
{
102+
$client = static::createClient();
103+
$this->loginAsUser($client, 'admin');
104+
105+
$crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2']);
106+
self::assertResponseIsSuccessful();
107+
108+
$form = $crawler->selectButton('batch_eda[submit]')->form();
109+
110+
// Apply all text fields
111+
$form['batch_eda[apply_reference_prefix]'] = true;
112+
$form['batch_eda[reference_prefix]'] = 'C';
113+
$form['batch_eda[apply_value]'] = true;
114+
$form['batch_eda[value]'] = '100nF';
115+
$form['batch_eda[apply_kicad_symbol]'] = true;
116+
$form['batch_eda[kicad_symbol]'] = 'Device:C';
117+
$form['batch_eda[apply_kicad_footprint]'] = true;
118+
$form['batch_eda[kicad_footprint]'] = 'Capacitor_SMD:C_0402';
119+
120+
// Apply all tri-state checkboxes
121+
$form['batch_eda[apply_visibility]'] = true;
122+
$form['batch_eda[apply_exclude_from_bom]'] = true;
123+
$form['batch_eda[apply_exclude_from_board]'] = true;
124+
$form['batch_eda[apply_exclude_from_sim]'] = true;
125+
126+
$client->submit($form);
127+
128+
self::assertResponseRedirects();
129+
130+
// Verify the changes were actually persisted
131+
$em = $client->getContainer()->get('doctrine')->getManager();
132+
$part1 = $em->find(Part::class, 1);
133+
$part2 = $em->find(Part::class, 2);
134+
135+
self::assertSame('C', $part1->getEdaInfo()->getReferencePrefix());
136+
self::assertSame('100nF', $part1->getEdaInfo()->getValue());
137+
self::assertSame('Device:C', $part1->getEdaInfo()->getKicadSymbol());
138+
self::assertSame('Capacitor_SMD:C_0402', $part1->getEdaInfo()->getKicadFootprint());
139+
140+
self::assertSame('C', $part2->getEdaInfo()->getReferencePrefix());
141+
self::assertSame('100nF', $part2->getEdaInfo()->getValue());
142+
}
143+
144+
public function testBatchEdaFormSubmissionWithRedirectUrl(): void
145+
{
146+
$client = static::createClient();
147+
$this->loginAsUser($client, 'admin');
148+
149+
$crawler = $client->request('GET', '/en/tools/batch_eda_edit', [
150+
'ids' => '1',
151+
'_redirect' => '/en/parts',
152+
]);
153+
self::assertResponseIsSuccessful();
154+
155+
$form = $crawler->selectButton('batch_eda[submit]')->form();
156+
$form['batch_eda[apply_reference_prefix]'] = true;
157+
$form['batch_eda[reference_prefix]'] = 'U';
158+
159+
$client->submit($form);
160+
161+
// Should redirect to the custom URL, not the default route
162+
self::assertResponseRedirects('/en/parts');
163+
}
164+
165+
public function testBatchEdaFormSkipsUncheckedFields(): void
166+
{
167+
$client = static::createClient();
168+
$this->loginAsUser($client, 'admin');
169+
170+
// First, set a known value
171+
$em = $client->getContainer()->get('doctrine')->getManager();
172+
$part = $em->find(Part::class, 3);
173+
$part->getEdaInfo()->setReferencePrefix('ORIGINAL');
174+
$em->flush();
175+
176+
$crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '3']);
177+
self::assertResponseIsSuccessful();
178+
179+
$form = $crawler->selectButton('batch_eda[submit]')->form();
180+
// Only apply value, NOT reference_prefix
181+
$form['batch_eda[apply_value]'] = true;
182+
$form['batch_eda[value]'] = 'NewValue';
183+
// Explicitly leave apply_reference_prefix unchecked (default)
184+
185+
$client->submit($form);
186+
self::assertResponseRedirects();
187+
188+
// Refresh entity
189+
$em->clear();
190+
$part = $em->find(Part::class, 3);
191+
self::assertSame('ORIGINAL', $part->getEdaInfo()->getReferencePrefix());
192+
self::assertSame('NewValue', $part->getEdaInfo()->getValue());
193+
}
88194
}

0 commit comments

Comments
 (0)