(NFC) ContactJoinTest - Ensure that ambiguous state is matched to country
authorTim Otten <totten@civicrm.org>
Fri, 10 Feb 2023 06:52:27 +0000 (22:52 -0800)
committerTim Otten <totten@civicrm.org>
Fri, 10 Feb 2023 22:12:08 +0000 (14:12 -0800)
Before: There is one test using 'AK' -- in the US.

After: There are two tests using 'AK -- in the US and in Nigeria.

tests/phpunit/api/v4/Entity/ContactJoinTest.php

index 9f7d026e12976e9af2fd9fe98e8018ea5887af78..f68ae8c7f2001cb218a8a22a621ccbd8097f17a0 100644 (file)
@@ -117,6 +117,7 @@ class ContactJoinTest extends Api4TestBase {
       ->execute();
     $this->assertCount(1, $addr);
     $this->assertEquals('Hello', $contact['address_billing.city']);
+    $this->assertEquals(1001, $contact['address_billing.state_province_id']);
     $this->assertEquals(1228, $contact['address_billing.country_id']);
     $emails = Email::get(FALSE)
       ->addWhere('contact_id', '=', $contact['id'])
@@ -126,6 +127,33 @@ class ContactJoinTest extends Api4TestBase {
     $this->assertEquals('b@test.com', $contact['email_billing.email']);
   }
 
+  /**
+   * This is the same as testCreateWithPrimaryAndBilling, but the ambiguous
+   * state "AK" is resolved within a different country "NG".
+   */
+  public function testCreateWithPrimaryAndBilling_Nigeria() {
+    $contact = $this->createTestRecord('Contact', [
+      'email_primary.email' => 'a@test.com',
+      'email_billing.email' => 'b@test.com',
+      'address_billing.city' => 'Hello',
+      'address_billing.state_province_id:abbr' => 'AK',
+      'address_billing.country_id:abbr' => 'NG',
+    ]);
+    $addr = Address::get(FALSE)
+      ->addWhere('contact_id', '=', $contact['id'])
+      ->execute();
+    $this->assertCount(1, $addr);
+    $this->assertEquals('Hello', $contact['address_billing.city']);
+    $this->assertEquals(3885, $contact['address_billing.state_province_id']);
+    $this->assertEquals(1157, $contact['address_billing.country_id']);
+    $emails = Email::get(FALSE)
+      ->addWhere('contact_id', '=', $contact['id'])
+      ->execute();
+    $this->assertCount(2, $emails);
+    $this->assertEquals('a@test.com', $contact['email_primary.email']);
+    $this->assertEquals('b@test.com', $contact['email_billing.email']);
+  }
+
   public function testUpdateDeletePrimaryAndBilling() {
     $contact = $this->createTestRecord('Contact', [
       'phone_primary.phone' => '12345',