CRM-17984 test to demonstrate breakage
authorEileen <eileen@fuzion.co.nz>
Fri, 22 Apr 2016 06:10:44 +0000 (06:10 +0000)
committereileenmcnaugton <eileen@fuzion.co.nz>
Sun, 24 Apr 2016 02:14:43 +0000 (14:14 +1200)
Conflicts:
CRM/Core/BAO/CustomGroup.php

CRM/Core/BAO/CustomGroup.php
tests/phpunit/CRM/Core/BAO/CustomGroupTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
xml/schema/Contact/ContactType.xml

index de550b0fd55508653cf506bfd1f65c9df1054e0e..e5a5f336a616d1cc0d30474dc586e6440035502d 100644 (file)
@@ -312,8 +312,9 @@ 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 but required.
+
+   * @param CRM_Core_Form $deprecated
+   *   Not used.
    * @param int $entityID
    * @param int $groupID
    * @param string $subType
@@ -330,11 +331,10 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
    * @todo - review this  - It also returns an array called 'info' with tables, select, from, where keys
    *   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,
+    $deprecated = NULL,
     $entityID = NULL,
     $groupID = NULL,
     $subType = NULL,
index d3b6356740c3356fb3e91123b2ae2c5f1e3a5860..f37ec2ff73847c98b9dbc88512b2330b1adcf8e2 100644 (file)
@@ -43,40 +43,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 e62a05109b63b13fa870948fe47546df9084fe59..8289b4bf72f3bbdd85ca8c906283a3328ee94a93 100755 (executable)
@@ -2157,7 +2157,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>