CRM-17984 test to demonstrate breakage
authorEileen <eileen@fuzion.co.nz>
Fri, 22 Apr 2016 06:10:44 +0000 (06:10 +0000)
committerEileen <eileen@fuzion.co.nz>
Fri, 22 Apr 2016 06:22:43 +0000 (06:22 +0000)
CRM/Core/BAO/CustomGroup.php
tests/phpunit/CRM/Core/BAO/CustomGroupTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
xml/schema/Contact/ContactType.xml

index e4caa8a689c51fffa7c0cbfb0ec4ef5ecdb2ee02..db057daea7fbe1726b4769df45b77864107d3ab3 100644 (file)
@@ -316,8 +316,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
    *
    * @param string $entityType
    *   Of the contact whose contact type is needed.
-   * @param CRM_Core_Form $form
-   *   Not used
+   * @param CRM_Core_Form $deprecated
+   *   Not used.
    * @param int $entityID
    * @param int $groupID
    * @param string $subType
@@ -343,9 +343,9 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
    *   The reason for the info array in unclear and it could be determined from parsing the group tree after creation
    *   With caching the performance impact would be small & the function would be cleaner
    */
-  public static function &getTree(
+  public static function getTree(
     $entityType,
-    $form = NULL,
+    $deprecated = NULL,
     $entityID = NULL,
     $groupID = NULL,
     $subType = NULL,
index d121ba5fdf6dc8f9ed420c0ba17285e218d3f517..ac6962f058d7372abed0acb8497fb2ed7a15a10e 100644 (file)
@@ -39,40 +39,48 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase {
    * Test getTree().
    */
   public function testGetTree() {
-    $params = array();
-    $contactId = Contact::createIndividual();
-    $customGrouptitle = 'My Custom Group';
-    $groupParams = array(
-      'title' => $customGrouptitle,
-      'name' => 'my_custom_group',
-      'style' => 'Tab',
-      'extends' => 'Individual',
-      'is_active' => 1,
-      'version' => 3,
-    );
-
-    $customGroup = Custom::createGroup($groupParams);
-
-    $customGroupId = $customGroup->id;
-
-    $fields = array(
-      'groupId' => $customGroupId,
-      'dataType' => 'String',
-      'htmlType' => 'Text',
-    );
-
-    $customField = Custom::createField($params, $fields);
-    $formParams = NULL;
-    $getTree = CRM_Core_BAO_CustomGroup::getTree('Individual', $formParams, $customGroupId);
+    $customGroup = $this->CustomGroupCreate();
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+    $result = CRM_Core_BAO_CustomGroup::getTree('Individual', NULL, $customGroup['id']);
+    $this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']);
+    $this->customGroupDelete($customGroup['id']);
+  }
 
-    $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
-      'Database check for custom group record.'
-    );
+  /**
+   * 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 testGetTreeContactSubType() {
+    $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'parent_id' => 'Organization'));
+    $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big Bank')));
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+    $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big Bank'));
+    $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
+    $result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'Big Bank' . CRM_Core_DAO::VALUE_SEPARATOR);
+    $this->assertEquals($result1, $result);
+    $result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, 'Big Bank');
+    $this->assertEquals($result1, $result);
+    try {
+      CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Small Kind Bank'));
+    }
+    catch (CRM_Core_Exception $e) {
+      $this->customGroupDelete($customGroup['id']);
+      return;
+    }
+    $this->fail('There is no such thing as a small kind bank');
+  }
 
-    Custom::deleteField($customField);
-    Custom::deleteGroup($customGroup);
-    Contact::delete($contactId);
-    $customGroup->free();
+  /**
+   * Test calling getTree with contact subtype data.
+   */
+  public function testGetTreeActivitySubType() {
+    $customGroup = $this->CustomGroupCreate(array('extends' => 'Activity', 'extends_entity_column_value' => 1));
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+    $result = CRM_Core_BAO_CustomGroup::getTree('Activity', NULL, NULL, NULL, 1);
+    $this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']);
+    $this->customGroupDelete($customGroup['id']);
   }
 
   /**
index 8e87f506aa3191bb71e50fc5b1fd6c5efa404404..1c5cf67e1cdb6e9ec05ce0d3a455c2e4359df3bd 100644 (file)
@@ -2005,7 +2005,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * Create custom group.
    *
    * @param array $params
-   * @return array|int
+   * @return array
    */
   public function customGroupCreate($params = array()) {
     $defaults = array(
index f5b98b40bffcda00a209514833424cced69f6ed4..8a701d53e032fc1af454ec918318895b7f237c76 100644 (file)
     <title>Contact Type Parent</title>
     <type>int unsigned</type>
     <comment>Optional FK to parent contact type.</comment>
+    <pseudoconstant>
+      <table>civicrm_contact_type</table>
+      <keyColumn>id</keyColumn>
+      <labelColumn>label</labelColumn>
+      <condition>parent_id IS NULL</condition>
+    </pseudoconstant>
     <add>3.1</add>
   </field>
   <foreignKey>