APIv4 - Reorganize test classes, don't use transactions for custom value tests
[civicrm-core.git] / tests / phpunit / api / v4 / Action / ContactIsDeletedTest.php
CommitLineData
e1f5526a
SL
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
20namespace api\v4\Action;
21
46f571dd
CW
22use api\v4\Api4TestBase;
23use Civi\Test\TransactionalInterface;
e1f5526a
SL
24
25/**
26 * @group headless
27 */
46f571dd 28class ContactIsDeletedTest extends Api4TestBase implements TransactionalInterface {
e1f5526a
SL
29
30 public function setUpHeadless() {
31 $relatedTables = [
32 'civicrm_address',
33 'civicrm_email',
34 'civicrm_phone',
35 'civicrm_openid',
36 'civicrm_im',
37 'civicrm_website',
38 'civicrm_activity',
39 'civicrm_activity_contact',
40 ];
41 $this->cleanup(['tablesToTruncate' => $relatedTables]);
42 $displayNameFormat = '{contact.first_name}{ }{contact.last_name}';
43 \Civi::settings()->set('display_name_format', $displayNameFormat);
44
45 return parent::setUpHeadless();
46 }
47
48 /**
49 * This locks in a fix to ensure that if a user doesn't have permission to view the is_deleted field that doesn't hard fail if that field happens to be in an APIv4 call.
50 */
51 public function testIsDeletedPermission(): void {
52 $contact = $this->createLoggedInUser();
53 \CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts'];
54 $originalQuery = civicrm_api4('Contact', 'get', [
55 'checkPermissions' => TRUE,
56 'select' => ['id', 'display_name', 'is_deleted'],
57 'where' => [['first_name', '=', 'phoney']],
58 ]);
59
60 try {
61 $isDeletedQuery = civicrm_api4('Contact', 'get', [
62 'checkPermissions' => TRUE,
63 'select' => ['id', 'display_name'],
64 'where' => [['first_name', '=', 'phoney'], ['is_deleted', '=', 0]],
65 ]);
66 $this->assertEquals(count($originalQuery), count($isDeletedQuery));
67 }
68 catch (\API_Exception $e) {
69 $this->fail('An Exception Should not have been raised');
70 }
71 try {
72 $isDeletedJoinTest = civicrm_api4('Email', 'get', [
73 'checkPermissions' => TRUE,
74 'where' => [['contact_id.first_name', '=', 'phoney'], ['contact_id.is_deleted', '=', 0]],
75 ]);
76 }
77 catch (\API_Exception $e) {
78 $this->fail('An Exception Should not have been raised');
79 }
80 }
81
82}