From de00a2b14f60a7f6fef59b5b3331c17fc1e3e061 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 3 Aug 2023 13:14:34 -0400 Subject: [PATCH] ActionSchedule - Update APIs & tests to work with new metadata Before: Name was not automatically generated by the DAO so lots of manual wrangling After: Now that name has a unique index, the DAO handles it automatically --- api/v3/ActionSchedule.php | 14 +++++-- .../CRM/Activity/Form/ActivityTest.php | 1 + .../CRM/Core/BAO/ActionScheduleTest.php | 38 ++++--------------- .../CRM/Core/BAO/RecurringEntityTest.php | 1 + tests/phpunit/api/v3/ActionScheduleTest.php | 5 +++ .../phpunit/api/v3/SyntaxConformanceTest.php | 2 + 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/api/v3/ActionSchedule.php b/api/v3/ActionSchedule.php index 0931d67247..2fb0dae647 100644 --- a/api/v3/ActionSchedule.php +++ b/api/v3/ActionSchedule.php @@ -36,9 +36,6 @@ function civicrm_api3_action_schedule_get($params) { */ function civicrm_api3_action_schedule_create($params) { civicrm_api3_verify_one_mandatory($params, NULL, ['start_action_date', 'absolute_date']); - if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) { - $params['name'] = CRM_Utils_String::munge($params['title']); - } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ActionSchedule'); } @@ -54,6 +51,17 @@ function _civicrm_api3_action_schedule_create_spec(&$params) { $params['title']['api.required'] = TRUE; $params['mapping_id']['api.required'] = TRUE; $params['entity_value']['api.required'] = TRUE; + + // APIv3 doesn't understand dynamic pseudoconstants so just remove them + // to prevent false-positive validation errors. + $params['entity_value']['pseudoconstant'] = NULL; + $params['entity_status']['pseudoconstant'] = NULL; + $params['recipient']['pseudoconstant'] = NULL; + $params['recipient_listing']['pseudoconstant'] = NULL; + $params['start_action_date']['pseudoconstant'] = NULL; + $params['end_date']['pseudoconstant'] = NULL; + $params['filter_contact_language']['pseudoconstant'] = NULL; + $params['communication_language']['pseudoconstant'] = NULL; } /** diff --git a/tests/phpunit/CRM/Activity/Form/ActivityTest.php b/tests/phpunit/CRM/Activity/Form/ActivityTest.php index a9c0e912db..1606517e8f 100644 --- a/tests/phpunit/CRM/Activity/Form/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/Form/ActivityTest.php @@ -99,6 +99,7 @@ class CRM_Activity_Form_ActivityTest extends CiviUnitTestCase { // Create the repeating activity's schedule. $actionScheduleParams = [ + 'title' => 'RepeatingActSchedule', 'used_for' => 'civicrm_activity', 'entity_value' => $repeatingActivityBao->id, 'start_action_date' => $repeatingActivityBao->activity_date_time, diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index 1a6b64919a..ea2b359913 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -136,7 +136,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'birth_date' => '20050707', ]; $this->fixtures['sched_activity_1day'] = [ - 'name' => 'One_Day_Phone_Call_Notice', 'title' => 'One Day Phone Call Notice', 'limit_to' => '1', 'absolute_date' => NULL, @@ -168,7 +167,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'effective_end_date' => '2012-06-15 00:00:00', ]; $this->fixtures['sched_activity_5minute'] = [ - 'name' => 'Five_Minute_Phone_Call_Notice', 'title' => 'Five Minute Phone Call Notice', 'limit_to' => '1', 'absolute_date' => NULL, @@ -198,7 +196,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => '5 minutes (about {activity.activity_type})', ]; $this->fixtures['sched_activity_1day_r'] = [ - 'name' => 'One_Day_Phone_Call_Notice_R', 'title' => 'One Day Phone Call Notice R', 'limit_to' => 1, 'absolute_date' => NULL, @@ -229,7 +226,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'effective_end_date' => '2012-06-14 16:00:00', ]; $this->fixtures['sched_activity_1day_r_on_abs_date'] = [ - 'name' => 'One_Day_Phone_Call_Notice_R', 'title' => 'One Day Phone Call Notice R', 'limit_to' => 1, 'absolute_date' => CRM_Utils_Date::processDate('20120614100000'), @@ -259,7 +255,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => '1-Day (repeating) (about {activity.activity_type})', ]; $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'), @@ -289,7 +284,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => 'sched_event_name_1day_on_abs_date', ]; $this->fixtures['sched_membership_join_2week'] = [ - 'name' => 'sched_membership_join_2week', 'title' => 'sched_membership_join_2week', 'absolute_date' => '', 'body_html' => '

body sched_membership_join_2week

', @@ -318,7 +312,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => 'subject sched_membership_join_2week (joined {membership.join_date})', ]; $this->fixtures['sched_membership_start_1week'] = [ - 'name' => 'sched_membership_start_1week', 'title' => 'sched_membership_start_1week', 'absolute_date' => '', 'body_html' => '

body sched_membership_start_1week

', @@ -347,7 +340,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => 'subject sched_membership_start_1week (joined {membership.start_date})', ]; $this->fixtures['sched_membership_end_2week'] = [ - 'name' => 'sched_membership_end_2week', 'title' => 'sched_membership_end_2week', 'absolute_date' => '', 'body_html' => '

body sched_membership_end_2week

', @@ -377,7 +369,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'effective_start_date' => '2012-05-01 01:00:00', ]; $this->fixtures['sched_on_membership_end_date'] = [ - 'name' => 'sched_on_membership_end_date', 'title' => 'sched_on_membership_end_date', 'body_html' => '

Your membership expired today

', 'body_text' => 'Your membership expired today', @@ -391,7 +382,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => 'subject send reminder on membership_end_date', ]; $this->fixtures['sched_after_1day_membership_end_date'] = [ - 'name' => 'sched_after_1day_membership_end_date', 'title' => 'sched_after_1day_membership_end_date', 'body_html' => '

Your membership expired yesterday

', 'body_text' => 'Your membership expired yesterday', @@ -406,7 +396,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_membership_end_2month'] = [ - 'name' => 'sched_membership_end_2month', 'title' => 'sched_membership_end_2month', 'absolute_date' => '', 'body_html' => '

body sched_membership_end_2month

', @@ -436,7 +425,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_membership_absolute_date'] = [ - 'name' => 'sched_membership_absolute_date', 'title' => 'sched_membership_absolute_date', 'absolute_date' => CRM_Utils_Date::processDate('20120614100000'), 'body_html' => '

body sched_membership_absolute_date

', @@ -466,7 +454,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_contact_birth_day_yesterday'] = [ - 'name' => 'sched_contact_birth_day_yesterday', 'title' => 'sched_contact_birth_day_yesterday', 'absolute_date' => '', 'body_html' => '

you look like you were born yesterday!

', @@ -496,7 +483,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_contact_birth_day_anniversary'] = [ - 'name' => 'sched_contact_birth_day_anniversary', 'title' => 'sched_contact_birth_day_anniversary', 'absolute_date' => '', 'body_html' => '

happy birthday!

', @@ -526,7 +512,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_contact_grad_tomorrow'] = [ - 'name' => 'sched_contact_grad_tomorrow', 'title' => 'sched_contact_grad_tomorrow', 'absolute_date' => '', 'body_html' => '

congratulations on your graduation!

', @@ -556,7 +541,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_contact_grad_anniversary'] = [ - 'name' => 'sched_contact_grad_anniversary', 'title' => 'sched_contact_grad_anniversary', 'absolute_date' => '', 'body_html' => '

dear alum, please send us money.

', @@ -585,7 +569,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_contact_created_yesterday'] = [ - 'name' => 'sched_contact_created_yesterday', 'title' => 'sched_contact_created_yesterday', 'absolute_date' => '', 'body_html' => '

Your contact was created yesterday

', @@ -615,7 +598,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_contact_mod_anniversary'] = [ - 'name' => 'sched_contact_mod_anniversary', 'title' => 'sched_contact_mod_anniversary', 'absolute_date' => '', 'body_html' => '

You last updated your data last year

', @@ -645,7 +627,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $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' => '

body sched_event_type_start_1week_before ({event.title})

', @@ -677,7 +658,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => 'subject sched_event_type_start_1week_before ({event.title})', ]; $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' => '

body sched_event_type_end_2month_repeat_twice_2_weeks {event.title}

', @@ -710,7 +690,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'] = [ - 'name' => 'sched_membership_end_2month', 'title' => 'sched_membership_end_2month', 'absolute_date' => '', 'body_html' => '

body sched_membership_end_2month

', @@ -739,7 +718,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => 'subject sched_membership_end_2month', ]; $this->fixtures['sched_membership_end_limit_to_none'] = [ - 'name' => 'limit to none', 'title' => 'limit to none', 'absolute_date' => '', 'body_html' => '

body sched_membership_end_2month

', @@ -769,7 +747,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'subject' => 'limit to none', ]; $this->fixtures['sched_on_membership_end_date_repeat_interval'] = [ - 'name' => 'sched_on_membership_end_date', 'title' => 'sched_on_membership_end_date', 'body_html' => '

Your membership expired 1 unit ago

', 'body_text' => 'Your membership expired 1 unit ago', @@ -787,7 +764,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $customGroup = $this->callAPISuccess('CustomGroup', 'create', [ - 'title' => ts('Test Contact Custom group'), + 'title' => 'Test Contact Custom group', 'name' => 'test_contact_cg', 'extends' => 'Contact', 'domain_id' => CRM_Core_Config::domainID(), @@ -817,7 +794,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]; $this->fixtures['sched_on_custom_date'] = [ - 'name' => 'sched_on_custom_date', 'title' => 'sched_on_custom_date', 'body_html' => '

Send reminder before 1 hour of custom date field

', 'body_text' => 'Send reminder on custom date field', @@ -1390,7 +1366,6 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ); $actionScheduleParams = [ - 'name' => 'sched_contact_birth_day_yesterday', 'title' => 'sched_contact_birth_day_yesterday', 'absolute_date' => '', 'body_html' => '

you look like you were born yesterday!

', @@ -1407,7 +1382,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'is_repeat' => '0', 'mapping_id' => 6, 'msg_template_id' => '', - 'recipient' => '2', + 'recipient' => 'group', 'recipient_listing' => '', 'recipient_manual' => '', 'record_activity' => 1, @@ -1887,9 +1862,12 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $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->createScheduleFromFixtures('sched_contact_mod_anniversary'); - $actionSchedule['effective_start_date'] = date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['modified_date'])); - $actionScheduleDao = CRM_Core_BAO_ActionSchedule::writeRecord($actionSchedule); + $this->createScheduleFromFixtures('sched_contact_mod_anniversary'); + $actionSchedule = [ + 'id' => $this->fixtures['sched_contact_mod_anniversary']['action_schedule_id'], + 'effective_start_date' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['modified_date'])), + ]; + CRM_Core_BAO_ActionSchedule::writeRecord($actionSchedule); $this->assertCronRuns([ [ // On some random day, no email. diff --git a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php index 9ac465eb4e..a20b8cd6a4 100644 --- a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php +++ b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php @@ -84,6 +84,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { */ private function createActionSchedule($entity_id, $entity_table) { $params = [ + 'title' => 'My Reminder', "used_for" => $entity_table, "entity_value" => $entity_id, "start_action_date" => date("YmdHis"), diff --git a/tests/phpunit/api/v3/ActionScheduleTest.php b/tests/phpunit/api/v3/ActionScheduleTest.php index 9473b17878..ccfe14a87d 100644 --- a/tests/phpunit/api/v3/ActionScheduleTest.php +++ b/tests/phpunit/api/v3/ActionScheduleTest.php @@ -63,6 +63,11 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase { 'is_active' => 1, 'record_activity' => 1, 'start_action_date' => 'activity_date_time', + 'start_action_offset' => '1', + 'start_action_unit' => 'day', + 'start_action_condition' => 'before', + 'subject' => 'Hello', + 'body_html' => '

Hello

', 'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID, ]; $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 3ae84f73e8..bfd1f4cc98 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -486,6 +486,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { public static function toBeSkipped_updatesingle($sequential = FALSE) { $entitiesWithout = [ 'Attachment', + // This one confuses the test by unsetting some fields based on the values of others + 'ActionSchedule', // pseudo-entity; testUpdateSingleValueAlter doesn't introspect properly on it. Multiple magic fields 'Mailing', 'MailingEventUnsubscribe', -- 2.25.1