Merge pull request #11086 from agileware/CRM-21277
[civicrm-core.git] / tests / phpunit / api / v3 / PriceFieldTest.php
index a1b05f4303c01b0a16f9c4afb3dfc492c813a951..65d47a0bb89538e796186304261e63f1c47761d8 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
 | CiviCRM version 4.7                                                |
 +--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2016                                |
+| Copyright CiviCRM LLC (c) 2004-2018                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
@@ -115,4 +115,44 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase {
     $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']));
+  }
+
 }