Skip to content

Commit

Permalink
Add cleanup enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 15, 2025
1 parent d48b6fc commit cf18a7c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ protected function setUp(): void {
// something changed it and then inadvertently didn't restore it.
$this->errorHandlerAtStartOfTest = set_error_handler(function($errno, $errstr, $errfile, $errline) {});
restore_error_handler();
foreach (['civicrm_option_value', 'civicrm_campaign', 'civicrm_mailing_spool', 'civicrm_line_item', 'civicrm_im', 'civicrm_address'] as $entity) {
$this->entityTracking[$entity] = \CRM_Core_DAO::singleValueQuery('SELECT count(*) FROM ' . $entity);
}
}

/**
Expand Down Expand Up @@ -598,6 +601,16 @@ protected function tearDown(): void {
OptionValue::delete(FALSE)->addWhere('id', 'IN', $this->ids['OptionValue'])->execute();
}
unset(CRM_Core_Config::singleton()->userPermissionClass->permissions);
foreach ($this->entityTracking as $entity => $count) {
$field = 'name';
if ($entity === 'civicrm_line_item') {
$field = 'line_total';
}
if ($entity === 'civicrm_mailing_spool') {
$field = 'recipient_email';
}
$this->assertEquals($count, \CRM_Core_DAO::singleValueQuery('SELECT count(*) FROM ' . $entity), $entity . ' has not cleaned up well ' . CRM_Core_DAO::singleValueQuery('SELECT ' . $field . ' FROM ' . $entity . ' ORDER BY id DESC LIMIT 1'));
}
parent::tearDown();
}

Expand Down

0 comments on commit cf18a7c

Please sign in to comment.