2026-02-12 22:23:21 +01:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
|
|
|
|
|
|
use App\Entity\UserSystem\User;
|
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
|
|
|
|
|
|
#[Group("slow")]
|
|
|
|
|
#[Group("DB")]
|
2026-02-12 22:27:01 +01:00
|
|
|
final class BatchEdaControllerTest extends WebTestCase
|
2026-02-12 22:23:21 +01:00
|
|
|
{
|
|
|
|
|
private function loginAsUser($client, string $username): void
|
|
|
|
|
{
|
|
|
|
|
$entityManager = $client->getContainer()->get('doctrine')->getManager();
|
|
|
|
|
$userRepository = $entityManager->getRepository(User::class);
|
|
|
|
|
$user = $userRepository->findOneBy(['name' => $username]);
|
|
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
|
$this->markTestSkipped("User {$username} not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$client->loginUser($user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testBatchEdaPageLoads(): void
|
|
|
|
|
{
|
|
|
|
|
$client = static::createClient();
|
|
|
|
|
$this->loginAsUser($client, 'admin');
|
|
|
|
|
|
2026-02-12 22:27:01 +01:00
|
|
|
// Request with part IDs as comma-separated string (controller uses getString)
|
|
|
|
|
$client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2,3']);
|
2026-02-12 22:23:21 +01:00
|
|
|
|
|
|
|
|
self::assertResponseIsSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testBatchEdaPageWithoutPartsRedirects(): void
|
|
|
|
|
{
|
|
|
|
|
$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 testBatchEdaFormSubmission(): void
|
|
|
|
|
{
|
|
|
|
|
$client = static::createClient();
|
|
|
|
|
$this->loginAsUser($client, 'admin');
|
|
|
|
|
|
|
|
|
|
// Load the form page first
|
2026-02-12 22:27:01 +01:00
|
|
|
$crawler = $client->request('GET', '/en/tools/batch_eda_edit', ['ids' => '1,2']);
|
2026-02-12 22:23:21 +01:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|