From 073e34f05df40b057c4d1379e90eadb7bd4b30c3 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 15 Jan 2025 20:42:18 +1300 Subject: [PATCH] Minor test cleanups --- tests/phpunit/CiviTest/CiviCaseTestCase.php | 2 +- tests/phpunit/CiviTest/CiviUnitTestCase.php | 3 +++ tests/phpunit/api/v3/CaseTypeTest.php | 2 +- tests/phpunit/api/v3/ContributionTest.php | 16 +++++++--------- tests/phpunit/api/v3/CustomFieldTest.php | 4 ++-- tests/phpunit/api/v3/MailingABTest.php | 4 ++-- tests/phpunit/api/v3/MailingContactTest.php | 2 +- tests/phpunit/api/v3/MailingTest.php | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviCaseTestCase.php b/tests/phpunit/CiviTest/CiviCaseTestCase.php index e8422cb63b86..a61f42a2011d 100644 --- a/tests/phpunit/CiviTest/CiviCaseTestCase.php +++ b/tests/phpunit/CiviTest/CiviCaseTestCase.php @@ -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 { diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index c48e2893dc95..a070b93f74ea 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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')); } } diff --git a/tests/phpunit/api/v3/CaseTypeTest.php b/tests/phpunit/api/v3/CaseTypeTest.php index b5387e9a1e34..a8650c3d68b6 100644 --- a/tests/phpunit/api/v3/CaseTypeTest.php +++ b/tests/phpunit/api/v3/CaseTypeTest.php @@ -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'; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 2a8b04963950..3eddaec27f3a 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -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(); } @@ -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', @@ -2801,7 +2801,7 @@ 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'], @@ -2809,7 +2809,7 @@ public function testRepeatTransactionPassedInCampaign(): void { ]) ); - $this->callAPISuccess('contribution', 'repeattransaction', [ + $this->callAPISuccess('Contribution', 'repeattransaction', [ 'original_contribution_id' => $originalContribution['id'], 'contribution_status_id' => 'Completed', 'trxn_id' => 2345, @@ -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]); @@ -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(); } /** diff --git a/tests/phpunit/api/v3/CustomFieldTest.php b/tests/phpunit/api/v3/CustomFieldTest.php index 6f9df434e0df..5050d0398981 100644 --- a/tests/phpunit/api/v3/CustomFieldTest.php +++ b/tests/phpunit/api/v3/CustomFieldTest.php @@ -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(); @@ -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']); diff --git a/tests/phpunit/api/v3/MailingABTest.php b/tests/phpunit/api/v3/MailingABTest.php index a4cb2061f20b..6a353d558c00 100644 --- a/tests/phpunit/api/v3/MailingABTest.php +++ b/tests/phpunit/api/v3/MailingABTest.php @@ -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]; @@ -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); diff --git a/tests/phpunit/api/v3/MailingContactTest.php b/tests/phpunit/api/v3/MailingContactTest.php index c24428711978..8076f02cf9d3 100644 --- a/tests/phpunit/api/v3/MailingContactTest.php +++ b/tests/phpunit/api/v3/MailingContactTest.php @@ -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(); } diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index 484685e2fbf5..534e56e4f80d 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -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']);