4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 namespace api\v
4\Entity
;
21 use api\v
4\UnitTestCase
;
23 use Civi\Test\TransactionalInterface
;
28 class NoteTest
extends UnitTestCase
implements TransactionalInterface
{
30 public function testDeleteWithChildren() {
31 $c1 = $this->createEntity(['type' => 'Individual']);
33 $text = uniqid(__FUNCTION__
, TRUE);
35 // Create 2 top-level notes.
36 $notes = Note
::save(FALSE)
37 ->setRecords([['note' => $text], ['note' => $text]])
39 'entity_id' => $c1['id'],
40 'entity_table' => 'civicrm_contact',
43 // Add 2 children of the first note.
44 $children = Note
::save(FALSE)
45 ->setRecords([['note' => $text], ['note' => $text]])
47 'entity_id' => $notes->first()['id'],
48 'entity_table' => 'civicrm_note',
51 // Add 2 children of the first child.
52 $grandChildren = Note
::save(FALSE)
53 ->setRecords([['note' => $text], ['note' => $text]])
55 'entity_id' => $children->first()['id'],
56 'entity_table' => 'civicrm_note',
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)
63 $this->assertCount(6, $existing);
67 ->addWhere('id', '=', $notes->first()['id'])
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)
74 $this->assertCount(1, $existing);