-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathCrudControllerNegativeTest.php
More file actions
99 lines (86 loc) · 3.33 KB
/
Copy pathCrudControllerNegativeTest.php
File metadata and controls
99 lines (86 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
* Copyright (c) 2025-2026 Netresearch DTT GmbH
* SPDX-License-Identifier: AGPL-3.0-only
*/
declare(strict_types=1);
namespace Tests;
use App\Entity\Project;
/**
* @internal
*
* @coversNothing
*/
final class CrudControllerNegativeTest extends AbstractWebTestCase
{
/**
* Invalid ticket format should return 406.
*/
public function testSaveActionInvalidTicketFormat(): void
{
// Ensure logged in
$this->logInSession('unittest');
// Use a project that enforces ticket format via jiraId
$parameter = [
'start' => '09:00:00',
'end' => '10:00:00',
'date' => '2024-01-02',
'project_id' => 1,
'customer_id' => 1,
'activity_id' => 1,
'ticket' => 'invalid-ticket',
];
$this->client->request(\Symfony\Component\HttpFoundation\Request::METHOD_POST, '/tracking/save', $parameter, [], ['HTTP_ACCEPT' => 'application/json']);
$this->assertStatusCode(400); // Validation still returns 400 for ticket format errors
$data = json_decode((string) $this->client->getResponse()->getContent(), true);
self::assertIsArray($data);
self::assertArrayHasKey('message', $data);
self::assertNotEmpty($data['message']);
}
/**
* Ticket prefix not matching project's Jira ID should return 406.
*/
public function testSaveActionInvalidTicketPrefix(): void
{
$this->logInSession('unittest');
// SA is configured in fixtures; use mismatching prefix
$parameter = [
'start' => '09:00:00',
'end' => '10:00:00',
'date' => '2024-01-03',
'project_id' => 1,
'customer_id' => 1,
'activity_id' => 1,
'ticket' => 'WRONG-123',
];
$this->client->request(\Symfony\Component\HttpFoundation\Request::METHOD_POST, '/tracking/save', $parameter, [], ['HTTP_ACCEPT' => 'application/json']);
$this->assertStatusCode(400); // Validation still returns 400 for ticket prefix errors
$data = json_decode((string) $this->client->getResponse()->getContent(), true);
self::assertIsArray($data);
self::assertArrayHasKey('message', $data);
self::assertNotEmpty($data['message']);
// Depending on data, it might reach prefix check; format check comes first in controller
}
/**
* Inactive project should return 406.
*/
public function testSaveActionInactiveProject(): void
{
$this->logInSession('unittest');
// Project id 2 is inactive in fixtures (see DefaultControllerTest data expectations)
$parameter = [
'start' => '09:00:00',
'end' => '10:00:00',
'date' => '2024-01-04',
'project_id' => 2,
'customer_id' => 1,
'activity_id' => 1,
];
$this->client->request(\Symfony\Component\HttpFoundation\Request::METHOD_POST, '/tracking/save', $parameter, [], ['HTTP_ACCEPT' => 'application/json']);
$this->assertStatusCode(400); // Validation still returns 400 for inactive project errors
$data = json_decode((string) $this->client->getResponse()->getContent(), true);
self::assertIsArray($data);
self::assertArrayHasKey('message', $data);
self::assertNotEmpty($data['message']);
}
}