|
37 | 37 | use CommonITILActor; |
38 | 38 | use CommonITILObject; |
39 | 39 | use Computer; |
| 40 | +use Contract; |
40 | 41 | use CronTask; |
41 | 42 | use DbTestCase; |
42 | 43 | use Entity; |
|
54 | 55 | use Supplier_Ticket; |
55 | 56 | use Symfony\Component\DomCrawler\Crawler; |
56 | 57 | use Ticket; |
| 58 | +use Ticket_Contract; |
57 | 59 | use Ticket_User; |
58 | 60 | use TicketValidation; |
59 | 61 | use User; |
@@ -8289,4 +8291,37 @@ public function testSelfServiceFormRendering(): void |
8289 | 8291 | // trigger in case of issues. |
8290 | 8292 | $this->assertNotEmpty($content); |
8291 | 8293 | } |
| 8294 | + |
| 8295 | + public function testHandleAddContracts() |
| 8296 | + { |
| 8297 | + $this->login(); |
| 8298 | + $contract_1 = $this->createItem(Contract::class, [ |
| 8299 | + 'name' => 'Contract 1', |
| 8300 | + 'entities_id' => $this->getTestRootEntity(true), |
| 8301 | + ]); |
| 8302 | + $contract_2 = $this->createItem(Contract::class, [ |
| 8303 | + 'name' => 'Contract 2', |
| 8304 | + 'entities_id' => $this->getTestRootEntity(true), |
| 8305 | + ]); |
| 8306 | + |
| 8307 | + $ticket = $this->createItem(Ticket::class, [ |
| 8308 | + 'name' => 'Ticket with contracts', |
| 8309 | + 'content' => 'test', |
| 8310 | + 'entities_id' => $this->getTestRootEntity(true), |
| 8311 | + '_contracts_id' => $contract_1->getID(), |
| 8312 | + ]); |
| 8313 | + $tc = new Ticket_Contract(); |
| 8314 | + $linked_contracts = array_values($tc->find(['tickets_id' => $ticket->getID()])); |
| 8315 | + $this->assertCount(1, $linked_contracts); |
| 8316 | + $this->assertEquals($contract_1->getID(), $linked_contracts[0]['contracts_id']); |
| 8317 | + |
| 8318 | + $ticket->update([ |
| 8319 | + 'id' => $ticket->getID(), |
| 8320 | + '_contracts_id' => $contract_2->getID(), |
| 8321 | + ]); |
| 8322 | + $linked_contracts = array_values($tc->find(['tickets_id' => $ticket->getID()])); |
| 8323 | + $this->assertCount(2, $linked_contracts); |
| 8324 | + $this->assertContains($contract_1->getID(), array_column($linked_contracts, 'contracts_id')); |
| 8325 | + $this->assertContains($contract_2->getID(), array_column($linked_contracts, 'contracts_id')); |
| 8326 | + } |
8292 | 8327 | } |
0 commit comments