+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
*/
protected $deletableTestObjects;
- /** This test case doesn't require DB reset */
+ /**
+ * This test case doesn't require DB reset.
+ */
public $DBResetRequired = FALSE;
protected $_entity;
- /** Map custom group entities to civicrm components */
+ /**
+ * Map custom group entities to civicrm components.
+ */
static $componentMap = array(
'Contribution' => 'CiviContribute',
'Membership' => 'CiviMember',
return static::entities(static::toBeSkipped_getlimit());
}
+ /**
+ * Generate list of entities that can be retrieved using SQL operator syntax.
+ *
+ * @return array
+ */
public static function entities_getSqlOperators() {
return static::entities(static::toBeSkipped_getSqlOperators());
}
}
/**
- * Generate list of entities to test for get by id functions
+ * Generate list of entities to test for get by id functions.
* @param bool $sequential
* @return array
* Entities to be skipped
'CustomSearch',
'Extension',
'ReportTemplate',
- 'System'
+ 'System',
);
if ($sequential === TRUE) {
return $entitiesWithoutGet;
'PaymentProcessor',
'Setting',
'MailingContact',
- 'SystemLog'
+ 'SystemLog',
//skip this because it doesn't make sense to update logs,
);
if ($sequential === TRUE) {
'installments',
'original_installment_amount',
'next_pay_date',
- 'amount' // can't be changed through API,
+ 'amount', // can't be changed through API,
),
'break_return' => array(// if these are passed in they are retrieved from the wrong table
'honor_contact_id',
return $knownFailures[$entity][$key];
}
- /** testing the _get **/
+ /* ----- testing the _get ----- */
/**
* @dataProvider toBeSkipped_get
- entities that don't need a get action
+ * Entities that don't need a get action
* @param $Entity
*/
public function testNotImplemented_get($Entity) {
}
/**
- * Create two entities and make sure we can fetch them individually by ID
+ * Create two entities and make sure we can fetch them individually by ID.
*
* @dataProvider entities_get
*
}
/**
- * Check that get fetches an appropriate number of results
+ * Check that get fetches an appropriate number of results.
*
* @param string $entityName
* Name of entity to test.
// create entities
$baoObj1 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
- $this->assertTrue(is_integer($baoObj1->id), 'check first id');
+ $this->assertTrue(is_int($baoObj1->id), 'check first id');
$this->deletableTestObjects[$baoString][] = $baoObj1->id;
$baoObj2 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
- $this->assertTrue(is_integer($baoObj2->id), 'check second id');
+ $this->assertTrue(is_int($baoObj2->id), 'check second id');
$this->deletableTestObjects[$baoString][] = $baoObj2->id;
// fetch first by ID
}
}
- /** testing the _create **/
+ /* ---- testing the _create ---- */
/**
* @dataProvider toBeSkipped_create
$baoString = _civicrm_api3_get_BAO($entityName);
$this->assertNotEmpty($baoString, $entityName);
$this->assertNotEmpty($entityName, $entityName);
- $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get'));
+ $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get', 'options' => array('get_options' => 'all')));
if ($entityName != 'Pledge') {
- $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create'));
+ $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create', 'options' => array('get_options' => 'all')));
}
$fields = $fields['values'];
$return = array_keys($fieldsGet['values']);
$this->assertArrayHasKey('type', $specs, "the _spec function for $entityName field $field does not specify the type");
switch ($specs['type']) {
case CRM_Utils_Type::T_DATE:
- case CRM_Utils_Type::T_TIMESTAMP:
$entity[$fieldName] = '2012-05-20';
break;
+ case CRM_Utils_Type::T_TIMESTAMP:
+ // 4.6 doesn't support timestamp updates from 4.7 we should uncomment this. See CRM-16204
+ continue;
+
//case CRM_Utils_Type::T_DATETIME:
case 12:
case CRM_Utils_Type::T_URL:
$entity[$field] = 'warm.beer.com';
}
- if (!empty($specs['pseudoconstant'])) {
- $options = $this->callAPISuccess($entityName, 'getoptions', array('context' => 'create', 'field' => $field));
- if (empty($options['values'])) {
+ if (empty($specs['FKClassName']) && (!empty($specs['pseudoconstant']) || !empty($specs['options']))) {
+ $options = CRM_Utils_Array::value('options', $specs, array());
+ if (!$options) {
//eg. pdf_format id doesn't ship with any
if (isset($specs['pseudoconstant']['optionGroupName'])) {
- $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array(
- 'name' => 'pdf_format',
- 'return' => 'id'
- ));
$optionValue = $this->callAPISuccess('option_value', 'create', array(
- 'option_group_id' => $optionGroupID,
- 'label' => 'new option value'
+ 'option_group_id' => $specs['pseudoconstant']['optionGroupName'],
+ 'label' => 'new option value',
+ 'sequential' => 1,
));
- $options['values'][] = $optionValue['id'];
+ $optionValue = $optionValue['values'];
+ $options[$optionValue[0]['value']] = 'new option value';
}
}
- $entity[$field] = array_rand($options['values']);
+ $entity[$field] = array_rand($options);
+ }
+ if (!empty($specs['FKClassName']) && !empty($specs['pseudoconstant'])) {
+ // in the weird situation where a field has both an fk and pseudoconstant defined,
+ // e.g. campaign_id field, need to flush caches.
+ // FIXME: Why doesn't creating a campaign clear caches?
+ civicrm_api3($entityName, 'getfields', array('cache_clear' => 1));
}
$updateParams = array(
'id' => $entity['id'],
'update-result' => $update,
'getsingle-params' => $checkParams,
'getsingle-result' => $checkEntity,
- 'expected entity' => $entity
+ 'expected entity' => $entity,
), TRUE));
if ($resetFKTo) {
//reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in
$baoObj->free();
}
- /** testing the _getFields **/
+ /* ---- testing the _getFields ---- */
- /** testing the _delete **/
+ /* ---- testing the _delete ---- */
/**
* @dataProvider toBeSkipped_delete
while ($i < $count) {
// create entities
$baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
- $this->assertTrue(is_integer($baoObj->id), 'check first id');
+ $this->assertTrue(is_int($baoObj->id), 'check first id');
$this->deletableTestObjects[$baoString][] = $baoObj->id;
$baos[] = $baoObj;
$i++;
/**
- * Verify that HTML metacharacters provided as inputs appear consistently
+ * Verify that HTML metacharacters provided as inputs appear consistently.
* as outputs.
*
* At time of writing, the encoding scheme requires (for example) that an