Exemplo n.º 1
0
 public function testCreateCustomValue()
 {
     $this->_populateOptionAndCustomGroup();
     $customFieldDataType = CRM_Core_BAO_CustomField::dataType();
     $dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml();
     $count = 0;
     foreach ($customFieldDataType as $dataType => $label) {
         switch ($dataType) {
             case 'Country':
             case 'StateProvince':
                 $this->foreignKeyChecksOff();
             case 'String':
             case 'Link':
             case 'Int':
             case 'Float':
             case 'Money':
             case 'Date':
             case 'Boolean':
                 //Based on the custom field data-type choose desired SQL operators(to test with) and basic $type
                 if (in_array($dataType, array('String', 'Link'))) {
                     $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL');
                     $type = 'string';
                 } elseif ($dataType == 'Boolean') {
                     $validSQLOperators = array('=', '!=', 'IS NOT NULL', 'IS NULL');
                     $type = 'boolean';
                 } else {
                     if ($dataType == 'Country') {
                         $type = 'country';
                     } elseif ($dataType == 'StateProvince') {
                         $type = 'state_province';
                     } elseif ($dataType == 'ContactReference') {
                         $type = 'contact';
                     } elseif ($dataType == 'Date') {
                         $type = 'date';
                     } else {
                         $type = $dataType == 'Int' ? 'integer' : 'number';
                     }
                     $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL');
                 }
                 //Create custom field of $dataType and html-type $html
                 foreach ($dataToHtmlTypes[$count] as $html) {
                     $params = array('custom_group_id' => $this->ids[$type]['custom_group_id'], 'label' => "{$dataType} - {$html}", 'data_type' => $dataType, 'html_type' => $html, 'default_value' => NULL);
                     if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference', 'Boolean'))) {
                         $params += array('option_group_id' => $this->optionGroup[$type]['id']);
                     }
                     $customField = $this->customFieldCreate($params);
                     //Now test with $validSQLOperator SQL operators against its custom value(s)
                     $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperators, $type);
                 }
                 $count++;
                 break;
             default:
                 // skipping File data-type
                 $count++;
                 break;
         }
     }
 }
 public function testCreateCustomValue()
 {
     $customFieldDataType = CRM_Core_BAO_CustomField::dataType();
     $dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml();
     $count = 0;
     foreach ($customFieldDataType as $dataType => $label) {
         switch ($dataType) {
             case 'Date':
             case 'StateProvince':
             case 'String':
             case 'Link':
             case 'Int':
             case 'Float':
             case 'Money':
                 if (in_array($dataType, array('String', 'Link'))) {
                     $validSQLOperator = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL');
                     $type = 'string';
                 } else {
                     if ($dataType == 'Country') {
                         $type == 'country';
                     } elseif ($dataType == 'StateProvince') {
                         $type = 'state_province';
                     } elseif ($dataType == 'ContactReference') {
                         $type = 'contact';
                     } elseif ($dataType == 'Date') {
                         $type = 'date';
                     } else {
                         $type = $dataType == 'Int' ? 'integer' : 'number';
                     }
                     $validSQLOperator = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL');
                 }
                 foreach ($dataToHtmlTypes[$count] as $html) {
                     $params = array('custom_group_id' => $this->ids[$type]['custom_group_id'], 'label' => "{$dataType} - {$html}", 'data_type' => $dataType, 'html_type' => $html, 'default_value' => NULL);
                     if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference'))) {
                         $params += array('option_group_id' => $this->optionGroup[$type]['id']);
                     }
                     $customField = $this->customFieldCreate($params);
                     $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperator, $type);
                 }
                 $count++;
                 break;
             default:
                 //TODO: Test case of Country fields remain as it throws foreign key contraint ONLY in test environment
                 $count++;
                 break;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Function to set variables up before form is built
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     if (!self::$_dataTypeKeys) {
         self::$_dataTypeKeys = array_keys(CRM_Core_BAO_CustomField::dataType());
         self::$_dataTypeValues = array_values(CRM_Core_BAO_CustomField::dataType());
     }
     if (!self::$_dataToHTML) {
         self::$_dataToHTML = CRM_Core_BAO_CustomField::dataToHtml();
     }
     //custom group id
     $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
     if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
         CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set.");
     }
     if ($this->_gid) {
         $url = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}");
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext($url);
     }
     //custom field id
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     //get the values form db if update.
     $this->_values = array();
     if ($this->_id) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_CustomField::retrieve($params, $this->_values);
         // note_length is an alias for the text_length field
         $this->_values['note_length'] = CRM_Utils_Array::value('text_length', $this->_values);
     }
     if (self::$_dataToLabels == NULL) {
         self::$_dataToLabels = array(array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio'), 'CheckBox' => ts('CheckBox'), 'Multi-Select' => ts('Multi-Select'), 'AdvMulti-Select' => ts('Advanced Multi-Select'), 'Autocomplete-Select' => ts('Autocomplete Select')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('TextArea' => ts('TextArea'), 'RichTextEditor' => 'RichTextEditor'), array('Date' => ts('Select Date')), array('Radio' => ts('Radio')), array('StateProvince' => ts('Select State/Province'), 'Multi-Select' => ts('Multi-Select State/Province')), array('Country' => ts('Select Country'), 'Multi-Select' => ts('Multi-Select Country ')), array('File' => ts('Select File')), array('Link' => ts('Link')), array('ContactReference' => ts('Autocomplete Select')));
     }
 }
Exemplo n.º 4
0
 /**
  * Check for Each data type: loop through available form input types
  */
 public function testCustomFieldCreateAllAvailableFormInputs()
 {
     $gid = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'testAllFormInputs'));
     $dtype = CRM_Core_BAO_CustomField::dataType();
     $htype = CRM_Core_BAO_CustomField::dataToHtml();
     $n = 0;
     foreach ($dtype as $dkey => $dvalue) {
         foreach ($htype[$n] as $hkey => $hvalue) {
             //echo $dkey."][".$hvalue."\n";
             $this->_loopingCustomFieldCreateTest($this->_buildParams($gid['id'], $hvalue, $dkey));
         }
         $n++;
     }
 }
Exemplo n.º 5
0
 public function testCreateCustomValue()
 {
     $this->_populateOptionAndCustomGroup();
     $customFieldDataType = CRM_Core_BAO_CustomField::dataType();
     $dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml();
     $count = 0;
     $optionSupportingHTMLTypes = array('Select', 'Radio', 'CheckBox', 'AdvMulti-Select', 'Autocomplete-Select', 'Multi-Select');
     foreach ($customFieldDataType as $dataType => $label) {
         switch ($dataType) {
             // case 'Country':
             // case 'StateProvince':
             case 'String':
             case 'Link':
             case 'Int':
             case 'Float':
             case 'Money':
             case 'Date':
             case 'Boolean':
                 //Based on the custom field data-type choose desired SQL operators(to test with) and basic $type
                 if (in_array($dataType, array('String', 'Link'))) {
                     $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL');
                     $type = 'string';
                 } elseif ($dataType == 'Boolean') {
                     $validSQLOperators = array('=', '!=', 'IS NOT NULL', 'IS NULL');
                     $type = 'boolean';
                 } else {
                     if ($dataType == 'Country') {
                         $type = 'country';
                     } elseif ($dataType == 'StateProvince') {
                         $type = 'state_province';
                     } elseif ($dataType == 'ContactReference') {
                         $type = 'contact';
                     } elseif ($dataType == 'Date') {
                         $type = 'date';
                     } else {
                         $type = $dataType == 'Int' ? 'integer' : 'number';
                     }
                     $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL');
                 }
                 //Create custom field of $dataType and html-type $html
                 foreach ($dataToHtmlTypes[$count] as $html) {
                     // per CRM-18568 the like operator does not currently work for fields with options.
                     // the LIKE operator could potentially bypass ACLs (as could IS NOT NULL) and some thought needs to be given
                     // to it.
                     if (in_array($html, $optionSupportingHTMLTypes)) {
                         $validSQLOperators = array_diff($validSQLOperators, array('LIKE', 'NOT LIKE'));
                     }
                     $params = array('custom_group_id' => $this->ids[$type]['custom_group_id'], 'label' => "{$dataType} - {$html}", 'data_type' => $dataType, 'html_type' => $html, 'default_value' => NULL);
                     if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference', 'Boolean'))) {
                         $params += array('option_group_id' => $this->optionGroup[$type]['id']);
                     }
                     $customField = $this->customFieldCreate($params);
                     //Now test with $validSQLOperator SQL operators against its custom value(s)
                     $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperators, $type);
                 }
                 $count++;
                 break;
             default:
                 // skipping File data-type & state province due to caching issues
                 $count++;
                 break;
         }
     }
 }