From 398f49abf80e0d28a9c3f79024959c2e2a26fb3c Mon Sep 17 00:00:00 2001 From: Allen Shaw <allen@emphanos.com> Date: Tue, 30 Apr 2013 13:27:41 -0700 Subject: [PATCH] Added support for more optionValue types in get() method, with corresponding tests. Toward CRM-12464. ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 --- tests/phpunit/CRM/Core/PseudoConstantTest.php | 65 ++++++++++++++++--- xml/schema/Contact/Contact.xml | 7 +- xml/schema/Core/Address.xml | 7 +- xml/schema/Core/Email.xml | 7 +- xml/schema/Core/Phone.xml | 4 +- 5 files changed, 72 insertions(+), 18 deletions(-) diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index 3e6d0cebb3..a54c027665 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -43,14 +43,63 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { parent::setUp(); } - function testGender() { - $expected = array( - 1 => 'Female', - 2 => 'Male', - 3 => 'Transgender', + function testOptionValues() { + // We'll test these daoName/field combinations. + // array[DAO Name] = properties, where properties can be: + // - fieldName: the SQL column name within the DAO table. + // - sample: Any one value which is expected in the list of option values. + // - max: integer (default = 10) maximum number of option values expected. + $fields = array( + 'CRM_Contact_DAO_Contact' => array( + array( + 'fieldName' => 'prefix_id', + 'sample' => 'Mr.', + ), + array( + 'fieldName' => 'suffix_id', + 'sample' => 'Sr.', + ), + array( + 'fieldName' => 'gender_id', + 'sample' => 'Male', + ), + ), + 'CRM_Core_DAO_Phone' => array( + array( + 'fieldName' => 'phone_type_id', + 'sample' => 'Phone', + ), + array( + 'fieldName' => 'location_type_id', + 'sample' => 'Home', + ), + ), + 'CRM_Core_DAO_Email' => array( + array( + 'fieldName' => 'location_type_id', + 'sample' => 'Home', + ), + ), + 'CRM_Core_DAO_Address' => array( + array( + 'fieldName' => 'location_type_id', + 'sample' => 'Home', + ), + ), ); - - $actual = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); - $this->assertEquals($expected, $actual); + + foreach ($fields as $daoName => $daoFields) { + foreach ($daoFields as $field) { + $message = "DAO name: '{$daoName}', field: '{$fieldName}'"; + + // Ensure sample value is contained in the returned optionValues. + $optionValues = CRM_Core_PseudoConstant::get($daoName, $field['fieldName']); + $this->assertContains($field['sample'], $optionValues, $message); + + // Ensure count of optionValues is not extraordinarily high. + $max = CRM_Utils_Array::value('max', $field, 10); + $this->assertLessThanOrEqual($max, count($optionValues), $message); + } + } } } diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index ee91a07c3f..6f36583ba9 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -338,8 +338,7 @@ <type>int unsigned</type> <comment>Prefix or Title for name (Ms, Mr...). FK to prefix ID</comment> <pseudoconstant> - <name>individualPrefix</name> - <optionGroupName>individualPrefix</optionGroupName> + <optionGroupName>individual_prefix</optionGroupName> </pseudoconstant> <headerPattern>/^(prefix|title)/i</headerPattern> <dataPattern>/^(mr|ms|mrs|sir|dr)\.?$/i</dataPattern> @@ -355,8 +354,7 @@ <title>Individual Suffix</title> <type>int unsigned</type> <pseudoconstant> - <name>individualSuffix</name> - <optionGroupName>individualSuffix</optionGroupName> + <optionGroupName>individual_suffix</optionGroupName> </pseudoconstant> <comment>Suffix for name (Jr, Sr...). FK to suffix ID</comment> <headerPattern>/^suffix$/i</headerPattern> @@ -482,7 +480,6 @@ <title>Gender</title> <type>int unsigned</type> <pseudoconstant> - <name>gender</name> <optionGroupName>gender</optionGroupName> </pseudoconstant> <headerPattern>/^gender$/i</headerPattern> diff --git a/xml/schema/Core/Address.xml b/xml/schema/Core/Address.xml index 85f4eda1bb..409179064d 100644 --- a/xml/schema/Core/Address.xml +++ b/xml/schema/Core/Address.xml @@ -36,7 +36,12 @@ <title>Address Location Type</title> <type>int unsigned</type> <comment>Which Location does this address belong to.</comment> - <add>2.0</add> + <add>2.0</add> + <pseudoconstant> + <table>civicrm_location_type</table> + <keyColumn>id</keyColumn> + <labelColumn>name</labelColumn> + </pseudoconstant> </field> <index> <name>index_location_type</name> diff --git a/xml/schema/Core/Email.xml b/xml/schema/Core/Email.xml index 539f6ebba7..30196b1b76 100644 --- a/xml/schema/Core/Email.xml +++ b/xml/schema/Core/Email.xml @@ -36,7 +36,12 @@ <title>Email Location Type</title> <type>int unsigned</type> <comment>Which Location does this email belong to.</comment> - <add>2.0</add> + <add>2.0</add> + <pseudoconstant> + <table>civicrm_location_type</table> + <keyColumn>id</keyColumn> + <labelColumn>name</labelColumn> + </pseudoconstant> </field> <index> <name>index_location_type</name> diff --git a/xml/schema/Core/Phone.xml b/xml/schema/Core/Phone.xml index 5463d24340..cc0d0942e5 100644 --- a/xml/schema/Core/Phone.xml +++ b/xml/schema/Core/Phone.xml @@ -37,7 +37,6 @@ <type>int unsigned</type> <comment>Which Location does this phone belong to.</comment> <pseudoconstant> - <name>locationType</name> <table>civicrm_location_type</table> <keyColumn>id</keyColumn> <labelColumn>name</labelColumn> @@ -136,8 +135,7 @@ <type>int unsigned</type> <comment>Which type of phone does this number belongs.</comment> <pseudoconstant> - <name>phoneType</name> - <optionGroupName>phoneType</optionGroupName> + <optionGroupName>phone_type</optionGroupName> </pseudoconstant> <add>2.2</add> </field> -- GitLab