From a5422b2730a3e4031206455d99c6f42ad2461700 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 28 Sep 2021 15:05:30 -0700 Subject: [PATCH] (REF) WorkflowMessage - Emphasize the newer 'workflow' instead of 'valueName' --- .../Traits/ReflectiveWorkflowTrait.php | 6 +++--- Civi/WorkflowMessage/WorkflowMessage.php | 3 +-- .../ExampleWorkflowMessageTest.php | 20 +++++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php b/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php index a19958eb8f..f10fe04113 100644 --- a/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php +++ b/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php @@ -250,7 +250,7 @@ trait ReflectiveWorkflowTrait { */ protected function exportExtraEnvelope(array &$export): void { if ($wfName = \CRM_Utils_Constant::value(static::CLASS . '::WORKFLOW')) { - $export['valueName'] = $wfName; + $export['workflow'] = $wfName; } if ($wfGroup = \CRM_Utils_Constant::value(static::CLASS . '::GROUP')) { $export['groupName'] = $wfGroup; @@ -292,8 +292,8 @@ trait ReflectiveWorkflowTrait { */ protected function importExtraEnvelope(array &$values): void { if ($wfName = \CRM_Utils_Constant::value(static::CLASS . '::WORKFLOW')) { - if (isset($values['valueName']) && $wfName === $values['valueName']) { - unset($values['valueName']); + if (isset($values['workflow']) && $wfName === $values['workflow']) { + unset($values['workflow']); } } if ($wfGroup = \CRM_Utils_Constant::value(static::CLASS . '::GROUP')) { diff --git a/Civi/WorkflowMessage/WorkflowMessage.php b/Civi/WorkflowMessage/WorkflowMessage.php index d164a2f935..7ecf283bdb 100644 --- a/Civi/WorkflowMessage/WorkflowMessage.php +++ b/Civi/WorkflowMessage/WorkflowMessage.php @@ -66,7 +66,7 @@ class WorkflowMessage { public static function create(string $wfName, array $imports = []) { $classMap = static::getWorkflowNameClassMap(); $class = $classMap[$wfName] ?? 'Civi\WorkflowMessage\GenericWorkflowMessage'; - $imports['envelope']['valueName'] = $wfName; + $imports['envelope']['workflow'] = $wfName; $model = new $class(); static::importAll($model, $imports); return $model; @@ -96,7 +96,6 @@ class WorkflowMessage { unset($params['model']); } - if (isset($params['tplParams'])) { $model->import('tplParams', $params['tplParams']); unset($params['tplParams']); diff --git a/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php b/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php index 9e4b2babc9..34766fb0d9 100644 --- a/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php +++ b/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php @@ -33,7 +33,11 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { const WORKFLOW = 'my_example_wf'; - const GROUP = 'my_example_grp'; + /** + * Use this to provide interop with old-style `groupName`. + * @deprecated + */ + const GROUP = 'msg_old_style_grp'; /** * @var string @@ -189,8 +193,8 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { $this->assertEquals(100, $tpl['some_extra_tpl_stuff']); $envelope = $ex->export('envelope'); - $this->assertEquals('my_example_wf', $envelope['valueName']); - $this->assertEquals('my_example_grp', $envelope['groupName']); + $this->assertEquals('my_example_wf', $envelope['workflow']); + $this->assertEquals('msg_old_style_grp', $envelope['groupName']); } /** @@ -247,10 +251,10 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { $tpl = $ex->export('tplParams'); $this->assertEquals(456, $tpl['myImpromputInt']); $this->assertEquals(['is not mentioned anywhere'], $tpl['impromptu_smarty_data']); - $this->assertTrue(!isset($tpl['valueName'])); + $this->assertTrue(!isset($tpl['workflow'])); $envelope = $ex->export('envelope'); - $this->assertEquals('some_impromptu_wf', $envelope['valueName']); + $this->assertEquals('some_impromptu_wf', $envelope['workflow']); $this->assertEquals('foo@example.com', $envelope['from']); $this->assertTrue(!isset($envelope['myProtectedInt'])); @@ -267,7 +271,7 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { $ex = $this->createExample()->setContactId($cid); \Civi::dispatcher()->addListener('hook_civicrm_alterMailParams', function($e) use (&$hookCount) { $hookCount++; - $this->assertEquals('my_example_wf', $e->params['valueName'], 'ExampleWorkflow::WORKFLOW should propagate to params[valueName]'); + $this->assertEquals('my_example_wf', $e->params['workflow'], 'ExampleWorkflow::WORKFLOW should propagate to params[workflow]'); }); $this->assertEquals(0, $hookCount); $rendered = $ex->renderTemplate([ @@ -289,7 +293,7 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { ]); \Civi::dispatcher()->addListener('hook_civicrm_alterMailParams', function($e) use (&$hookCount) { $hookCount++; - $this->assertEquals('some_impromptu_wf', $e->params['valueName'], 'Adhoc name should propagate to params[workflow]'); + $this->assertEquals('some_impromptu_wf', $e->params['workflow'], 'Adhoc name should propagate to params[workflow]'); }); $this->assertEquals(0, $hookCount); $rendered = $ex->renderTemplate([ @@ -318,7 +322,7 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { \Civi::dispatcher()->addListener('hook_civicrm_alterMailParams', function($e) use (&$hookCount) { $hookCount++; - $this->assertEquals('petition_sign', $e->params['valueName']); + $this->assertEquals('petition_sign', $e->params['workflow']); }); $this->assertEquals(0, $hookCount); $rendered = $ex->renderTemplate(); -- 2.25.1