Add propertyBag handling for getEmail when incoming uses email-5
authoreileen <emcnaughton@wikimedia.org>
Sat, 9 May 2020 00:11:15 +0000 (12:11 +1200)
committereileen <emcnaughton@wikimedia.org>
Sat, 9 May 2020 00:11:30 +0000 (12:11 +1200)
Calling code is often setting email-5. The property bag should iron out this inconsistency, and getEmail (and similar)
should handle the appended billing id. We can't do this in the static property map as it is a calculated variable

Civi/Payment/PropertyBag.php
tests/phpunit/Civi/Payment/PropertyBagTest.php

index c067a1f77ae593a8329009b101f2fc2ae6049d6a..42cfc56079b5c233c87571c1631ebc433de9f884 100644 (file)
@@ -210,6 +210,13 @@ class PropertyBag implements \ArrayAccess {
       // Good, modern name.
       return $prop;
     }
+    // Handling for legacy addition of billing details.
+    if ($newName === NULL && substr($prop, -2) === '-' . \CRM_Core_BAO_LocationType::getBilling()
+      && isset(static::$propMap[substr($prop, 0, -2)])
+    ) {
+      $newName = substr($prop, 0, -2);
+    }
+
     if ($newName === NULL) {
       if ($silent) {
         // Only for use by offsetExists
index e058325366ca9068669fc8673549cf0c112bdb03..4ac3992bfd32f6478cb75e00d9eea452e512c660 100644 (file)
@@ -80,6 +80,15 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt
     $this->assertEquals(123, $propertyBag['contact_id']);
   }
 
+  /**
+   * Test that emails set by the legacy method of 'email-5' can be retrieved with getEmail.
+   */
+  public function testSetBillingEmailLegacy() {
+    $localPropertyBag = new PropertyBag();
+    $localPropertyBag->mergeLegacyInputParams(['email-' . \CRM_Core_BAO_LocationType::getBilling() => 'a@b.com']);
+    $this->assertEquals('a@b.com', $localPropertyBag->getEmail());
+  }
+
   /**
    */
   public function testMergeInputs() {
@@ -88,7 +97,7 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt
       'contactID' => 123,
       'contributionRecurID' => 456,
     ]);
-    $this->assertEquals("We have merged input params into the property bag for now but please rewrite code to not use this.", $propertyBag->lastWarning);
+    $this->assertEquals('We have merged input params into the property bag for now but please rewrite code to not use this.', $propertyBag->lastWarning);
     $this->assertEquals(123, $propertyBag->getContactID());
     $this->assertEquals(456, $propertyBag->getContributionRecurID());
   }