CRM-13252 attempt to replicate multiple phone create
authoreileen <eileen@fuzion.co.nz>
Thu, 5 Sep 2013 08:39:21 +0000 (20:39 +1200)
committereileen <eileen@fuzion.co.nz>
Thu, 5 Sep 2013 08:39:21 +0000 (20:39 +1200)
tests/phpunit/api/v3/ContactTest.php

index 1b03b4f7c8847ff06663b28e8dc3faef150b7cac..a982e88411e81397d63e60388fa2900c432250c3 100644 (file)
@@ -1203,6 +1203,49 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     $this->assertEquals('testGetByUsername', $result['values'][$cid]['first_name']);
   }
 
+  /**
+   * Test to check return works OK
+   */
+  function testContactGetReturnValues() {
+    $extraParams = array('nick_name' => 'Bob', 'phone' => '456', 'email' => 'e@mail.com');
+    $contactID = $this->individualCreate($extraParams);
+    //actually it turns out the above doesn't create a phone
+    $phones = $this->callAPISuccess('phone', 'create', array('contact_id' => $contactID, 'phone' => '456',));
+    $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contactID));
+    foreach ($extraParams as $key => $value) {
+      $this->assertEquals($result[$key], $value);
+    }
+    //now we check they are still returned with 'return' key
+    $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contactID, 'return' => array_keys($extraParams)));
+    foreach ($extraParams as $key => $value) {
+      $this->assertEquals($result[$key], $value);
+    }
+  }
+
+  function testCRM13252MultipleChainedPhones() {
+    $contactID = $this->householdCreate();
+    $this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 0);
+    $params = array(
+     'contact_id' => $contactID,
+     'household_name' => 'Household 1',
+     'contact_type' => 'Household',
+     'api.phone.create' => array(
+        0 => array(
+          'phone' => '111-111-1111',
+          'location_type_id' => 1,
+          'phone_type_id' => 1,
+        ),
+        1 => array(
+          'phone' => '222-222-2222',
+          'location_type_id' => 1,
+          'phone_type_id' => 2,
+        )
+      )
+    );
+    $result = $this->callAPISuccess('contact', 'create', $params);
+    $this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 2);
+
+  }
   /**
    * Test for Contact.get id=@user:username (with an invalid username)
    */