'civicrm_uf_match',
'civicrm_campaign',
'civicrm_email',
+ 'civicrm_file',
+ 'civicrm_entity_file',
];
$this->quickCleanup($tablesToTruncate);
$this->cleanUpAfterACLs();
* Cleanup after test.
*
* @throws \CRM_Core_Exception
+ * @throws \API_Exception
*/
public function tearDown(): void {
- parent::tearDown();
$this->quickCleanup(['civicrm_batch']);
+ parent::tearDown();
}
/**
'civicrm_case_contact',
'civicrm_case_activity',
'civicrm_case_type',
+ 'civicrm_file',
+ 'civicrm_entity_file',
'civicrm_activity_contact',
'civicrm_managed',
'civicrm_relationship',
/**
* Make sure that the latest case activity works accurately.
*/
- public function testCaseActivity() {
+ public function testCaseActivity(): void {
$userID = $this->createLoggedInUser();
$addTimeline = civicrm_api3('Case', 'addtimeline', [
}
protected function tearDown(): void {
- parent::tearDown();
$this->quickCleanup($this->tablesToTruncate, TRUE);
+ parent::tearDown();
}
public function testAddCaseToContact() {
*/
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
+ parent::tearDown();
}
/**
/**
* Clean up DB.
+ *
+ * @throws \CRM_Core_Exception|\API_Exception
*/
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
+ parent::tearDown();
}
/**
$this->quickCleanUpFinancialEntities();
$this->revertTemplateToReservedTemplate('contribution_invoice_receipt');
CRM_Utils_Hook::singleton()->reset();
+ parent::tearDown();
}
/**
*/
class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
+ public function tearDown(): void {
+ $this->quickCleanup(['civicrm_file', 'civicrm_entity_file'], TRUE);
+ parent::tearDown();
+ }
+
/**
* Test store function for country.
*/
];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
/**
];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
/**
* Test store function for state province.
*/
- public function testStoreStateProvince() {
+ public function testStoreStateProvince(): void {
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
$fields = [
];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
/**
* Test store function for date.
*/
- public function testStoreDate() {
+ public function testStoreDate(): void {
$params = [];
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
/**
* Test store function for rich text editor.
*/
- public function testStoreRichTextEditor() {
+ public function testStoreRichTextEditor(): void {
$params = [];
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
-
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
/**
* Test store function for multiselect int.
+ *
+ * @throws \API_Exception
*/
- public function testStoreMultiSelectInt() {
+ public function testStoreMultiSelectInt(): void {
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
$fields = [
->addWhere('id', '=', $contactID)
->execute()->first();
$this->assertEquals([1, 2], $customData['new_custom_group.Custom_Field']);
-
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
/**
* Test getEntityValues function for stored value.
*/
- public function testGetEntityValues() {
-
+ public function testGetEntityValues(): void {
$params = [];
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate(['extends' => 'Individual']);
$entityValues = CRM_Core_BAO_CustomValueTable::getEntityValues($contactID, 'Individual');
- $this->assertEquals($entityValues[$customField['id']], '<p><strong>This is a <u>test</u></p>',
+ $this->assertEquals('<p><strong>This is a <u>test</u></p>', $entityValues[$customField['id']],
'Checking same for returned value.'
);
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
- public function testCustomGroupMultiple() {
- $params = [];
+ public function testCustomGroupMultiple(): void {
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
$this->assertEquals($params['custom_' . $customField['id'] . '_-1'], $result['custom_' . $customField['id']]);
$this->assertEquals($params['entityID'], $result['entityID']);
-
- $this->customFieldDelete($customField['id']);
- $this->customGroupDelete($customGroup['id']);
- $this->contactDelete($contactID);
}
}
$this->callAPISuccess('MailSettings', 'delete', [
'id' => $this->mailSettingsId,
]);
+ $this->quickCleanup(['civicrm_file', 'civicrm_entity_file']);
parent::tearDown();
}
/**
* Common teardown functions for all unit tests.
*
- * @throws \CRM_Core_Exception
* @throws \API_Exception
*/
protected function tearDown(): void {
*
* @param array $tablesToTruncate
* @param bool $dropCustomValueTables
- *
- * @throws \CRM_Core_Exception
- * @throws \API_Exception
*/
- public function quickCleanup($tablesToTruncate, $dropCustomValueTables = FALSE) {
+ public function quickCleanup(array $tablesToTruncate, $dropCustomValueTables = FALSE): void {
if ($this->tx) {
- throw new \CRM_Core_Exception("CiviUnitTestCase: quickCleanup() is not compatible with useTransaction()");
+ $this->fail('CiviUnitTestCase: quickCleanup() is not compatible with useTransaction()');
}
if ($dropCustomValueTables) {
$this->cleanupCustomGroups();
$tablesToTruncate = array_unique(array_merge($this->_tablesToTruncate, $tablesToTruncate));
- CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS = 0;");
+ CRM_Core_DAO::executeQuery('SET FOREIGN_KEY_CHECKS = 0;');
foreach ($tablesToTruncate as $table) {
$sql = "TRUNCATE TABLE $table";
CRM_Core_DAO::executeQuery($sql);
}
- CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS = 1;");
+ CRM_Core_DAO::executeQuery('SET FOREIGN_KEY_CHECKS = 1;');
}
/**
* Clean up financial entities after financial tests (so we remember to get all the tables :-))
- *
- * @throws \CRM_Core_Exception
*/
- public function quickCleanUpFinancialEntities() {
+ public function quickCleanUpFinancialEntities(): void {
$tablesToTruncate = [
'civicrm_activity',
'civicrm_activity_contact',
$this->restoreDefaultPriceSetConfig();
$this->disableTaxAndInvoicing();
$this->setCurrencySeparators(',');
- FinancialType::delete(FALSE)->addWhere(
- 'name', 'NOT IN', ['Donation' , 'Member Dues', 'Campaign Contribution', 'Event Fee']
- )->execute();
+ try {
+ FinancialType::delete(FALSE)->addWhere(
+ 'name', 'NOT IN', [
+ 'Donation',
+ 'Member Dues',
+ 'Campaign Contribution',
+ 'Event Fee',
+ ]
+ )->execute();
+ }
+ catch (API_Exception $e) {
+ $this->fail('failed to cleanup financial types ' . $e->getMessage());
+ }
CRM_Core_PseudoConstant::flush('taxRates');
System::singleton()->flushProcessors();
// @fixme this parameter is leaking - it should not be defined as a class static
/**
* Delete any existing custom data groups.
- *
- * @throws \API_Exception
*/
protected function cleanupCustomGroups(): void {
- CustomField::get(FALSE)->setSelect(['option_group_id', 'custom_group_id'])
- ->addChain('delete_options', OptionGroup::delete()
- ->addWhere('id', '=', '$option_group_id')
- )
- ->addChain('delete_fields', CustomField::delete()
- ->addWhere('id', '=', '$id')
- )->execute();
+ try {
+ CustomField::get(FALSE)->setSelect(['option_group_id', 'custom_group_id'])
+ ->addChain('delete_options', OptionGroup::delete()
+ ->addWhere('id', '=', '$option_group_id')
+ )
+ ->addChain('delete_fields', CustomField::delete()
+ ->addWhere('id', '=', '$id')
+ )->execute();
- CustomGroup::delete(FALSE)->addWhere('id', '>', 0)->execute();
+ CustomGroup::delete(FALSE)->addWhere('id', '>', 0)->execute();
+ }
+ catch (API_Exception $e) {
+ $this->fail('failed to cleanup custom groups ' . $e->getMessage());
+ }
}
/**
'civicrm_website',
'civicrm_relationship',
'civicrm_uf_match',
+ 'civicrm_file',
+ 'civicrm_entity_file',
'civicrm_phone',
'civicrm_address',
'civicrm_acl_contact_cache',