Fix creating test objects CRM-12464
authorColeman Watts <coleman@civicrm.org>
Mon, 3 Jun 2013 23:08:10 +0000 (16:08 -0700)
committerColeman Watts <coleman@civicrm.org>
Mon, 3 Jun 2013 23:08:10 +0000 (16:08 -0700)
----------------------------------------
* CRM-12464: Add PseudoConstants to Schema Metadata
  http://issues.civicrm.org/jira/browse/CRM-12464

CRM/Core/DAO.php

index f37b8d3e1675c948ce092b343876a33bb010c37e..697a671fa857d0c3bdbec4ea4e3e55c27f34555f 100644 (file)
@@ -1275,12 +1275,10 @@ SELECT contact_id
       'CRM_Core_DAO_Domain',
     );
 
-    require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php");
-
     for ($i = 0; $i < $numObjects; ++$i) {
 
       ++$counter;
-      $object   = new $daoName ( );
+      $object = new $daoName();
 
       $fields = &$object->fields();
       foreach ($fields as $name => $value) {
@@ -1323,24 +1321,13 @@ SELECT contact_id
 
             continue;
           }
-          $constant = CRM_Utils_Array::value('pseudoconstant', $value);
-          if (!empty($constant)) {
-            if (empty($constant['name'])) {
-              throw new CRM_Core_Exception("Failed to choose value for $daoName ($name) -- missing pseudo-constant name");
-            }
-            $constantValues = CRM_Utils_PseudoConstant::getConstant($constant['name']);
-            if (!empty($constantValues)) {
-              $constantOptions = array_keys($constantValues);
-              $object->$dbName = $constantOptions[0];
-            }
-            continue;
-          }
-          $enum = CRM_Utils_Array::value('enumValues', $value);
-          if (!empty($enum)) {
-            $options = explode(',', $enum);
-            $object->$dbName = $options[0];
+          // Pick an option value if needed
+          $options = $daoName::buildOptions($dbName);
+          if ($options) {
+            $object->$dbName = key($options);
             continue;
           }
+
           switch ($value['type']) {
             case CRM_Utils_Type::T_INT:
             case CRM_Utils_Type::T_FLOAT: