CRM-18469, CRM-17984 - getTree regression on multiple integers separated by the cnrtl...
authoreileenmcnaugton <eileen@fuzion.co.nz>
Wed, 27 Apr 2016 07:37:02 +0000 (19:37 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 27 Apr 2016 08:21:05 +0000 (20:21 +1200)
CRM/Core/BAO/CustomGroup.php
tests/phpunit/CRM/Core/BAO/CustomGroupTest.php

index d56c7ed18bdda7608aab7b81fc4d49c2ed831c95..837bde7f1b4f22edc8337eece0bd04983b8b8d94 100644 (file)
@@ -363,7 +363,12 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
         $subTypes = array();
       }
       else {
-        $subTypes = explode(',', $subTypes);
+        if (stristr(',', $subTypes)) {
+          $subTypes = explode(',', $subTypes);
+        }
+        else {
+          $subTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($subTypes, CRM_Core_DAO::VALUE_SEPARATOR));
+        }
       }
     }
 
index ac6962f058d7372abed0acb8497fb2ed7a15a10e..3d35f44251844e640011b9d7f5fb079a18701bee 100644 (file)
@@ -72,6 +72,25 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase {
     $this->fail('There is no such thing as a small kind bank');
   }
 
+  /**
+   * Test calling getTree with contact subtype data.
+   *
+   * Note that the function seems to support a range of formats so 3 are tested. Yay for
+   * inconsistency.
+   */
+  public function testGetTreeCampaignSubType() {
+    $this->campaignCreate();
+    $this->campaignCreate();
+    $customGroup = $this->CustomGroupCreate(array(
+      'extends' => 'Campaign',
+      'extends_entity_column_value' => '\ 11\ 12\ 1'
+    ));
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+    $result1 = CRM_Core_BAO_CustomGroup::getTree('Campaign', NULL, NULL, NULL, '\ 11\ 12\ 1');
+    $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
+    $this->customGroupDelete($customGroup['id']);
+  }
+
   /**
    * Test calling getTree with contact subtype data.
    */
@@ -84,7 +103,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test retrieve() with Empty Params
+   * Test retrieve() with Empty Params.
    */
   public function testRetrieveEmptyParams() {
     $params = array();