Commit | Line | Data |
---|---|---|
6623e554 CW |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | Copyright CiviCRM LLC. All rights reserved. | | |
6 | | | | |
7 | | This work is published under the GNU AGPLv3 license with some | | |
8 | | permitted exceptions and without any warranty. For full license | | |
9 | | and copyright information, see https://civicrm.org/licensing | | |
10 | +--------------------------------------------------------------------+ | |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
16 | * @copyright CiviCRM LLC https://civicrm.org/licensing | |
17 | */ | |
18 | ||
19 | namespace api\v4\Entity; | |
20 | ||
21 | use api\v4\UnitTestCase; | |
22 | use Civi\Api4\Note; | |
23 | use Civi\Test\TransactionalInterface; | |
24 | ||
25 | /** | |
26 | * @group headless | |
27 | */ | |
28 | class NoteTest extends UnitTestCase implements TransactionalInterface { | |
29 | ||
30 | public function testDeleteWithChildren() { | |
31 | $c1 = $this->createEntity(['type' => 'Individual']); | |
32 | ||
33 | $text = uniqid(__FUNCTION__, TRUE); | |
34 | ||
35 | // Create 2 top-level notes. | |
36 | $notes = Note::save(FALSE) | |
37 | ->setRecords([['note' => $text], ['note' => $text]]) | |
38 | ->setDefaults([ | |
39 | 'entity_id' => $c1['id'], | |
40 | 'entity_table' => 'civicrm_contact', | |
41 | ])->execute(); | |
42 | ||
43 | // Add 2 children of the first note. | |
44 | $children = Note::save(FALSE) | |
45 | ->setRecords([['note' => $text], ['note' => $text]]) | |
46 | ->setDefaults([ | |
47 | 'entity_id' => $notes->first()['id'], | |
48 | 'entity_table' => 'civicrm_note', | |
49 | ])->execute(); | |
50 | ||
51 | // Add 2 children of the first child. | |
52 | $grandChildren = Note::save(FALSE) | |
53 | ->setRecords([['note' => $text], ['note' => $text]]) | |
54 | ->setDefaults([ | |
55 | 'entity_id' => $children->first()['id'], | |
56 | 'entity_table' => 'civicrm_note', | |
57 | ])->execute(); | |
58 | ||
59 | // We just created 2 top-level notes and 4 children. Ensure we have a total of 6. | |
60 | $existing = Note::get(FALSE) | |
61 | ->addWhere('note', '=', $text) | |
62 | ->execute(); | |
63 | $this->assertCount(6, $existing); | |
64 | ||
65 | // Delete parent | |
66 | Note::delete(FALSE) | |
67 | ->addWhere('id', '=', $notes->first()['id']) | |
68 | ->execute(); | |
69 | ||
70 | // Should have deleted 1 parent + 4 child-notes, for a new total of 1 remaining. | |
71 | $existing = Note::get(FALSE) | |
72 | ->addWhere('note', '=', $text) | |
73 | ->execute(); | |
74 | $this->assertCount(1, $existing); | |
75 | } | |
76 | ||
77 | } |