From: eileen Date: Wed, 20 May 2020 02:58:52 +0000 (+1200) Subject: Fix pricefield pseudoconstant. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4f238b49c5a1e43adbc136b8cfd7321716e752ed;p=civicrm-core.git Fix pricefield pseudoconstant. The price field turns out not to be returning pseudoconstant fields for 2 reasons 1) the label field is defined but the name field is not 2) any price fields with no domain are filtered out. In my single domain db this is all of them. I think we can safely understand NULL domain_id as 'not restricted by domain'. For some tables (membershipType) it is a required field but for PriceField it is not. I would be inclined to say it should be required less often. However, where it is required thenn the OR IS NULL should never be true --- diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 911189b5e1..e158ee21f0 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -1527,7 +1527,7 @@ WHERE id = %1 } // Filter domain specific options if (in_array('domain_id', $availableFields)) { - $wheres[] = 'domain_id = ' . CRM_Core_Config::domainID(); + $wheres[] = 'domain_id = ' . CRM_Core_Config::domainID() . ' OR domain_id is NULL'; } $queryParams = [ 1 => [$params['keyColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES], diff --git a/CRM/Price/BAO/PriceField.php b/CRM/Price/BAO/PriceField.php index 8f7cc8e1b5..f48cd14e83 100644 --- a/CRM/Price/BAO/PriceField.php +++ b/CRM/Price/BAO/PriceField.php @@ -9,14 +9,6 @@ +--------------------------------------------------------------------+ */ -/** - * - * @package CRM - * @copyright CiviCRM LLC https://civicrm.org/licensing - * $Id$ - * - */ - /** * Business objects for managing price fields. * diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 7983cc531b..732aa5dd8e 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -71,6 +71,7 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { $priceSetBAO->save(); CRM_Utils_Hook::post($hook, 'PriceSet', $priceSetBAO->id, $priceSetBAO); + unset(\Civi::$statics['CRM_Core_PseudoConstant']); return $priceSetBAO; } @@ -1171,6 +1172,7 @@ WHERE id = %1"; $copy->save(); CRM_Utils_Hook::copy('Set', $copy); + unset(\Civi::$statics['CRM_Core_PseudoConstant']); return $copy; } diff --git a/CRM/Price/DAO/PriceField.php b/CRM/Price/DAO/PriceField.php index 56dc69ac28..987ae6614f 100644 --- a/CRM/Price/DAO/PriceField.php +++ b/CRM/Price/DAO/PriceField.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Price/PriceField.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:88307b88d5be27887068a778e663b0a2) + * (GenCodeChecksum:691cc70f15386dd0c2cd4ab63f9798af) */ /** @@ -204,6 +204,7 @@ class CRM_Price_DAO_PriceField extends CRM_Core_DAO { 'table' => 'civicrm_price_set', 'keyColumn' => 'id', 'labelColumn' => 'title', + 'nameColumn' => 'name', ], ], 'name' => [ diff --git a/api/v3/Generic.php b/api/v3/Generic.php index d8f2e92db4..0eef89a7a2 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -406,6 +406,7 @@ function civicrm_api3_generic_replace($apiRequest) { * * @return array * Array of results + * @throws \CiviCRM_API3_Exception */ function civicrm_api3_generic_getoptions($apiRequest) { // Resolve aliases. diff --git a/tests/phpunit/CRM/Price/BAO/PriceFieldTest.php b/tests/phpunit/CRM/Price/BAO/PriceFieldTest.php index 7d3c7a7faa..e6374edc71 100644 --- a/tests/phpunit/CRM/Price/BAO/PriceFieldTest.php +++ b/tests/phpunit/CRM/Price/BAO/PriceFieldTest.php @@ -15,26 +15,15 @@ */ class CRM_Price_BAO_PriceFieldTest extends CiviUnitTestCase { - /** - * Sets up the fixtures. - */ - protected function setUp() { - parent::setUp(); - } - - /** - * Tears down the fixture. - */ - protected function tearDown() { - } - /** * Test that when re-submitting the price field values with the option ids added * in the format that the contribution page / event page configuration screen * does it it doesn't duplicate the options + * + * @throws \CRM_Core_Exception */ public function testSubmitPriceFieldWithOptions() { - $this->priceSet = civicrm_api3('PriceSet', 'create', [ + $priceSet = $this->callAPISuccess('PriceSet', 'create', [ 'is_active' => 1, 'extends' => 2, 'is_quick_config' => 1, @@ -42,7 +31,7 @@ class CRM_Price_BAO_PriceFieldTest extends CiviUnitTestCase { 'name' => 'test_price_set', 'title' => 'Test Price Set', ]); - $this->priceFieldParams = [ + $priceFieldParams = [ 'name' => 'contribution_amount', 'is_active' => 1, 'weight' => 2, @@ -66,11 +55,11 @@ class CRM_Price_BAO_PriceFieldTest extends CiviUnitTestCase { 3 => 3, ], 'default_option' => 2, - 'price_set_id' => $this->priceSet['id'], + 'price_set_id' => $priceSet['id'], ]; - $this->priceField = civicrm_api3('PriceField', 'create', $this->priceFieldParams); - $this->priceFieldParams['id'] = $this->priceField['id']; - $fieldOptions = civicrm_api3('PriceFieldValue', 'get', ['price_field_id' => $this->priceField['id']]); + $priceField = $this->callAPISuccess('PriceField', 'create', $priceFieldParams); + $priceFieldParams['id'] = $priceField['id']; + $fieldOptions = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField['id']]); foreach ($fieldOptions['values'] as $fieldOption) { if ($fieldOption['amount'] < 20) { $key = 1; @@ -81,11 +70,18 @@ class CRM_Price_BAO_PriceFieldTest extends CiviUnitTestCase { else { $key = 3; } - $this->priceFieldParams['option_id'][$key] = $fieldOption['id']; + $priceFieldParams['option_id'][$key] = $fieldOption['id']; } - $this->priceFieldParams['default_option'] = 3; - $options = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $this->priceField['id']]); + $priceFieldParams['default_option'] = 3; + $options = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField['id']]); $this->assertEquals(3, $options['count']); } + /** + * Test the name can be retrieved from the id using the pseudoConstant. + */ + public function testGetFromPseudoConstant() { + $this->assertNotEmpty(CRM_Core_PseudoConstant::getKey('CRM_Price_BAO_PriceField', 'price_set_id', 'default_contribution_amount')); + } + } diff --git a/tests/phpunit/CRM/Price/BAO/PriceSetTest.php b/tests/phpunit/CRM/Price/BAO/PriceSetTest.php index d6d9265fb4..1c311ed327 100644 --- a/tests/phpunit/CRM/Price/BAO/PriceSetTest.php +++ b/tests/phpunit/CRM/Price/BAO/PriceSetTest.php @@ -33,6 +33,8 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { * * (these are denoted as 'quickConfig' in the code - but quickConfig is only supposed to refer to the * configuration interface - there should be no different post process. + * + * @throws \CRM_Core_Exception */ public function testGetAmountLevelTextAmount() { $priceSetID = $this->eventPriceSetCreate(9); @@ -49,6 +51,8 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { /** * CRM-20237 Test that Copied price set does not generate long name and unneded information + * + * @throws \CRM_Core_Exception */ public function testCopyPriceSet() { $priceSetID = $this->eventPriceSetCreate(9); @@ -79,6 +83,8 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { /** * Test CRM_Price_BAO_PriceSet::getMembershipCount() that return correct number of * membership type occurances against it's corresponding member orgaisation + * + * @throws \CRM_Core_Exception */ public function testGetMembershipCount() { // create two organisations diff --git a/xml/schema/Price/PriceField.xml b/xml/schema/Price/PriceField.xml index c3ac6dd662..0c2c1af3c1 100644 --- a/xml/schema/Price/PriceField.xml +++ b/xml/schema/Price/PriceField.xml @@ -27,6 +27,7 @@ civicrm_price_set
id + name title
1.8