diff --git a/tests/phpunit/CRM/Upgrade/SnapshotTest.php b/tests/phpunit/CRM/Upgrade/SnapshotTest.php index a6a8ae366200..a5324a7fcc88 100644 --- a/tests/phpunit/CRM/Upgrade/SnapshotTest.php +++ b/tests/phpunit/CRM/Upgrade/SnapshotTest.php @@ -12,14 +12,22 @@ protected function setUp(): void { CRM_Upgrade_Snapshot::$cleanupAfter = 4; } - public function testTableNames_good() { + public function tearDown(): void { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + + /** + * @throws \CRM_Core_Exception + */ + public function testTableNamesGood(): void { $this->assertEquals('snap_civicrm_v5_45_stuff', CRM_Upgrade_Snapshot::createTableName('civicrm', '5.45', 'stuff')); $this->assertEquals('snap_civicrm_v5_50_stuffy_things', CRM_Upgrade_Snapshot::createTableName('civicrm', '5.50', 'stuffy_things')); $this->assertEquals('snap_oauth_client_v12_34_ext_things', CRM_Upgrade_Snapshot::createTableName('oauth_client', '12.34', 'ext_things')); $this->assertEquals('snap_oauth_client_v0_1234_ext_things', CRM_Upgrade_Snapshot::createTableName('oauth_client', '0.1234', 'ext_things')); } - public function testTableNames_bad() { + public function testTableNamesBad(): void { try { CRM_Upgrade_Snapshot::createTableName('civicrm', '5.45', 'ab&cd'); $this->fail('Accepted invalid name'); @@ -28,7 +36,7 @@ public function testTableNames_bad() { $this->assertRegExp('/Malformed snapshot name/', $e->getMessage()); } try { - CRM_Upgrade_Snapshot::createTableName('civicrm', '5.45', 'loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmod'); + CRM_Upgrade_Snapshot::createTableName('civicrm', '5.45', 'long_table_name_that_is_too_long_for_the_validation'); $this->fail('Accepted excessive name'); } catch (CRM_Core_Exception $e) { @@ -38,11 +46,15 @@ public function testTableNames_bad() { /** * This example creates a snapshot based on particular sliver of data (ie - * the "display_name" and "sort_name" for "Individual" records). It ensures that: + * the "display_name" and "sort_name" for "Individual" records). It ensures + * that: * - * 1. Some columns are copied - while other columns are not (based on `select()`). + * 1. Some columns are copied - while other columns are not (based on + * `select()`). * 2. Some rows are copied - while other rows are not (based on `where()`). * 3. Multiple pages of data are copied. + * + * @throws \CRM_Core_Exception */ public function testContent(): void { for ($i = 0; $i < 15; $i++) { @@ -84,7 +96,7 @@ public function testBasicLifecycle(): void { $this->organizationCreate([], $i); } $this->eventCreateUnpaid([]); - $this->eventCreateUnpaid([]); + $this->eventCreateUnpaid([], 'second'); $this->runAll(CRM_Upgrade_Snapshot::createTasks('civicrm', '5.45', 'names', CRM_Utils_SQL_Select::from('civicrm_contact') ->select('id, display_name, sort_name') @@ -117,6 +129,8 @@ public function testBasicLifecycle(): void { * ex: "table_1.column_1" * @param string $actualField * ex: "table_2.column_2" + * + * @throws \Civi\Core\Exception\DBQueryException */ protected function assertSameSchema(string $expectField, string $actualField): void { [$expectTable, $expectColumn] = explode('.', $expectField); @@ -138,7 +152,7 @@ protected function assertSameSchema(string $expectField, string $actualField): v } protected function runAll(iterable $tasks): void { - $queue = Civi::queue('snaptest', ['type' => 'Memory']); + $queue = Civi::queue('snap-test', ['type' => 'Memory']); foreach ($tasks as $task) { $queue->createItem($task); } diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index b0e2beff7a97..214aa065556d 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -46,7 +46,7 @@ class CRM_Utils_TokenConsistencyTest extends CiviUnitTestCase { * Post test cleanup. */ public function tearDown(): void { - $this->quickCleanup(['civicrm_case', 'civicrm_case_type', 'civicrm_participant', 'civicrm_event'], TRUE); + $this->quickCleanup(['civicrm_case', 'civicrm_case_type'], TRUE); $this->quickCleanUpFinancialEntities(); // WORKAROUND: CRM_Event_Tokens copies `civicrm_event` data into metadata cache. That should probably change, but that's a different scope-of-work. @@ -633,11 +633,9 @@ protected function getMembershipID(): int { /** * Get expected output from token parsing. * - * @param int|null $participantCreatedID - * * @return string */ - protected function getExpectedParticipantTokenOutput(int $participantCreatedID = NULL): string { + protected function getExpectedParticipantTokenOutput(): string { return "participant.status_id :2 participant.role_id :1 participant.register_date :February 19th, 2007 @@ -646,7 +644,7 @@ protected function getExpectedParticipantTokenOutput(int $participantCreatedID = participant.fee_amount :$50.00 participant.registered_by_id : participant.transferred_to_contact_id : -participant.created_id :{$participantCreatedID} +participant.created_id :{$this->ids['Contact']['logged_in']} participant.role_id:label :Attendee participant.balance : participant.custom_2 :99999 @@ -726,7 +724,7 @@ public function testParticipantTokenConsistency(): void { $this->assertEquals(array_merge($tokens, $this->getEventTokens(), $this->getDomainTokens()), $tokenProcessor->listTokens()); $this->callAPISuccess('job', 'send_reminder', []); - $expected = $this->getExpectedParticipantTokenOutput(3); + $expected = $this->getExpectedParticipantTokenOutput(); $mut->checkMailLog([$expected]); $tokenProcessor->addMessage('html', $this->getTokenString(array_keys($this->getParticipantTokens())), 'text/plain'); @@ -881,6 +879,7 @@ public function getDomainTokens(): array { */ public function testEventTokenConsistency(): void { $mut = new CiviMailUtils($this); + $this->createLoggedInUser(); $this->setupParticipantScheduledReminder(); $tokens = array_merge($this->getEventTokens()); @@ -889,7 +888,7 @@ public function testEventTokenConsistency(): void { $expectedEventString = $this->getExpectedEventTokenOutput(); $this->callAPISuccess('job', 'send_reminder', []); - $expectedParticipantString = $this->getExpectedParticipantTokenOutput(5); + $expectedParticipantString = $this->getExpectedParticipantTokenOutput(); $toCheck = array_merge(explode("\n", $expectedEventString), explode("\n", $expectedParticipantString)); $toCheck[] = $expectedEventString; $toCheck[] = $expectedParticipantString; diff --git a/tests/phpunit/Civi/Token/ImpliedContextSubscriberTest.php b/tests/phpunit/Civi/Token/ImpliedContextSubscriberTest.php index 134260b032ec..40d2241e49ce 100644 --- a/tests/phpunit/Civi/Token/ImpliedContextSubscriberTest.php +++ b/tests/phpunit/Civi/Token/ImpliedContextSubscriberTest.php @@ -3,6 +3,11 @@ class ImpliedContextSubscriberTest extends \CiviUnitTestCase { + public function tearDown(): void { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + public function testParticipantImplicitEvent(): void { $participantId = $this->participantCreate(); @@ -15,7 +20,7 @@ public function testParticipantImplicitEvent(): void { public function testParticipantExplicitEvent(): void { $participantId = $this->participantCreate(); - $otherEventId = $this->eventCreateUnpaid(['title' => 'Alternate Event'])['id']; + $otherEventId = $this->eventCreateUnpaid(['title' => 'Alternate Event'], 'second')['id']; $messages = \CRM_Core_TokenSmarty::render( ['text' => 'You may also like {event.title}!'], diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 1d692efdd74a..0690e21edf92 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -30,7 +30,6 @@ use Civi\Api4\Contribution; use Civi\Api4\CustomField; use Civi\Api4\CustomGroup; -use Civi\Api4\Event; use Civi\Api4\ExampleData; use Civi\Api4\FinancialAccount; use Civi\Api4\FinancialType; @@ -1007,40 +1006,6 @@ public function contributionDelete(int $contributionID) { ]); } - /** - * Create an Event. - * - * @param array $params - * Name-value pair for an event. - * @param string|int $identifier - * - * @return array - * - * @throws \CRM_Core_Exception - * - * @noinspection PhpUnhandledExceptionInspection - * @noinspection PhpDocMissingThrowsInspection - */ - public function eventCreate(array $params = [], string $identifier = 'event'): array { - // if no contact was passed, make up a dummy event creator - if (!isset($params['contact_id'])) { - $params['contact_id'] = $this->_contactCreate([ - 'contact_type' => 'Individual', - 'first_name' => 'Event', - 'last_name' => 'Creator', - ]); - } - - $params = array_merge($this->getExampleData('Event', 'PaidEvent'), $params); - - if (!empty($params['payment_processor_id'])) { - $params['payment_processor'] = is_array($params['payment_processor_id']) ? $params['payment_processor_id'] : [$params['payment_processor_id']]; - } - $event = Event::create(FALSE)->setValues($params)->execute()->first(); - $this->ids['Event'][$identifier] = $event['id']; - return $event; - } - /** * Delete event. *