Skip to content

Commit

Permalink
Remove now unsed createEvent test function
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 3, 2023
1 parent 3001e23 commit 3aa1913
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 50 deletions.
28 changes: 21 additions & 7 deletions tests/phpunit/CRM/Upgrade/SnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
Expand All @@ -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++) {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
13 changes: 6 additions & 7 deletions tests/phpunit/CRM/Utils/TokenConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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());
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion tests/phpunit/Civi/Token/ImpliedContextSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

class ImpliedContextSubscriberTest extends \CiviUnitTestCase {

public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
parent::tearDown();
}

public function testParticipantImplicitEvent(): void {
$participantId = $this->participantCreate();

Expand All @@ -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}!'],
Expand Down
35 changes: 0 additions & 35 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 3aa1913

Please sign in to comment.