From: Eileen Date: Fri, 22 Apr 2016 06:10:44 +0000 (+0000) Subject: CRM-17984 test to demonstrate breakage X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=27dd62528f5f16e856760db948bbe90bd6240f8c;p=civicrm-core.git CRM-17984 test to demonstrate breakage --- diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index e4caa8a689..db057daea7 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -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, diff --git a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php index d121ba5fdf..ac6962f058 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php @@ -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']); } /** diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 8e87f506aa..1c5cf67e1c 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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( diff --git a/xml/schema/Contact/ContactType.xml b/xml/schema/Contact/ContactType.xml index f5b98b40bf..8a701d53e0 100644 --- a/xml/schema/Contact/ContactType.xml +++ b/xml/schema/Contact/ContactType.xml @@ -66,6 +66,12 @@ Contact Type Parent int unsigned Optional FK to parent contact type. + + civicrm_contact_type
+ id + label + parent_id IS NULL +
3.1