public function testCustomGroupMultipleOldFormate() { $params = array(); $contactID = Contact::createIndividual(); $customGroup = Custom::createGroup($params, 'Individual', TRUE); $fields = array('groupId' => $customGroup->id, 'dataType' => 'String', 'htmlType' => 'Text'); $customField = Custom::createField($params, $fields); $params = array('entityID' => $contactID, "custom_{$customField->id}" => 'First String'); $error = CRM_Core_BAO_CustomValueTable::setValues($params); $newParams = array('entityID' => $contactID, "custom_{$customField->id}" => 1); $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); $this->assertEquals($params["custom_{$customField->id}"], $result["custom_{$customField->id}_1"]); $this->assertEquals($params['entityID'], $result['entityID']); Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactID); }
/** * Create() method with custom data. */ public function testCreateWithCustomData() { $contactId = Contact::createIndividual(); $ids = array('contribution' => NULL); //create custom data $customGroup = Custom::createGroup(array(), 'Contribution'); $fields = array('label' => 'testFld', 'data_type' => 'String', 'html_type' => 'Text', 'is_active' => 1, 'custom_group_id' => $customGroup->id); $customField = CRM_Core_BAO_CustomField::create($fields); $params = array('contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, 'contribution_status_id' => 1, 'payment_instrument_id' => 1, 'source' => 'STUDENT', 'receive_date' => '20080522000000', 'receipt_date' => '20080522000000', 'id' => NULL, 'non_deductible_amount' => 0.0, 'total_amount' => 200.0, 'fee_amount' => 5, 'net_amount' => 195, 'trxn_id' => '22ereerwww322323', 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', 'thankyou_date' => '20080522'); $params['custom'] = array($customField->id => array(-1 => array('value' => 'Test custom value', 'type' => 'String', 'custom_field_id' => $customField->id, 'custom_group_id' => $customGroup->id, 'table_name' => $customGroup->table_name, 'column_name' => $customField->column_name, 'file_id' => NULL))); $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids); // Check that the custom field value is saved $customValueParams = array('entityID' => $contribution->id, 'custom_' . $customField->id => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($customValueParams); $this->assertEquals('Test custom value', $values['custom_' . $customField->id], 'Check the custom field value'); $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.'); $this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id for Conribution.'); $this->contributionDelete($contribution->id); Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactId); }
public function testFixFieldValueOfTypeMemo() { $customGroup = Custom::createGroup(array(), 'Individual'); $fields = array('groupId' => $customGroup->id, 'dataType' => 'Memo', 'htmlType' => 'TextArea'); $customField = Custom::createField(array(), $fields); $custom = 'custom_' . $customField->id; $params = array(); $params = array('email' => '*****@*****.**', $custom => 'note'); CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($params); $this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.'); Custom::deleteField($customField); Custom::deleteGroup($customGroup); }
/** * Function to test checkCustomField() */ function testCheckCustomField() { $customGroupTitle = 'My Custom Group'; $groupParams = array('title' => $customGroupTitle, 'name' => 'my_custom_group', 'extends' => 'Individual', 'help_pre' => 'Custom Group Help Pre', 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1); $customGroup = Custom::createGroup($groupParams); $customGroupId = $customGroup->id; $customFieldLabel = 'Test Custom Field'; $fieldParams = array('custom_group_id' => $customGroupId, 'label' => $customFieldLabel, 'html_type' => 'Text', 'data_type' => 'String', 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1); $customField = Custom::createField($fieldParams); $customFieldId = $customField->id; //check db for custom group $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.'); $this->assertEquals($customGroupTitle, $dbCustomGroupTitle); //check db for custom field $dbCustomFieldLabel = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldId, 'label', 'id', 'Database check for custom field record.'); $this->assertEquals($customFieldLabel, $dbCustomFieldLabel); //check the custom field type. $params = array('Individual'); require_once 'CRM/Core/BAO/CustomGroup.php'; $usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params); $this->assertEquals(false, $usedFor); $params = array('Contribution', 'Membership', 'Participant'); $usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params); $this->assertEquals(true, $usedFor); //cleanup DB by deleting customGroup Custom::deleteField($customField); Custom::deleteGroup($customGroup); }
/** * Test setValues() and getValues() methods with custom field YesNo(Boolean) Radio */ public function testSetGetValuesYesNoRadio() { $params = array(); $contactID = Contact::createIndividual(); //create Custom Group $customGroup = Custom::createGroup($params, 'Individual', TRUE); //create Custom Field of type YesNo(Boolean) Radio $fields = array('groupId' => $customGroup->id, 'dataType' => 'Boolean', 'htmlType' => 'Radio'); $customField = Custom::createField($params, $fields); // Retrieve the field ID for sample custom field 'test_Boolean' $params = array('label' => 'test_Boolean'); $field = array(); //get field Id CRM_Core_BAO_CustomField::retrieve($params, $field); $fieldID = $field['id']; // valid boolean value '1' for Boolean Radio $yesNo = '1'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $yesNo); $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the YesNo radio value is stored $values = array(); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); $this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the boolean value is stored for contact ' . $contactID); // Now set YesNo radio to an invalid boolean value and try to reset $badYesNo = '20'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $badYesNo); $errorScope = CRM_Core_TemporaryErrorScope::useException(); $message = NULL; try { $result = CRM_Core_BAO_CustomValueTable::setValues($params); } catch (Exception $e) { $message = $e->getMessage(); } $errorScope = NULL; // Check that an exception has been thrown $this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed'); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the date value has NOT been updated for contact ' . $contactID); // Cleanup Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactID); }
function testSetGetValuesYesNoRadio() { $params = array(); $contactID = Contact::createIndividual(); //create Custom Group $customGroup = Custom::createGroup($params, 'Individual', true); //create Custom Field of type YesNo(Boolean) Radio $fields = array('groupId' => $customGroup->id, 'dataType' => 'Boolean', 'htmlType' => 'Radio'); $customField = Custom::createField($params, $fields); // Retrieve the field ID for sample custom field 'test_Boolean' $params = array('label' => 'test_Boolean'); $field = array(); //get field Id require_once 'CRM/Core/BAO/CustomField.php'; CRM_Core_BAO_CustomField::retrieve($params, $field); $fieldID = $field['id']; // valid boolean value '1' for Boolean Radio $yesNo = '1'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $yesNo); require_once 'CRM/Core/BAO/CustomValueTable.php'; $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the YesNo radio value is stored $values = array(); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); $this->assertEquals($values['custom_1_1'], $yesNo, 'Verify that the date value is stored for contact ' . $contactID); // Now set YesNo radio to an invalid boolean value and try to reset $badYesNo = '20'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $badYesNo); require_once 'CRM/Core/BAO/CustomValueTable.php'; $result = CRM_Core_BAO_CustomValueTable::setValues($params); // Check that the error flag is set AND that custom date value has not been modified $this->assertEquals($result['is_error'], $yesNo, 'Verify that is_error = 1 when bad boolen value is passed.'); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['custom_1_1'], $yesNo, 'Verify that the date value has NOT been updated for contact ' . $contactID); // Cleanup Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactID); }