Skip to content

Commit

Permalink
Minor test cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 15, 2025
1 parent ddca7aa commit 073e34f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/CiviTest/CiviCaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function tearDown(): void {
CaseType::delete(FALSE)->addWhere('id', 'IN', $this->ids['CaseType'])->execute();
}
CRM_Case_XMLRepository::singleton()->flush();
$this->assertEntityCleanup();
parent::tearDown();
$this->assertEntityCleanup();
}

public static function setUpBeforeClass(): void {
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ protected function assertEntityCleanup(): void {
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'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/CaseTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function testCaseTypeDeleteInUse(): void {
* @throws \Exception
*/
public function testCaseStatusByCaseType(): void {
$statusName = md5(mt_rand());
$statusName = 'crazy_new_status';
$template = $this->callAPISuccess('CaseType', 'getsingle', ['name' => 'housing_support']);
unset($template['id']);
$template['name'] = $template['title'] = 'test_case_type';
Expand Down
16 changes: 7 additions & 9 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function setUp(): void {
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
$this->restoreMembershipTypes();
$this->quickCleanup(['civicrm_uf_match'], TRUE);
$this->quickCleanup(['civicrm_uf_match', 'civicrm_mailing_spool'], TRUE);
if (!empty($this->ids['Campaign'])) {
Campaign::delete(FALSE)->addWhere('id', 'IN', $this->ids['Campaign'])->execute();
}
Expand Down Expand Up @@ -2788,8 +2788,8 @@ public function testRepeatTransactionUpdatedFinancialType(): void {
*/
public function testRepeatTransactionPassedInCampaign(): void {
$paymentProcessorID = $this->paymentProcessorCreate();
$campaignID = $this->campaignCreate();
$campaignID2 = $this->campaignCreate();
$campaignID = $this->campaignCreate([], 'first');
$campaignID2 = $this->campaignCreate([], 'second');
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->individualID,
'installments' => '12',
Expand All @@ -2801,15 +2801,15 @@ public function testRepeatTransactionPassedInCampaign(): void {
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
]);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$originalContribution = $this->callAPISuccess('Contribution', 'create', array_merge(
$this->_params,
[
'contribution_recur_id' => $contributionRecur['id'],
'campaign_id' => $campaignID,
])
);

$this->callAPISuccess('contribution', 'repeattransaction', [
$this->callAPISuccess('Contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => 2345,
Expand Down Expand Up @@ -2984,7 +2984,7 @@ public function testCompleteTransactionWithEmailReceiptInput(): void {
* Test that $is_recur is assigned to the receipt.
*/
public function testCompleteTransactionForRecurring(): void {
$this->mut = new CiviMailUtils($this, TRUE);
$mut = new CiviMailUtils($this, TRUE);
$this->swapMessageTemplateForTestTemplate();
$recurring = $this->setUpRecurringContribution();
$contributionPage = $this->createReceiptableContributionPage(['is_recur' => TRUE, 'recur_frequency_unit' => 'month', 'recur_interval' => 1]);
Expand All @@ -3001,12 +3001,10 @@ public function testCompleteTransactionForRecurring(): void {
'is_email_receipt' => 1,
]);

$this->mut->checkMailLog([
$mut->checkMailLog([
'is_recur:::1',
'cancelSubscriptionUrl:::' . CIVICRM_UF_BASEURL,
]);
$this->mut->stop();
$this->revertTemplateToReservedTemplate();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function tearDown(): void {
// if we don't do it more carefully here.
CRM_Core_DAO::executeQuery('UPDATE civicrm_custom_field f
INNER JOIN civicrm_option_group g ON g.id = option_group_id
SET option_group_id = NULL');
SET option_group_id = NULL WHERE g.name = "gender"');
CustomField::delete()
->addWhere('id', '>', 0)
->execute();
Expand Down Expand Up @@ -319,7 +319,7 @@ public function testCustomFieldCreateWithOptionValues(): void {

];

$customField = $this->callAPISuccess('custom_field', 'create', $params);
$customField = $this->callAPISuccess('CustomField', 'create', $params);

$this->assertAPISuccess($customField);
$this->assertNotNull($customField['id']);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/MailingABTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testMailerDeleteSuccess(): void {
/**
* @return array
*/
public function groupPctProvider() {
public function groupPctProvider(): array {
// array(int $totalSize, int $groupPct, int $expectedCountA, $expectedCountB, $expectedCountC)
$cases = [];
$cases[] = [400, 7, 28, 28, 344];
Expand Down Expand Up @@ -167,7 +167,7 @@ public function testDistribution($totalGroupContacts, $groupPct, $expectedCountA
* Create a test. Declare the second mailing a winner. Ensure that key
* fields propagate to the final mailing.
*/
public function testSubmitWinnderId(): void {
public function testSubmitWinnerId(): void {
$checkSyncFields = ['subject', 'body_text'];

$result = $this->groupContactCreate($this->_groupID, 20, TRUE);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/MailingContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class api_v3_MailingContactTest extends CiviUnitTestCase {

public function tearDown(): void {
$this->quickCleanup(['civicrm_contact', 'civicrm_mailing_recipients', 'civicrm_mailing', 'civicrm_mailing_event_delivered']);
$this->quickCleanup(['civicrm_contact', 'civicrm_mailing_recipients', 'civicrm_mailing_event_queue', 'civicrm_mailing', 'civicrm_mailing_event_delivered']);
parent::tearDown();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/MailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function tearDown(): void {
* @dataProvider versionThreeAndFour
*/
public function testMailerCreateSuccess(): void {
$this->callAPISuccess('Campaign', 'create', ['name' => 'big campaign', 'title' => 'abc']);
$this->campaignCreate(['name' => 'big campaign', 'title' => 'abc']);
$result = $this->callAPISuccess('mailing', 'create', $this->_params + ['scheduled_date' => 'now', 'campaign_id' => 'big campaign']);
$jobs = $this->callAPISuccess('MailingJob', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals(1, $jobs['count']);
Expand Down

0 comments on commit 073e34f

Please sign in to comment.