From b0608558758ccf2fdadae59f367c5284a70eab06 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Dec 2024 15:28:36 -0800 Subject: [PATCH 1/5] (NFC) CustomFileTest - Use normal namespace --- tests/phpunit/api/v4/Custom/CustomFileTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/phpunit/api/v4/Custom/CustomFileTest.php b/tests/phpunit/api/v4/Custom/CustomFileTest.php index 6f005cce75f..acaac534238 100644 --- a/tests/phpunit/api/v4/Custom/CustomFileTest.php +++ b/tests/phpunit/api/v4/Custom/CustomFileTest.php @@ -15,9 +15,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ -namespace Civi\tests\phpunit\api\v4\Custom; +namespace api\v4\Custom; -use api\v4\Custom\CustomTestBase; use Civi\Api4\CustomGroup; use Civi\Api4\CustomField; use Civi\Api4\File; From 25965d8552b1fd0f8a1348c25a894fcfd0ef2e4d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Dec 2024 15:33:30 -0800 Subject: [PATCH 2/5] AbstractMappingTest - Compat with PHPUnit 10 --- tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php index fe13dcbe2ef..0f7fdfce8ec 100644 --- a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php +++ b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php @@ -198,7 +198,7 @@ protected function setUp(): void { ]; $this->schedule = new \CRM_Core_DAO_ActionSchedule(); - $this->schedule->title = $this->getName(TRUE); + $this->schedule->title = is_callable([$this, 'name']) ? $this->name() : $this->getName(TRUE); $this->schedule->name = \CRM_Utils_String::munge($this->schedule->title); $this->schedule->is_active = 1; $this->schedule->group_id = NULL; From a023e3dffcc60f624ad5159016effd8004a5857f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Dec 2024 15:36:07 -0800 Subject: [PATCH 3/5] (REF) AbstractMappingTest => AbstractMappingTestCase --- tests/phpunit/CRM/Activity/ActionMappingTest.php | 4 ++-- tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php | 6 +++--- tests/phpunit/CRM/Event/ActionMappingTest.php | 6 +++--- ...{AbstractMappingTest.php => AbstractMappingTestCase.php} | 2 +- .../phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) rename tests/phpunit/Civi/ActionSchedule/{AbstractMappingTest.php => AbstractMappingTestCase.php} (99%) diff --git a/tests/phpunit/CRM/Activity/ActionMappingTest.php b/tests/phpunit/CRM/Activity/ActionMappingTest.php index a3211ff39c8..4f271b93db6 100644 --- a/tests/phpunit/CRM/Activity/ActionMappingTest.php +++ b/tests/phpunit/CRM/Activity/ActionMappingTest.php @@ -22,10 +22,10 @@ * NOTE: There are also pretty deep tests of activity-based reminders in * CRM_Core_BAO_ActionScheduleTest. * - * @see \Civi\ActionSchedule\AbstractMappingTest + * @see \Civi\ActionSchedule\AbstractMappingTestCase * @see CRM_Core_BAO_ActionScheduleTest */ -class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappingTest { +class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappingTestCase { /** * Generate a list of test cases, where each is a distinct combination of diff --git a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php index bd0b4074dfd..aaf69b3280e 100644 --- a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php +++ b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php @@ -9,7 +9,7 @@ +--------------------------------------------------------------------+ */ -use Civi\ActionSchedule\AbstractMappingTest; +use Civi\ActionSchedule\AbstractMappingTestCase; use Civi\Api4\Contribution; use Civi\Token\TokenProcessor; @@ -21,10 +21,10 @@ * reminders for *contribution types*. It follows a design/pattern described in * AbstractMappingTest. * - * @see \Civi\ActionSchedule\AbstractMappingTest + * @see \Civi\ActionSchedule\AbstractMappingTestCase * @group headless */ -class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTest { +class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTestCase { /** * Generate a list of test cases, where each is a distinct combination of diff --git a/tests/phpunit/CRM/Event/ActionMappingTest.php b/tests/phpunit/CRM/Event/ActionMappingTest.php index 940e8e0c11e..97915590563 100644 --- a/tests/phpunit/CRM/Event/ActionMappingTest.php +++ b/tests/phpunit/CRM/Event/ActionMappingTest.php @@ -9,7 +9,7 @@ +--------------------------------------------------------------------+ */ -use Civi\ActionSchedule\AbstractMappingTest; +use Civi\ActionSchedule\AbstractMappingTestCase; /** * Class CRM_Event_ActionMappingTest @@ -18,10 +18,10 @@ * This class tests various configurations of event scheduled-reminders. It follows a design/pattern described in * AbstractMappingTest. * - * @see \Civi\ActionSchedule\AbstractMappingTest + * @see \Civi\ActionSchedule\AbstractMappingTestCase * @group headless */ -class CRM_Event_ActionMappingTest extends AbstractMappingTest { +class CRM_Event_ActionMappingTest extends AbstractMappingTestCase { public function createTestCases() { } diff --git a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTestCase.php similarity index 99% rename from tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php rename to tests/phpunit/Civi/ActionSchedule/AbstractMappingTestCase.php index 0f7fdfce8ec..872f54cb32a 100644 --- a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php +++ b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTestCase.php @@ -38,7 +38,7 @@ * @see CRM_Contribute_ActionMapping_ByTypeTest * @see CRM_Activity_ActionMappingTest */ -abstract class AbstractMappingTest extends \CiviUnitTestCase { +abstract class AbstractMappingTestCase extends \CiviUnitTestCase { /** * @var \CRM_Core_DAO_ActionSchedule diff --git a/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php b/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php index a995732bce0..5acb1323dca 100644 --- a/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php +++ b/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php @@ -7,10 +7,10 @@ * Test scheduled-communications based on SavedSearches. * * @group ActionSchedule - * @see \Civi\ActionSchedule\AbstractMappingTest + * @see \Civi\ActionSchedule\AbstractMappingTestCase * @group headless */ -class SavedSearchMappingTest extends AbstractMappingTest { +class SavedSearchMappingTest extends AbstractMappingTestCase { protected $savedSearch = []; From 725025cfec80fa2c363ea86c70c9207f52e3f987 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Dec 2024 16:34:27 -0800 Subject: [PATCH 4/5] ActionMappingTest - Update data-providers for phpunit 10 --- .../CRM/Activity/ActionMappingTest.php | 2 +- .../Contribute/ActionMapping/ByTypeTest.php | 2 +- tests/phpunit/CRM/Event/ActionMappingTest.php | 45 ++++++++++++++++--- .../AbstractMappingTestCase.php | 5 ++- .../ActionSchedule/SavedSearchMappingTest.php | 4 +- 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/CRM/Activity/ActionMappingTest.php b/tests/phpunit/CRM/Activity/ActionMappingTest.php index 4f271b93db6..88446e84502 100644 --- a/tests/phpunit/CRM/Activity/ActionMappingTest.php +++ b/tests/phpunit/CRM/Activity/ActionMappingTest.php @@ -40,7 +40,7 @@ class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappin * - recipients: array of emails * - subject: regex */ - public function createTestCases() { + public static function createTestCases(): array { $cs = []; $cs[] = [ diff --git a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php index aaf69b3280e..5ec94ca3893 100644 --- a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php +++ b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php @@ -39,7 +39,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTestCase { * - recipients: array of emails * - subject: regex */ - public function createTestCases(): array { + public static function createTestCases(): array { $cs = []; $cs[] = [ diff --git a/tests/phpunit/CRM/Event/ActionMappingTest.php b/tests/phpunit/CRM/Event/ActionMappingTest.php index 97915590563..bbd0fafe935 100644 --- a/tests/phpunit/CRM/Event/ActionMappingTest.php +++ b/tests/phpunit/CRM/Event/ActionMappingTest.php @@ -23,20 +23,51 @@ */ class CRM_Event_ActionMappingTest extends AbstractMappingTestCase { - public function createTestCases() { + public static function createTestCases(): array { + $cs = []; + + $cs[] = [ + '2015-02-01 00:00:00', + 'createReunion registerAliceDualRole scheduleForEventStart startWeekBefore targetByRole useHelloFirstName', + [ + [ + 'time' => '2015-01-25 00:00:00', + 'to' => ['alice@example.org'], + 'subject' => '/Hello, Alice/', + ], + ], + ]; + + return $cs; + } + + public function createReunion(array $params = [], string $identifier = 'event') { + $this->eventCreateUnpaid([ + 'title' => 'Roadie Reunion', + 'start_date' => '2015-02-01 00:00:00', + 'end_date' => '2015-02-03 05:00:00', + 'registration_start_date' => '2014-08-01 09:00:00', + 'registration_end_date' => '2015-01-15 23:59:59', + ]); } - public function testLimitByRoleID(): void { - $this->participantCreate(['role_id' => [1, 2], 'event_id' => $this->eventCreateUnpaid()['id']]); + public function registerAliceDualRole() { + $this->participantCreate([ + 'role_id' => [1, 2], + 'contact_id' => $this->contacts['alice']['id'], + 'event_id' => $this->getEventID(), + ]); + } + + public function scheduleForEventStart(): void { $this->schedule->mapping_id = CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID; $this->schedule->start_action_date = 'start_date'; $this->schedule->entity_value = $this->getEventID(); + } + + public function targetByRole(): void { $this->schedule->limit_to = 1; $this->schedule->recipient_listing = 1; - $this->startWeekBefore(); - $this->useHelloFirstName(); - $this->schedule->save(); - $this->callAPISuccess('Job', 'send_reminder', []); } } diff --git a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTestCase.php b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTestCase.php index 872f54cb32a..4196b882caf 100644 --- a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTestCase.php +++ b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTestCase.php @@ -95,7 +95,7 @@ abstract class AbstractMappingTestCase extends \CiviUnitTestCase { * - subject: regex * - message: regex */ - abstract public function createTestCases(); + abstract public static function createTestCases(): array; // ---------------------------------------- Setup Helpers ---------------------------------------- @@ -274,6 +274,9 @@ protected function setUp(): void { * @throws \Exception */ public function testDefault(string $targetDate, string $setupFuncs, array $expectMessages) { + if ($targetDate === 'INCOMPLETE') { + $this->markTestIncomplete(); + } $this->targetDate = $targetDate; foreach (explode(' ', $setupFuncs) as $setupFunc) { diff --git a/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php b/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php index 5acb1323dca..36bff1edcdd 100644 --- a/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php +++ b/tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php @@ -159,8 +159,8 @@ protected function setDateField(string $fieldName): void { /** * Disable testDefault by returning no test cases */ - public function createTestCases() { - return []; + public static function createTestCases(): array { + return [['INCOMPLETE', '', []]]; } } From 02cd1de124910ecd6440da91627666141b8177d7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Dec 2024 17:05:58 -0800 Subject: [PATCH 5/5] ByTypeTest - More consistent results on PHPUnit 10 Tests seem to execute in a different order, leading to different ID#s --- tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php index 5ec94ca3893..12e3a3a85f7 100644 --- a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php +++ b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php @@ -193,7 +193,7 @@ public static function createTestCases(): array { * Create a contribution record for Alice with type "Member Dues". */ public function addAliceDues(): void { - $campaignID = $this->campaignCreate([ + $campaignID = $this->ids['Campaign']['big'] = $this->campaignCreate([ 'title' => 'Campaign', 'name' => 'big_campaign', ]); @@ -373,7 +373,7 @@ public function testTokenRendering(): void { 'fee_amount = €5.00', 'paid_amount = €100.00', 'balance_amount = €0.00', - 'campaign_id = 1', + 'campaign_id = ' . $this->ids['Campaign']['big'], 'campaign name = big_campaign', 'campaign label = Campaign', 'receipt text = Thank you!',