Merge pull request #20884 from MegaphoneJon/financial-89
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / CaseTest.php
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
20 namespace api\v4\Entity;
21
22 use Civi\Api4\CiviCase;
23 use api\v4\UnitTestCase;
24 use Civi\Api4\Relationship;
25
26 /**
27 * @group headless
28 */
29 class CaseTest extends UnitTestCase {
30
31 public function setUp(): void {
32 parent::setUp();
33 \CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
34 $this->loadDataSet('CaseType');
35 }
36
37 public function tearDown(): void {
38 $relatedTables = [
39 'civicrm_activity',
40 'civicrm_activity_contact',
41 'civicrm_relationship',
42 'civicrm_case_contact',
43 'civicrm_case_type',
44 'civicrm_case',
45 ];
46 $this->cleanup(['tablesToTruncate' => $relatedTables]);
47 parent::tearDown();
48 }
49
50 public function testCreateUsingLoggedInUser() {
51 $uid = $this->createLoggedInUser();
52
53 $contactID = $this->createEntity(['type' => 'Individual'])['id'];
54
55 $case = CiviCase::create(FALSE)
56 ->addValue('case_type_id', $this->getReference('test_case_type_1')['id'])
57 ->addValue('creator_id', 'user_contact_id')
58 ->addValue('status_id', 1)
59 ->addValue('contact_id', $contactID)
60 ->execute()
61 ->first();
62
63 $relationships = Relationship::get(FALSE)
64 ->addWhere('case_id', '=', $case['id'])
65 ->execute();
66
67 $this->assertCount(1, $relationships);
68 $this->assertEquals($uid, $relationships[0]['contact_id_b']);
69 $this->assertEquals($contactID, $relationships[0]['contact_id_a']);
70 }
71
72 }