Test tearDown fixes
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / CustomValueTableTest.php
index c27ac83d878373c092ffbf304e2b7e52e72a28d9..61b74ad1b97444a39efb76b28eeefaafd2abc575 100644 (file)
@@ -6,6 +6,11 @@
  */
 class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
 
+  public function tearDown(): void {
+    $this->quickCleanup(['civicrm_file', 'civicrm_entity_file'], TRUE);
+    parent::tearDown();
+  }
+
   /**
    * Test store function for country.
    */
@@ -35,10 +40,6 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
     ];
 
     CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
-    $this->customFieldDelete($customField['id']);
-    $this->customGroupDelete($customGroup['id']);
-    $this->contactDelete($contactID);
   }
 
   /**
@@ -70,16 +71,12 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
     ];
 
     CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
-    $this->customFieldDelete($customField['id']);
-    $this->customGroupDelete($customGroup['id']);
-    $this->contactDelete($contactID);
   }
 
   /**
    * Test store function for state province.
    */
-  public function testStoreStateProvince() {
+  public function testStoreStateProvince(): void {
     $contactID = $this->individualCreate();
     $customGroup = $this->customGroupCreate();
     $fields = [
@@ -104,16 +101,12 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
     ];
 
     CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
-    $this->customFieldDelete($customField['id']);
-    $this->customGroupDelete($customGroup['id']);
-    $this->contactDelete($contactID);
   }
 
   /**
    * Test store function for date.
    */
-  public function testStoreDate() {
+  public function testStoreDate(): void {
     $params = [];
     $contactID = $this->individualCreate();
     $customGroup = $this->customGroupCreate();
@@ -139,16 +132,12 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
     ];
 
     CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
-    $this->customFieldDelete($customField['id']);
-    $this->customGroupDelete($customGroup['id']);
-    $this->contactDelete($contactID);
   }
 
   /**
    * Test store function for rich text editor.
    */
-  public function testStoreRichTextEditor() {
+  public function testStoreRichTextEditor(): void {
     $params = [];
     $contactID = $this->individualCreate();
     $customGroup = $this->customGroupCreate();
@@ -173,17 +162,56 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
     ];
 
     CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
+  }
+
+  /**
+   * Test store function for multiselect int.
+   *
+   * @throws \API_Exception
+   */
+  public function testStoreMultiSelectInt(): void {
+    $contactID = $this->individualCreate();
+    $customGroup = $this->customGroupCreate();
+    $fields = [
+      'custom_group_id' => $customGroup['id'],
+      'data_type' => 'Int',
+      'html_type' => 'Multi-Select',
+      'option_values' => [
+        1 => 'choice1',
+        2 => 'choice2',
+      ],
+      'default_value' => '',
+    ];
+
+    $customField = $this->customFieldCreate($fields);
+
+    $params = [
+      [
+        $customField['id'] => [
+          'value' => CRM_Core_DAO::VALUE_SEPARATOR . '1' . CRM_Core_DAO::VALUE_SEPARATOR . '2' . CRM_Core_DAO::VALUE_SEPARATOR,
+          'type' => 'Int',
+          'custom_field_id' => $customField['id'],
+          'custom_group_id' => $customGroup['id'],
+          'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
+          'column_name' => $customField['values'][$customField['id']]['column_name'],
+          'file_id' => '',
+        ],
+      ],
+    ];
+
+    CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
 
-    $this->customFieldDelete($customField['id']);
-    $this->customGroupDelete($customGroup['id']);
-    $this->contactDelete($contactID);
+    $customData = \Civi\Api4\Contact::get(FALSE)
+      ->addSelect('new_custom_group.Custom_Field')
+      ->addWhere('id', '=', $contactID)
+      ->execute()->first();
+    $this->assertEquals([1, 2], $customData['new_custom_group.Custom_Field']);
   }
 
   /**
    * Test getEntityValues function for stored value.
    */
-  public function testGetEntityValues() {
-
+  public function testGetEntityValues(): void {
     $params = [];
     $contactID = $this->individualCreate();
     $customGroup = $this->customGroupCreate(['extends' => 'Individual']);
@@ -211,16 +239,12 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
 
     $entityValues = CRM_Core_BAO_CustomValueTable::getEntityValues($contactID, 'Individual');
 
-    $this->assertEquals($entityValues[$customField['id']], '<p><strong>This is a <u>test</u></p>',
+    $this->assertEquals('<p><strong>This is a <u>test</u></p>', $entityValues[$customField['id']],
       'Checking same for returned value.'
     );
-    $this->customFieldDelete($customField['id']);
-    $this->customGroupDelete($customGroup['id']);
-    $this->contactDelete($contactID);
   }
 
-  public function testCustomGroupMultiple() {
-    $params = [];
+  public function testCustomGroupMultiple(): void {
     $contactID = $this->individualCreate();
     $customGroup = $this->customGroupCreate();
 
@@ -246,10 +270,6 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
 
     $this->assertEquals($params['custom_' . $customField['id'] . '_-1'], $result['custom_' . $customField['id']]);
     $this->assertEquals($params['entityID'], $result['entityID']);
-
-    $this->customFieldDelete($customField['id']);
-    $this->customGroupDelete($customGroup['id']);
-    $this->contactDelete($contactID);
   }
 
 }