(REF) WorkflowMessage - Emphasize the newer 'workflow' instead of 'valueName'
authorTim Otten <totten@civicrm.org>
Tue, 28 Sep 2021 22:05:30 +0000 (15:05 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 28 Sep 2021 22:30:07 +0000 (15:30 -0700)
Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php
Civi/WorkflowMessage/WorkflowMessage.php
tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php

index a19958eb8f11c0bf297c3aa7ce459d004f11771c..f10fe04113e9c6192fa182cf2af0164ac850b5f6 100644 (file)
@@ -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')) {
index d164a2f935f21cf08a5b8f70247e7b03c69a4a67..7ecf283bdbe50a8bbaa6b5ab827a9ff17263cfb4 100644 (file)
@@ -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']);
index 9e4b2babc9d99ea4632975f2b3b49d88a4e47ca4..34766fb0d9a125526061fd1e97642ddf7e9b379f 100644 (file)
@@ -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();