protected $_entity;
+ /** Map custom group entities to civicrm components */
+ static $componentMap = array(
+ 'Contact' => NULL,
+ 'Individual' => NULL,
+ 'Household' => NULL,
+ 'Organization' => NULL,
+ 'Contribution' => 'CiviContribute',
+ 'Membership' => 'CiviMember',
+ 'Participant' => 'CiviEvent',
+ 'Group' => NULL,
+ 'Relationship' => NULL,
+ 'Event' => 'CiviEvent',
+ 'Case' => 'CiviCase',
+ 'Activity' => NULL,
+ 'Pledge' => 'CiviPledge',
+ 'Grant' => 'CiviGrant',
+ 'Address' => NULL,
+ );
+
/* they are two types of missing APIs:
- Those that are to be implemented
(in some future version when someone steps in -hint hint-). List the entities in toBeImplemented[ {$action} ]
}
}
+ /**
+ * @param null $skip
+ *
+ * @return array
+ */
public static function entities($skip = NULL) {
// To only test specific entities, call phpunit with SYNTAX_CONFORMANCE_ENTITIES="TheEntityName"
// or uncomment this line:
return $entities;
}
+ /**
+ * @return array
+ */
public static function entities_get() {
// all the entities, beside the ones flagged
return static::entities(static::toBeSkipped_get(TRUE));
}
+ /**
+ * @return array
+ */
public static function entities_create() {
return static::entities(static::toBeSkipped_create(TRUE));
}
+ /**
+ * @return array
+ */
public static function entities_updatesingle() {
return static::entities(static::toBeSkipped_updatesingle(TRUE));
}
+ /**
+ * @return array
+ */
public static function entities_getlimit() {
return static::entities(static::toBeSkipped_getlimit());
}
+ /**
+ * @return array
+ */
public static function entities_delete() {
return static::entities(static::toBeSkipped_delete(TRUE));
}
+ /**
+ * @return array
+ */
+ public static function entities_getfields() {
+ return static::entities(static::toBeSkipped_getfields(TRUE));
+ }
+ /**
+ * @return array
+ */
public static function custom_data_entities_get() {
return static::custom_data_entities();
}
+ /**
+ * @return array
+ */
public static function custom_data_entities() {
- $entities = CRM_Core_BAO_CustomQuery::$extendsMap;
- $customDataEntities = array();
+ $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
+ $entities = CRM_Core_BAO_CustomQuery::$extendsMap;
+ $components = self::$componentMap;
+ $customDataEntities = array();
$invalidEntities = array('Individual', 'Organization', 'Household');
$entitiesToFix = array('Case', 'Relationship');
- foreach ($entities as $entityName => $entity ) {
- if(!in_array($entityName, $invalidEntities)
- && !in_array($entityName, $entitiesToFix)) {
- $customDataEntities[] = array($entityName );
- }
- }
+ foreach ($entities as $entityName => $entity ) {
+ if(!in_array($entityName, $invalidEntities)
+ && !in_array($entityName, $entitiesToFix)
+ && (!empty($components[$entityName]) && in_array($components[$entityName], $enableComponents) || $components[$entityName] == NULL)) {
+ $customDataEntities[] = array($entityName );
+ }
+ }
return $customDataEntities;
}
+ /**
+ * @param bool $sequential
+ *
+ * @return array
+ */
public static function toBeSkipped_get($sequential = FALSE) {
$entitiesWithoutGet = array('MailingEventSubscribe', 'MailingEventConfirm', 'MailingEventResubscribe', 'MailingEventUnsubscribe', 'MailingGroup', 'Location');
if ($sequential === TRUE) {
return array('MailingContact');
}
+ /**
+ * @param bool $sequential
+ *
+ * @return array
+ */
public static function toBeSkipped_create($sequential = FALSE) {
$entitiesWithoutCreate = array('MailingGroup', 'Constant', 'Entity', 'Location', 'Profile', 'MailingRecipients');
if ($sequential === TRUE) {
return $entities;
}
+ /**
+ * @param bool $sequential
+ *
+ * @return array
+ */
public static function toBeSkipped_delete($sequential = FALSE) {
$entitiesWithout = array('MailingContact', 'MailingEventConfirm', 'MailingEventResubscribe', 'MailingEventSubscribe', 'MailingEventUnsubscribe', 'MailingGroup', 'MailingRecipients', 'Constant', 'Entity', 'Location', 'Domain', 'Profile', 'CustomValue', 'Setting');
if ($sequential === TRUE) {
return $entities;
}
+ /**
+ * @param bool $sequential
+ *
+ * @return array
+ * @todo add metadata for ALL these entities
+ */
+ public static function toBeSkipped_getfields($sequential = FALSE) {
+ $entitiesWithMetadataNotYetFixed = array('ReportTemplate', 'CustomSearch');
+ if ($sequential === TRUE) {
+ return $entitiesWithMetadataNotYetFixed ;
+ }
+ $entities = array();
+ foreach ($entitiesWithMetadataNotYetFixed as $e) {
+ $entities[] = array($e);
+ }
+ return $entities;
+ }
/**
* Generate list of entities to test for get by id functions
* @param boolean $sequential
'MailSettings',
'Setting',
'MailingContact',
+ 'SystemLog' //skip this because it doesn't make sense to update logs
);
if ($sequential === TRUE) {
return $entitiesWithout;
'pledge_contribution_page_id',
'pledge_status_id',
'pledge_campaign_id',
+ 'pledge_financial_type_id',
)
),
'PaymentProcessorType' => array(
'id' => $entity['id'],
$field => isset($entity[$field]) ? $entity[$field] : NULL,
);
+ if(isset($updateParams['financial_type_id']) && $entityName != 'Product') {
+ //api has special handling on these 2 fields for backward compatibility reasons
+ $entity['contribution_type_id'] = $updateParams['financial_type_id'];
+ }
$update = $this->callAPISuccess($entityName, 'create', $updateParams);
$checkParams = array(
);
$checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
- $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updaetd\n" . print_r(array('update-params' => $updateParams, 'update-result' => $update, 'getsingle-params' => $checkParams, 'getsingle-result' => $checkEntity, 'expected entity' => $entity), TRUE));
+ $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array('update-params' => $updateParams, 'update-result' => $update, 'getsingle-params' => $checkParams, 'getsingle-result' => $checkEntity, 'expected entity' => $entity), TRUE));
}
$baoObj->free();
}
);
}
+ /**
+ * Create two entities and make sure delete action only deletes one!
+ *
+ * @dataProvider entities_getfields
+ *
+ */
+ public function testGetfieldsHasTitle($entity) {
+ $entities = $this->getEntitiesSupportingCustomFields();
+ if (in_array($entity, $entities)) {
+ $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, $entity . 'Test.php');
+ }
+ $actions = $this->callAPISuccess($entity, 'getactions', array());
+ foreach ($actions['values'] as $action) {
+ if (substr($action, -7) == '_create' || substr($action, -4) == '_get' || substr($action, -7) == '_delete') {
+ //getactions can't distinguish between contribution_page.create & contribution_page.create
+ continue;
+ }
+ $fields = $this->callAPISuccess($entity, 'getfields', array('action' => $action));
+ if (!empty($ids) && in_array($action, array('create', 'get'))) {
+ $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $fields['values']);
+ }
+
+ foreach ($fields['values'] as $fieldName => $fieldSpec) {
+ $this->assertArrayHasKey('title', $fieldSpec, "no title for $entity - $fieldName on action $action");
+ $this->assertNotEmpty($fieldSpec['title'], "empty title for $entity - $fieldName");
+ }
+ }
+ if (!empty($ids)) {
+ $this->customFieldDelete($ids['custom_field_id']);
+ $this->customGroupDelete($ids['custom_group_id']);
+ }
+ }
+
+ /**
+ * @return array
+ */
+ public function getEntitiesSupportingCustomFields() {
+ $entities = self::custom_data_entities_get();
+ $returnEntities = array();
+ foreach ($entities as $entityArray) {
+ $returnEntities[] = $entityArray[0];
+ }
+ return $returnEntities;
+ }
/**
* @param $entityName
* @param int $count
1 => array($eventId, 'Integer')
));
}
-
}