Skip to content

Commit

Permalink
CRM-19741 Add back in fix and add in unit tests to lock in fix
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed Apr 6, 2017
1 parent 4e48646 commit c61962a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
10 changes: 8 additions & 2 deletions CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,21 @@ public static function create(&$params) {
}
$optionsIds = array();
$maxIndex = CRM_Price_Form_Field::NUM_OPTION;
$priceField2 = civicrm_api3('price_field', 'getsingle', array('id' => $priceField->id));
if ($priceField2['html_type'] == 'Text') {
if ($priceField->html_type == 'Text') {
$maxIndex = 1;
$fieldOptions = civicrm_api3('price_field_value', 'get', array(
'price_field_id' => $priceField->id,
'sequential' => 1,
));
foreach ($fieldOptions['values'] as $option) {
$optionsIds['id'] = $option['id'];
// CRM-19741 If we are dealing with price fields that are Text only set the field value label to match
if (!empty($params['id']) && $priceField->label != $option['label']) {
$fieldValue = new CRM_Price_DAO_PriceFieldValue();
$fieldValue->label = $priceField->label;
$fieldValue->id = $option['id'];
$fieldValue->save();
}
}
}
$defaultArray = array();
Expand Down
40 changes: 40 additions & 0 deletions tests/phpunit/api/v3/PriceFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,44 @@ public function testGetFieldsPriceField() {
$this->assertEquals(1, $result['values']['options_per_line']['type']);
}

/**
* CRM-19741
* Test updating the label of a texte price field and ensure price field value label is also updated
*/
public function testUpdatePriceFieldLabel() {
$field = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$this->callAPISuccess('price_field_value', 'create', array(
'price_field_id' => $field['id'],
'name' => 'rye grass',
'label' => 'juicy and healthy',
'amount' => 1,
'financial_type_id' => 1,
));
$priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety'));
$priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id']));
$this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']);
$this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id']));
$this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id']));
}

/**
* CRM-19741
* Confirm value label only updates if fiedl type is html.
*/
public function testUpdatePriceFieldLabelNotUpdateField() {
$field = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array('html_type' => 'Radio')));
$this->callAPISuccess('price_field_value', 'create', array(
'price_field_id' => $field['id'],
'name' => 'rye grass',
'label' => 'juicy and healthy',
'amount' => 1,
'financial_type_id' => 1,
));
$priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety'));
$priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id']));
$this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']);
$this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id']));
$this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id']));
}

}

0 comments on commit c61962a

Please sign in to comment.