[NFC] dev/mail#103 Add in unit test to demonstate issue with APIv4 and joins
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 12 Nov 2021 00:59:43 +0000 (11:59 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 12 Nov 2021 22:50:56 +0000 (22:50 +0000)
Add comment to test along the lines from Coleman and fix test cleanup

Update test to extend from BaseCustomValueTest

tests/phpunit/api/v4/Entity/ContactCustomJoinTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/api/v4/Entity/ContactCustomJoinTest.php b/tests/phpunit/api/v4/Entity/ContactCustomJoinTest.php
new file mode 100644 (file)
index 0000000..2a92ec0
--- /dev/null
@@ -0,0 +1,53 @@
+<?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\Action\BaseCustomValueTest;
+
+/**
+ * @group headless
+ */
+class ContactCustomJoinTest extends BaseCustomValueTest {
+
+  /**
+   * Add test to ensure that in the very unusual and not really supported situation where there is a space in the
+   * custom group machine name. This is not supported but has been seen in the wild and as such we have this test to lock in the fix for dev/mail#103
+   */
+  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();
+  }
+
+}