Skip to content

Commit

Permalink
[WIP][NFC] dev/mail#103 Add in unit test to demonstate issue with API…
Browse files Browse the repository at this point in the history
…v4 and joins
  • Loading branch information
seamuslee001 committed Nov 12, 2021
1 parent 016e9d5 commit c555a17
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/phpunit/api/v4/Entity/ContactCustomJoinTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/


namespace api\v4\Entity;

use Civi\Api4\Contact;
use Civi\Api4\CustomGroup;
use Civi\Api4\CustomField;
use api\v4\UnitTestCase;

/**
* @group headless
*/
class ContactCustomJoinTest extends UnitTestCase {

public function testContactCustomJoin() {
$customGroup = CustomGroup::create()->setValues([
'name' => 'D - Identification_20',
'table_name' => 'civicrm_value_demographics',
'title' => 'D - Identification',
'extends' => 'Individual',
])->execute();
\CRM_Core_DAO::executeQuery("UPDATE civicrm_custom_group SET name = 'D - Identification_20' WHERE id = %1", [1 => [$customGroup[0]['id'], 'Integer']]);
$customField = CustomField::create()->setValues([
'label' => 'Test field',
'custom_group_id' => $customGroup[0]['id'],
'html_type' => 'Text',
'data_type' => 'String',
])->execute();
Contact::get()->addSelect('*')->addSelect('custom.*')->execute();
CustomField::delete()->addWhere('id', '=', $customField[0]['id']);
CustomGroup::delete()->addWhere('id', '=', $customGroup[0]['id']);
}

}

0 comments on commit c555a17

Please sign in to comment.