Files
Lesstime/tests/Functional/Controller/Mail/MailTaskIntegrationControllerTest.php
T
Matthieu 23809f165e feat(project-management) : migrate core Projects/Tasks domain into module (back)
Tranche 2 of LST-65. Mechanical, behaviour-preserving move of the core
business domain into src/Module/ProjectManagement/. API operations,
securities, uriTemplates and the 38 MCP tool names are all unchanged.

- 10 entities + 2 enums moved to Domain/{Entity,Enum}; intra-module
  relations stay concrete, cross-module relations go through contracts
  (Project.client -> ClientInterface, Task/TaskDocument users ->
  UserInterface).
- 9 repositories split into Domain/Repository interfaces + Doctrine impls,
  bound in services.yaml; consumers inject the interfaces. find() kept off
  the interfaces (ServiceEntityRepository ?object compat) -> findById().
- State (7), MCP tools (38), controller, CalDavService/RecurrenceCalculator,
  3 Doctrine listeners and SwitchWorkflowOutput moved under Infrastructure/.
- doctrine.yaml: ProjectManagement mapping + resolve_target_entities of the
  3 module contracts repointed to the module (ClientInterface stays legacy).
- ProjectManagementModule registered (id project-management, 4 RBAC perms,
  not re-wired); sidebar my-tasks/projects gated by the module.
- Legacy not-yet-modularised consumers (Mail/Gitea/BookStack, Serializer,
  fixtures, tests) swapped to the module FQCN — transitional coupling to be
  cleaned in 2.4/2.5/2.6.

159 tests green, mapping valid, no API route regression, cs-fixer clean.
2026-06-20 16:54:59 +02:00

115 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Functional\Controller\Mail;
use App\Entity\MailFolder;
use App\Entity\MailMessage;
use App\Module\Core\Domain\Entity\User;
use App\Module\ProjectManagement\Domain\Entity\Project;
use App\Module\ProjectManagement\Domain\Entity\Task;
use DateTimeImmutable;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @internal
*/
class MailTaskIntegrationControllerTest extends WebTestCase
{
public function testLinkTaskReturns401WhenNotAuthenticated(): void
{
$client = static::createClient();
$client->request('POST', '/api/mail/messages/1/link-task', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode(['taskId' => 1]));
self::assertResponseStatusCodeSame(401);
}
public function testUnlinkTaskReturns401WhenNotAuthenticated(): void
{
$client = static::createClient();
$client->request('DELETE', '/api/mail/messages/1/link-task/1');
self::assertResponseStatusCodeSame(401);
}
public function testTaskMailsListReturns401WhenNotAuthenticated(): void
{
$client = static::createClient();
$client->request('GET', '/api/tasks/1/mails');
self::assertResponseStatusCodeSame(401);
}
public function testCreateTaskReturns401WhenNotAuthenticated(): void
{
$client = static::createClient();
$client->request('POST', '/api/mail/messages/1/create-task', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode(['projectId' => 1]));
self::assertResponseStatusCodeSame(401);
}
public function testCreateTaskAppliesStatusAndAssigneeAndIgnoresPriority(): void
{
$client = static::createClient();
$container = static::getContainer();
$em = $container->get('doctrine.orm.entity_manager');
$admin = $em->getRepository(User::class)->findOneBy(['username' => 'admin']);
$client->loginUser($admin);
$project = $em->getRepository(Project::class)->findOneBy([]);
self::assertNotNull($project);
$status = $project->getWorkflow()->getStatuses()->first();
self::assertNotFalse($status);
// Create a mail folder + message in the test DB (none in fixtures)
$folder = new MailFolder();
$folder->setDisplayName('Boîte de réception');
$folder->setUnreadCount(0);
$folder->setTotalCount(0);
$em->persist($folder);
$rand = random_int(100000, 999999);
$folder->setPath('INBOX.'.$rand);
$message = new MailMessage();
$message->setMessageId('test-'.$rand.'@example.com');
$message->setFolder($folder);
$message->setUid($rand);
$message->setFromAddress('sender@example.com');
$message->setToAddresses([]);
$message->setSentAt(new DateTimeImmutable());
$message->setIsRead(false);
$message->setIsFlagged(false);
$message->setHasAttachments(false);
$message->setSyncedAt(new DateTimeImmutable());
$message->setSubject('Sujet de test');
$em->persist($message);
$em->flush();
$client->request(
'POST',
'/api/mail/messages/'.$message->getId().'/create-task',
[],
[],
['CONTENT_TYPE' => 'application/json'],
json_encode([
'projectId' => $project->getId(),
'assigneeId' => $admin->getId(),
'statusId' => $status->getId(),
'priorityId' => 999, // doit être ignoré
])
);
self::assertResponseStatusCodeSame(201);
$payload = json_decode($client->getResponse()->getContent(), true);
$em->clear();
$task = $em->getRepository(Task::class)->find($payload['taskId']);
self::assertSame($status->getId(), $task->getStatus()?->getId());
self::assertSame($admin->getId(), $task->getAssignee()?->getId());
self::assertNull($task->getPriority());
}
}