diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index 3e6d0cebb3ee411239131816f929c7065ba77d07..a54c027665bb458e0dac7d891cbf198878e05baa 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 ee91a07c3f4f9878b3b120c3e395c88627c03b08..6f36583ba993f9ba543a7e23d4279e771819a7c9 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 85f4eda1bbf528eab8451b7c864b737e6b2d4da3..409179064d25da77caec59130db8b8a164c33206 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 539f6ebba77323a0a6d034da75f7907929d5aa2e..30196b1b76eb15055240ee7934a5dec65b86f2f3 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 5463d24340ff418dd785e0c5fa084da3708c4c29..cc0d0942e5b3d5899cc628720ff326a2ac6f09f7 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>