public function setUp() { parent::setUp(); /** @var $hooks \CRM_Utils_Hook_UnitTests */ $hooks = \CRM_Utils_Hook::singleton(); $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes')); \CRM_Case_XMLRepository::singleton(TRUE); \CRM_Case_XMLProcessor::flushStaticCaches(); // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types //. Using XML was causing breakage as id numbers were changing over time // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a // state where tests could run afterwards without re-loading. $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_status', 'format.only_id' => 1)); $optionValues = array('Medical evaluation' => 'Medical evaluation', 'Mental health evaluation' => "Mental health evaluation", 'Secure temporary housing' => 'Secure temporary housing', 'Long-term housing plan' => 'Long-term housing plan', 'ADC referral' => 'ADC referral', 'Income and benefits stabilization' => 'Income and benefits stabilization'); foreach ($optionValues as $name => $label) { $activityTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => 2, 'name' => $name, 'label' => $label, 'component_id' => 7)); // store for cleanup $this->optionValues[] = $activityTypes['id']; } // We used to be inconsistent about "HousingSupport" vs "housing_support". // Now, the rule is simply: use the "name" from "civicrm_case_type.name". $this->caseType = 'housing_support'; $this->caseTypeId = 1; $this->tablesToTruncate = array('civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_case', 'civicrm_case_contact', 'civicrm_case_activity', 'civicrm_case_type', 'civicrm_activity_contact', 'civicrm_managed', 'civicrm_relationship', 'civicrm_relationship_type'); $this->quickCleanup($this->tablesToTruncate); $this->loadAllFixtures(); // enable the default custom templates for the case type xml files $this->customDirectories(array('template_path' => TRUE)); // case is not enabled by default $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__); // create a logged in USER since the code references it for source_contact_id $this->createLoggedInUser(); $session = CRM_Core_Session::singleton(); $this->_loggedInUser = $session->get('userID'); /// note that activityType options are cached by the FULL set of options you pass in // ie. because Activity api includes campaign in it's call cache is not flushed unless // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE); }
/** * Add the relationship type in the db. * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $ids * The array that holds all the db ids. * * @return CRM_Contact_DAO_RelationshipType */ public static function add(&$params, &$ids) { //to change name, CRM-3336 if (empty($params['label_a_b']) && !empty($params['name_a_b'])) { $params['label_a_b'] = $params['name_a_b']; } if (empty($params['label_b_a']) && !empty($params['name_b_a'])) { $params['label_b_a'] = $params['name_b_a']; } // set label to name if it's not set - but *only* for // ADD action. CRM-3336 as part from (CRM-3522) if (empty($ids['relationshipType'])) { if (empty($params['name_a_b']) && !empty($params['label_a_b'])) { $params['name_a_b'] = $params['label_a_b']; } if (empty($params['name_b_a']) && !empty($params['label_b_a'])) { $params['name_b_a'] = $params['label_b_a']; } } // action is taken depending upon the mode $relationshipType = new CRM_Contact_DAO_RelationshipType(); $relationshipType->copyValues($params); // if label B to A is blank, insert the value label A to B for it if (!strlen(trim($strName = CRM_Utils_Array::value('name_b_a', $params)))) { $relationshipType->name_b_a = CRM_Utils_Array::value('name_a_b', $params); } if (!strlen(trim($strName = CRM_Utils_Array::value('label_b_a', $params)))) { $relationshipType->label_b_a = CRM_Utils_Array::value('label_a_b', $params); } $relationshipType->id = CRM_Utils_Array::value('relationshipType', $ids); $result = $relationshipType->save(); CRM_Core_PseudoConstant::relationshipType('label', TRUE); CRM_Core_PseudoConstant::relationshipType('name', TRUE); CRM_Case_XMLProcessor::flushStaticCaches(); return $result; }