mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-04 06:19:36 +00:00
Improve test coverage for BatchEdaController
Add tests for: applying all EDA fields at once, custom redirect URL, and verifying unchecked fields are skipped.
This commit is contained in:
parent
7e3aa7fed8
commit
06c6542438
1 changed files with 88 additions and 5 deletions
|
|
@ -48,7 +48,6 @@ final class BatchEdaControllerTest extends WebTestCase
|
||||||
$client = static::createClient();
|
$client = static::createClient();
|
||||||
$this->loginAsUser($client, 'admin');
|
$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']);
|
$client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2,3']);
|
||||||
|
|
||||||
self::assertResponseIsSuccessful();
|
self::assertResponseIsSuccessful();
|
||||||
|
|
@ -59,30 +58,114 @@ final class BatchEdaControllerTest extends WebTestCase
|
||||||
$client = static::createClient();
|
$client = static::createClient();
|
||||||
$this->loginAsUser($client, 'admin');
|
$this->loginAsUser($client, 'admin');
|
||||||
|
|
||||||
// Request without part IDs should redirect
|
|
||||||
$client->request('GET', '/en/tools/batch_eda_edit');
|
$client->request('GET', '/en/tools/batch_eda_edit');
|
||||||
|
|
||||||
self::assertResponseRedirects();
|
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
|
public function testBatchEdaFormSubmission(): void
|
||||||
{
|
{
|
||||||
$client = static::createClient();
|
$client = static::createClient();
|
||||||
$this->loginAsUser($client, 'admin');
|
$this->loginAsUser($client, 'admin');
|
||||||
|
|
||||||
// Load the form page first
|
|
||||||
$crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2']);
|
$crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2']);
|
||||||
|
|
||||||
self::assertResponseIsSuccessful();
|
self::assertResponseIsSuccessful();
|
||||||
|
|
||||||
// Find the form and submit it with reference prefix applied
|
|
||||||
$form = $crawler->selectButton('batch_eda[submit]')->form();
|
$form = $crawler->selectButton('batch_eda[submit]')->form();
|
||||||
$form['batch_eda[apply_reference_prefix]'] = true;
|
$form['batch_eda[apply_reference_prefix]'] = true;
|
||||||
$form['batch_eda[reference_prefix]'] = 'R';
|
$form['batch_eda[reference_prefix]'] = 'R';
|
||||||
|
|
||||||
$client->submit($form);
|
$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();
|
self::assertResponseRedirects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue