'contact_type' => 'Individual',
'email' => 'test-contact-2@example.com',
'gender_id' => 'Male',
- 'first_name' => 'Fabble',
+ 'first_name' => 'Fabio',
'last_name' => 'Fi',
];
$this->fixtures['contact_birthdate'] = [
'is_deceased' => 0,
'contact_type' => 'Individual',
- 'email' => 'test-bday@example.com',
+ 'email' => 'test-birth_day@example.com',
'birth_date' => '20050707',
];
$this->fixtures['sched_activity_1day'] = [
'start_action_unit' => '',
'subject' => '1-Day (repeating) (about {activity.activity_type})',
];
- $this->fixtures['sched_eventname_1day_on_abs_date'] = [
- 'name' => 'sched_eventname_1day_on_abs_date',
- 'title' => 'sched_eventname_1day_on_abs_date',
+ $this->fixtures['sched_event_name_1day_on_abs_date'] = [
+ 'name' => 'sched_event_name_1day_on_abs_date',
+ 'title' => 'sched_event_name_1day_on_abs_date',
'limit_to' => 1,
'absolute_date' => CRM_Utils_Date::processDate('20120614100000'),
- 'body_html' => '<p>sched_eventname_1day_on_abs_date</p>',
- 'body_text' => 'sched_eventname_1day_on_abs_date',
+ 'body_html' => '<p>sched_event_name_1day_on_abs_date</p>',
+ 'body_text' => 'sched_event_name_1day_on_abs_date',
'entity_status' => '1',
'entity_value' => '2',
'group_id' => NULL,
'start_action_date' => NULL,
'start_action_offset' => NULL,
'start_action_unit' => NULL,
- 'subject' => 'sched_eventname_1day_on_abs_date',
+ 'subject' => 'sched_event_name_1day_on_abs_date',
];
$this->fixtures['sched_membership_join_2week'] = [
'name' => 'sched_membership_join_2week',
'subject' => 'subject sched_membership_absolute_date',
];
- $this->fixtures['sched_contact_bday_yesterday'] = [
- 'name' => 'sched_contact_bday_yesterday',
- 'title' => 'sched_contact_bday_yesterday',
+ $this->fixtures['sched_contact_birth_day_yesterday'] = [
+ 'name' => 'sched_contact_birth_day_yesterday',
+ 'title' => 'sched_contact_birth_day_yesterday',
'absolute_date' => '',
'body_html' => '<p>you look like you were born yesterday!</p>',
'body_text' => 'you look like you were born yesterday!',
'start_action_date' => 'date_field',
'start_action_offset' => '1',
'start_action_unit' => 'day',
- 'subject' => 'subject sched_contact_bday_yesterday',
+ 'subject' => 'subject sched_contact_birth_day_yesterday',
];
- $this->fixtures['sched_contact_bday_anniv'] = [
- 'name' => 'sched_contact_bday_anniv',
- 'title' => 'sched_contact_bday_anniv',
+ $this->fixtures['sched_contact_birth_day_anniversary'] = [
+ 'name' => 'sched_contact_birth_day_anniversary',
+ 'title' => 'sched_contact_birth_day_anniversary',
'absolute_date' => '',
'body_html' => '<p>happy birthday!</p>',
'body_text' => 'happy birthday!',
'start_action_date' => 'date_field',
'start_action_offset' => '1',
'start_action_unit' => 'day',
- 'subject' => 'subject sched_contact_bday_anniv',
+ 'subject' => 'subject sched_contact_birth_day_anniversary',
];
$this->fixtures['sched_contact_grad_tomorrow'] = [
'subject' => 'subject sched_contact_grad_tomorrow',
];
- $this->fixtures['sched_contact_grad_anniv'] = [
- 'name' => 'sched_contact_grad_anniv',
- 'title' => 'sched_contact_grad_anniv',
+ $this->fixtures['sched_contact_grad_anniversary'] = [
+ 'name' => 'sched_contact_grad_anniversary',
+ 'title' => 'sched_contact_grad_anniversary',
'absolute_date' => '',
'body_html' => '<p>dear alum, please send us money.</p>',
'body_text' => 'dear alum, please send us money.',
'start_action_date' => 'date_field',
'start_action_offset' => '1',
'start_action_unit' => 'week',
- 'subject' => 'subject sched_contact_grad_anniv',
+ 'subject' => 'subject sched_contact_grad_anniversary',
];
$this->fixtures['sched_contact_created_yesterday'] = [
'subject' => 'subject sched_contact_created_yesterday',
];
- $this->fixtures['sched_contact_mod_anniv'] = [
- 'name' => 'sched_contact_mod_anniv',
- 'title' => 'sched_contact_mod_anniv',
+ $this->fixtures['sched_contact_mod_anniversary'] = [
+ 'name' => 'sched_contact_mod_anniversary',
+ 'title' => 'sched_contact_mod_anniversary',
'absolute_date' => '',
'body_html' => '<p>You last updated your data last year</p>',
'body_text' => 'Go update your stuff!',
'start_action_date' => 'date_field',
'start_action_offset' => '1',
'start_action_unit' => 'day',
- 'subject' => 'subject sched_contact_mod_anniv',
+ 'subject' => 'subject sched_contact_mod_anniversary',
];
- $this->fixtures['sched_eventtype_start_1week_before'] = [
- 'name' => 'sched_eventtype_start_1week_before',
- 'title' => 'sched_eventtype_start_1week_before',
+ $this->fixtures['sched_event_type_start_1week_before'] = [
+ 'name' => 'sched_event_type_start_1week_before',
+ 'title' => 'sched_event_type_start_1week_before',
'absolute_date' => '',
- 'body_html' => '<p>body sched_eventtype_start_1week_before ({event.title})</p>',
- 'body_text' => 'body sched_eventtype_start_1week_before ({event.title})',
+ 'body_html' => '<p>body sched_event_type_start_1week_before ({event.title})</p>',
+ 'body_text' => 'body sched_event_type_start_1week_before ({event.title})',
'end_action' => '',
'end_date' => '',
'end_frequency_interval' => '',
'start_action_date' => 'event_start_date',
'start_action_offset' => '1',
'start_action_unit' => 'week',
- 'subject' => 'subject sched_eventtype_start_1week_before ({event.title})',
+ 'subject' => 'subject sched_event_type_start_1week_before ({event.title})',
];
- $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'] = [
- 'name' => 'sched_eventtype_end_2month_repeat_twice_2_weeks',
- 'title' => 'sched_eventtype_end_2month_repeat_twice_2_weeks',
+ $this->fixtures['sched_event_type_end_2month_repeat_twice_2_weeks'] = [
+ 'name' => 'sched_event_type_end_2month_repeat_twice_2_weeks',
+ 'title' => 'sched_event_type_end_2month_repeat_twice_2_weeks',
'absolute_date' => '',
- 'body_html' => '<p>body sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}</p>',
- 'body_text' => 'body sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}',
+ 'body_html' => '<p>body sched_event_type_end_2month_repeat_twice_2_weeks {event.title}</p>',
+ 'body_text' => 'body sched_event_type_end_2month_repeat_twice_2_weeks {event.title}',
'end_action' => 'after',
'end_date' => 'event_end_date',
'end_frequency_interval' => '3',
'start_action_date' => 'event_end_date',
'start_action_offset' => '2',
'start_action_unit' => 'month',
- 'subject' => 'subject sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}',
+ 'subject' => 'subject sched_event_type_end_2month_repeat_twice_2_weeks {event.title}',
];
$this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'] = [
'id' => $customField['id'],
'token' => sprintf('{contact.custom_%s}', $customField['id']),
'name' => sprintf('custom_%s', $customField['id']),
- 'value' => 'text ' . substr(sha1(rand()), 0, 7),
+ 'value' => 'text ' . substr(sha1(mt_rand()), 0, 7),
];
$this->_setUp();
'civicrm_action_schedule',
'civicrm_action_log',
'civicrm_membership',
+ 'civicrm_line_item',
'civicrm_participant',
'civicrm_event',
'civicrm_email',
],
];
- // In this example, we autoconvert HTML to text
+ // In this example, we auto-convert HTML to text
$cases[2] = [
// Schedule definition.
[
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
- *
* @dataProvider mailerExamples
- *
*/
- public function testMailer($schedule, $patterns): void {
- $actionSchedule = array_merge($this->fixtures['sched_activity_1day'], $schedule);
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
-
+ public function testMailer(array $schedule, array $patterns): void {
+ $this->createScheduleFromFixtures('sched_activity_1day', $schedule);
$activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phone_call']);
- $this->assertInternalType('numeric', $activity->id);
$contact = $this->callAPISuccess('contact', 'create', array_merge(
$this->fixtures['contact'],
[
$this->createScheduleFromFixtures('sched_activity_1day');
$activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phone_call']);
- $this->assertInternalType('numeric', $activity->id);
$contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']);
$activity->subject = 'Test subject for phone_call';
$activity->save();
$this->createScheduleFromFixtures('sched_activity_1day_r');
$activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phone_call']);
- $this->assertTrue(is_numeric($activity->id));
$contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']);
$activity->save();
$this->createScheduleFromFixtures('sched_activity_1day_r_on_abs_date');
$activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phone_call']);
- $this->assertInternalType('numeric', $activity->id);
$contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']);
$activity->save();
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id]));
- $actionSchedule = $this->fixtures['sched_eventname_1day_on_abs_date'];
+ $actionSchedule = $this->fixtures['sched_event_name_1day_on_abs_date'];
$actionSchedule['entity_value'] = $participant->event_id;
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
// On absolute date set on 2012-06-14
'time' => '2012-06-14 00:00:00',
'recipients' => [['test-event@example.com']],
- 'subjects' => ['sched_eventname_1day_on_abs_date'],
+ 'subjects' => ['sched_event_name_1day_on_abs_date'],
],
[
// Run cron 4 hours later; first message already sent
*/
public function testMembershipDateMatch(): void {
$membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 1]));
- $this->assertInternalType('numeric', $membership->id);
$this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'test-member@example.com',
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
- $actionSchedule = $this->fixtures['sched_membership_join_2week'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ $this->createScheduleFromFixtures('sched_membership_join_2week', ['entity_value' => $membership->membership_type_id]);
// start_date=2012-03-15 ; schedule is 2 weeks after join_date
$this->assertCronRuns([
],
]);
- $actionSchedule = $this->fixtures['sched_membership_start_1week'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ $this->createScheduleFromFixtures('sched_membership_start_1week', ['entity_value' => $membership->membership_type_id]);
// start_date=2012-03-15 ; schedule is 1 weeks after start_date
$this->assertCronRuns([
);
$actionScheduleParams = [
- 'name' => 'sched_contact_bday_yesterday',
- 'title' => 'sched_contact_bday_yesterday',
+ 'name' => 'sched_contact_birth_day_yesterday',
+ 'title' => 'sched_contact_birth_day_yesterday',
'absolute_date' => '',
'body_html' => '<p>you look like you were born yesterday!</p>',
'body_text' => 'you look like you were born yesterday!',
'start_action_date' => 'date_field',
'start_action_offset' => '1',
'start_action_unit' => 'day',
- 'subject' => 'subject sched_contact_bday_yesterday',
+ 'subject' => 'subject sched_contact_birth_day_yesterday',
];
- // Create schedule reminder where parent group ($groupID) is selectd to limit recipients,
+ // Create schedule reminder where parent group ($groupID) is selected to limit recipients,
// which contain a individual contact - $contactID2 and is parent to smart group.
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionScheduleParams);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->callAPISuccess('ActionSchedule', 'create', $actionScheduleParams);
$this->assertCronRuns([
[
// On the birthday, no email.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
*/
public function testMembershipJoinDateNonMatch(): void {
$this->createMembershipFromFixture('rolling_membership', '', ['email' => 'test-member@example.com']);
// Add an alternative membership type, and only send messages for that type
$extraMembershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', []);
- $this->assertInternalType('numeric', $extraMembershipType->id);
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($this->fixtures['sched_membership_join_2week']);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
- $actionScheduleDao->entity_value = $extraMembershipType->id;
- $actionScheduleDao->save();
+ $this->createScheduleFromFixtures('sched_membership_join_2week', ['entity_value' => $extraMembershipType->id]);
// start_date=2012-03-15 ; schedule is 2 weeks after start_date
$this->assertCronRuns([
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
- $actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $this->callAPISuccess('action_schedule', 'create', $actionSchedule);
+ $this->createScheduleFromFixtures('sched_membership_end_2month_repeat_twice_4_weeks', ['entity_value' => $membership->membership_type_id]);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
- $actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $this->callAPISuccess('action_schedule', 'create', $actionSchedule);
+ $this->createScheduleFromFixtures('sched_membership_end_2month_repeat_twice_4_weeks', ['entity_value' => $membership->membership_type_id]);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
[
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
*/
public function testMembershipEndDateMatch(): void {
// creates membership with end_date = 20120615
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
- $actionSchedule = $this->fixtures['sched_membership_end_2week'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->createScheduleFromFixtures('sched_membership_end_2week', ['entity_value' => $membership->membership_type_id]);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
* @return array|NULL|object
* @throws \CRM_Core_Exception
*/
- public function createMembershipAndContact($contactFixture, $membershipTypeId) {
+ public function createMembershipAndContact(array $contactFixture, int $membershipTypeId) {
$result = $this->callAPISuccess('contact', 'create', $contactFixture);
$contact = $result['values'][$result['id']];
$params = [
'owner_membership_id' => 'NULL',
];
$params = array_merge($this->fixtures['rolling_membership'], $params);
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', $params);
- $this->assertInternalType('numeric', $membership->id);
- return $membership;
+ return $this->createTestObject('CRM_Member_DAO_Membership', $params);
}
/**
$membershipTypeId = $this->membershipTypeCreate($this->fixtures['rolling_membership']['membership_type_id']);
$membershipOne = $this->createMembershipAndContact($this->fixtures['contact'], $membershipTypeId);
$membershipTwo = $this->createMembershipAndContact($this->fixtures['contact_2'], $membershipTypeId);
- $actionSchedule = $this->fixtures['sched_membership_end_2week'];
- $actionSchedule['entity_value'] = $membershipTypeId;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->createScheduleFromFixtures('sched_membership_end_2week', ['entity_value' => $membershipTypeId]);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
'email' => 'test-member@example.com',
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
-
- $actionSchedule = $this->fixtures['sched_membership_end_2month'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->createScheduleFromFixtures('sched_membership_end_2month', ['entity_value' => $membership->membership_type_id]);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
/**
* @throws \CRM_Core_Exception
*/
- public function testContactBirthDateNoAnniv(): void {
+ public function testContactBirthDateNoAnniversary(): void {
$contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']);
$this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id'];
- $actionSchedule = $this->fixtures['sched_contact_bday_yesterday'];
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ $this->createScheduleFromFixtures('sched_contact_birth_day_yesterday');
$this->assertCronRuns([
[
// On the birthday, no email.
[
// The next day, send an email.
'time' => '2005-07-08 20:00:00',
- 'recipients' => [['test-bday@example.com']],
+ 'recipients' => [['test-birth_day@example.com']],
],
]);
}
public function testContactBirthDateAnniversary(): void {
$contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']);
$this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id'];
- $actionSchedule = $this->fixtures['sched_contact_bday_anniv'];
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->createScheduleFromFixtures('sched_contact_birth_day_anniversary');
$this->assertCronRuns([
[
// On some random day, no email.
[
// On the eve of their 9th birthday, send an email.
'time' => '2014-07-06 20:00:00',
- 'recipients' => [['test-bday@example.com']],
+ 'recipients' => [['test-birth_day@example.com']],
],
]);
}
$contactParams["custom_{$createField['id']}"] = '2013-12-16';
$contact = $this->callAPISuccess('Contact', 'create', $contactParams);
$this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id'];
- $actionSchedule = $this->fixtures['sched_contact_grad_tomorrow'];
- $actionSchedule['entity_value'] = "custom_{$createField['id']}";
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->createScheduleFromFixtures('sched_contact_grad_tomorrow', ['entity_value' => "custom_{$createField['id']}"]);
$this->assertCronRuns([
[
// On some random day, no email.
[
// The next day, send an email.
'time' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['created_date'] . ' +1 day')),
- 'recipients' => [['test-bday@example.com']],
+ 'recipients' => [['test-birth_day@example.com']],
],
]);
}
$contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']);
$this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id'];
$modifiedDate = $this->callAPISuccess('Contact', 'getvalue', ['id' => $contact['id'], 'return' => 'modified_date']);
- $actionSchedule = $this->fixtures['sched_contact_mod_anniv'];
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ $this->createScheduleFromFixtures('sched_contact_mod_anniversary');
$this->assertCronRuns([
[
// On some random day, no email.
[
// On the eve of 3 years after they were modified, send an email.
'time' => date('Y-m-d H:i:s', strtotime($modifiedDate . ' +3 years -1 day')),
- 'recipients' => [['test-bday@example.com']],
+ 'recipients' => [['test-birth_day@example.com']],
],
]);
}
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
*/
public function testMembershipLimitToNone(): void {
// creates membership with end_date = 20120615
$this->assertAPISuccess($result);
- $actionSchedule = $this->fixtures['sched_membership_end_limit_to_none'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->createScheduleFromFixtures('sched_membership_end_limit_to_none', ['entity_value' => $membership->membership_type_id]);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
*/
public function testMembershipWithReferenceDate(): void {
$membership = $this->createMembershipFromFixture('rolling_membership', 'Current', ['email' => 'member@example.com']);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
- $actionSchedule = $this->fixtures['sched_membership_join_2week'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ $this->createScheduleFromFixtures('sched_membership_join_2week', ['entity_value' => $membership->membership_type_id]);
// start_date=2012-03-15 ; schedule is 2 weeks after start_date
$this->assertCronRuns([
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
*/
public function testMembershipOnMultipleReminder(): void {
$membership = $this->createMembershipFromFixture('rolling_membership', 'Current', ['email' => 'member@example.com']);
$actionScheduleBefore['entity_value'] = $actionScheduleOn['entity_value'] = $actionScheduleAfter['entity_value'] = $membership->membership_type_id;
foreach (['actionScheduleBefore', 'actionScheduleOn', 'actionScheduleAfter'] as $value) {
$$value = CRM_Core_BAO_ActionSchedule::add($$value);
- $this->assertInternalType('numeric', $$value->id);
}
$this->assertCronRuns(
$contactParams["custom_{$createField['id']}"] = '2013-12-16';
$contact = $this->callAPISuccess('Contact', 'create', $contactParams);
$this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id'];
- $actionSchedule = $this->fixtures['sched_contact_grad_anniv'];
- $actionSchedule['entity_value'] = "custom_{$createField['id']}";
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->fixtures['sched_contact_grad_anniversary']['entity_value'] = "custom_{$createField['id']}";
+ $this->createScheduleFromFixtures('sched_contact_grad_anniversary');
+
$this->assertCronRuns([
[
// On some random day, no email.
$this->participantCreate(['contact_id' => $contact, 'event_id' => $event['id']]);
//Create a scheduled reminder to send email 7 days before registration date.
- $actionSchedule = $this->fixtures['sched_eventtype_start_1week_before'];
+ $actionSchedule = $this->fixtures['sched_event_type_start_1week_before'];
$actionSchedule['start_action_offset'] = 7;
$actionSchedule['start_action_unit'] = 'day';
$actionSchedule['start_action_date'] = 'registration_end_date';
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id]));
- $actionSchedule = $this->fixtures['sched_eventtype_start_1week_before'];
+ $actionSchedule = $this->fixtures['sched_event_type_start_1week_before'];
$actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id]));
- $actionSchedule = $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'];
+ $actionSchedule = $this->fixtures['sched_event_type_end_2month_repeat_twice_2_weeks'];
$actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
* - recipients: array(array(string)), list of email addresses which should receive messages
*
* @throws \CRM_Core_Exception
+ * @noinspection DisconnectedForeachInstructionInspection
*/
- public function assertCronRuns($cronRuns): void {
+ public function assertCronRuns(array $cronRuns): void {
foreach ($cronRuns as $cronRun) {
CRM_Utils_Time::setTime($cronRun['time']);
$this->callAPISuccess('job', 'send_reminder', []);
* @param array $objects
* DAO or BAO objects.
*/
- public function registerTestObjects($objects): void {
+ public function registerTestObjects(array $objects): void {
//if (is_object($objects)) {
// $objects = array($objects);
//}
foreach ($objects as $object) {
- $daoName = preg_replace('/_BAO_/', '_DAO_', get_class($object));
+ $daoName = str_replace('_BAO_', '_DAO_', get_class($object));
$this->_testObjects[$daoName][] = $object->id;
}
}
/**
* Test that the various repetition units work correctly.
+ *
* @see https://issues.civicrm.org/jira/browse/CRM-17028
+ * @throws \CRM_Core_Exception
*/
public function testRepetitionFrequencyUnit(): void {
$membershipTypeParams = [
$membershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', $membershipTypeParams);
$interval_units = ['hour', 'day', 'week', 'month', 'year'];
foreach ($interval_units as $interval_unit) {
- $membershipEndDate = DateTime::createFromFormat('Y-m-d H:i:s', "2013-03-15 00:00:00");
+ $membershipEndDate = DateTime::createFromFormat('Y-m-d H:i:s', '2013-03-15 00:00:00');
$contactParams = [
'contact_type' => 'Individual',
'first_name' => 'Test',
'is_deceased' => 0,
];
$contact = $this->createTestObject('CRM_Contact_DAO_Contact', $contactParams);
- $this->assertTrue(is_numeric($contact->id));
$emailParams = [
'contact_id' => $contact->id,
'is_primary' => 1,
'email' => "test-member-{$interval_unit}@example.com",
'location_type_id' => 1,
];
- $email = $this->createTestObject('CRM_Core_DAO_Email', $emailParams);
- $this->assertTrue(is_numeric($email->id));
+ $this->createTestObject('CRM_Core_DAO_Email', $emailParams);
$membershipParams = [
'membership_type_id' => $membershipType->id,
'contact_id' => $contact->id,
$actionScheduleParams['repetition_frequency_unit'] = $interval_unit;
$actionScheduleParams['repetition_frequency_interval'] = 2;
$actionSchedule = CRM_Core_BAO_ActionSchedule::add($actionScheduleParams);
- $this->assertTrue(is_numeric($actionSchedule->id));
$beforeEndDate = $this->createModifiedDateTime($membershipEndDate, '-1 day');
$beforeFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+1 $interval_unit");
$afterFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+2 $interval_unit");
// Test a reminder for the first membership type - that should exclude Black
// Sheep.
- $actionSchedule = $this->fixtures['sched_membership_join_2week'];
- $actionSchedule['entity_value'] = $membershipType1->id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertTrue(is_numeric($actionScheduleDao->id));
+ $this->fixtures['sched_membership_join_2week']['entity_value'] = $membershipType1->id;
+ $this->createScheduleFromFixtures('sched_membership_join_2week');
$this->assertCronRuns([
[
// Test a reminder for the second membership type - that should include
// Black Sheep.
- $actionSchedule = $this->fixtures['sched_membership_start_1week'];
- $actionSchedule['entity_value'] = $membershipType2->id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ $this->fixtures['sched_membership_start_1week']['entity_value'] = $membershipType2->id;
+ $this->createScheduleFromFixtures('sched_membership_start_1week');
$this->assertCronRuns([
[
*
* @return DateTime
*/
- public function createModifiedDateTime($origDateTime, $modifyRule): \DateTime {
+ public function createModifiedDateTime(DateTime $origDateTime, string $modifyRule): DateTime {
$newDateTime = clone($origDateTime);
$newDateTime->modify($modifyRule);
return $newDateTime;
]);
$this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
- $actionSchedule = $this->fixtures['sched_membership_absolute_date'];
- $actionSchedule['entity_value'] = $membership->membership_type_id;
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ $this->fixtures['sched_membership_absolute_date']['entity_value'] = $membership->membership_type_id;
+ $this->createScheduleFromFixtures('sched_membership_absolute_date');
$this->assertCronRuns([
[
*
* @return \CRM_Member_DAO_Membership
* @throws \API_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
*/
- protected function createMembershipFromFixture($fixture, $status, $emailParams = []): \CRM_Member_DAO_Membership {
+ protected function createMembershipFromFixture(string $fixture, string $status, $emailParams = []): CRM_Member_DAO_Membership {
/* @var CRM_Member_DAO_Membership $membership */
$membership = $this->createTestObject(
'CRM_Member_DAO_Membership',
array_merge($this->fixtures[$fixture], ['status_id' => CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', $status)])
);
- $this->assertInternalType('numeric', $membership->id);
if ($emailParams) {
Civi\Api4\Email::create(FALSE)->setValues(array_merge([
'contact_id' => $membership->contact_id,
* Create action schedule from defined fixtures.
*
* @param string $fixture
+ * @param array $extraParams
+ *
+ * @throws \CRM_Core_Exception
*/
- protected function createScheduleFromFixtures($fixture): void {
- $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($this->fixtures[$fixture]);
- $this->assertInternalType('numeric', $actionScheduleDao->id);
+ protected function createScheduleFromFixtures(string $fixture, $extraParams = []): void {
+ $id = $this->callAPISuccess('ActionSchedule', 'create', array_merge($this->fixtures[$fixture], $extraParams))['id'];
+ $this->fixtures[$fixture]['action_schedule_id'] = (int) $id;
}
}