'name' => 'default_goat_priceset', 'title' => 'Goat accomodation', 'is_active' => 1, 'help_pre' => "Where does your goat sleep", 'help_post' => "thank you for your time", 'extends' => 2, 'financial_type_id' => 1, 'is_quick_config' => 1, 'is_reserved' => 1, ]; $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams); $this->priceSetID = $price_set['id']; $this->_params = [ 'price_set_id' => $this->priceSetID, 'name' => 'grassvariety', 'label' => 'Grass Variety', 'html_type' => 'Text', 'is_enter_qty' => 1, 'is_active' => 1, ]; } public function tearDown() { $tablesToTruncate = [ 'civicrm_contact', 'civicrm_contribution', ]; $this->quickCleanup($tablesToTruncate); $delete = $this->callAPISuccess('PriceSet', 'delete', [ 'id' => $this->priceSetID, ]); $this->assertAPISuccess($delete); parent::tearDown(); } public function testCreatePriceField() { $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); $this->getAndCheck($this->_params, $result['id'], $this->_entity); } public function testGetBasicPriceField() { $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); $this->id = $createResult['id']; $this->assertAPISuccess($createResult); $getParams = [ 'name' => 'contribution_amount', ]; $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $getResult['count']); $this->callAPISuccess('price_field', 'delete', ['id' => $createResult['id']]); } public function testDeletePriceField() { $startCount = $this->callAPISuccess($this->_entity, 'getcount', []); $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); $deleteParams = ['id' => $createResult['id']]; $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); $this->assertAPISuccess($deleteResult); $endCount = $this->callAPISuccess($this->_entity, 'getcount', []); $this->assertEquals($startCount, $endCount); } public function testGetFieldsPriceField() { $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); $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', [ 'price_field_id' => $field['id'], 'name' => 'rye grass', 'label' => 'juicy and healthy', 'amount' => 1, 'financial_type_id' => 1, ]); $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']); $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]); $this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']); $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]); $this->callAPISuccess($this->_entity, 'delete', ['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, ['html_type' => 'Radio'])); $this->callAPISuccess('price_field_value', 'create', [ 'price_field_id' => $field['id'], 'name' => 'rye grass', 'label' => 'juicy and healthy', 'amount' => 1, 'financial_type_id' => 1, ]); $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']); $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]); $this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']); $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]); $this->callAPISuccess($this->_entity, 'delete', ['id' => $field['id']]); } }