From: Pradeep Nayak Date: Wed, 19 Nov 2014 16:19:35 +0000 (+0530) Subject: --CRM-10206, added api test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=842ee1947765a6701f921d0c2f60ba6232376d1d;p=civicrm-core.git --CRM-10206, added api test --- diff --git a/tests/phpunit/api/v3/CustomValueTest.php b/tests/phpunit/api/v3/CustomValueTest.php index 6783169926..8a8788cd3e 100644 --- a/tests/phpunit/api/v3/CustomValueTest.php +++ b/tests/phpunit/api/v3/CustomValueTest.php @@ -122,5 +122,55 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { $this->assertEquals('', $result['values'][$thirdCustomField]['1']); $this->assertEquals('value 4', $result['values'][$thirdCustomField]['2']); } -} + + public function testMultipleCustomValues() { + $params = array( + 'first_name' => 'abc3', + 'last_name' => 'xyz3', + 'contact_type' => 'Individual', + 'email' => 'man3@yahoo.com', + 'custom_' . $this->ids['single']['custom_field_id'] => "value 1", + 'custom_' . $this->ids['multi']['custom_field_id'][0] . '-1' => "multi value 1", + 'custom_' . $this->ids['multi']['custom_field_id'][0] . '-2' => "multi value 2", + 'custom_' . $this->ids['multi']['custom_field_id'][1] => "second multi value 1", + ); + + $result = $this->callAPISuccess('Contact', 'create', $params); + $contact_id = $result['id']; + $firstCustomField = $this->ids['multi']['custom_field_id'][1]; + $secondCustomField = $this->ids['single']['custom_field_id']; + $thirdCustomField = $this->ids['multi']['custom_field_id'][0]; + + $createParams = array( + 'contact_type' => 'Individual', + 'id' => $contact_id, + 'custom_' . $firstCustomField . '-1' => "second multi value 2", + 'custom_' . $firstCustomField . '-2' => "second multi value 3", + ); + $result = $this->callAPISuccess('Contact', 'create', $createParams); + + $params = array( + 'id' => $result['id'], + 'entity_id' => $result['id'], + ); + $result = $this->callAPISuccess('CustomValue', 'Get', $params); + // delete the contact + $this->callAPISuccess('contact', 'delete', array('id' => $contact_id)); + + $this->assertEquals($contact_id, $result['values'][$secondCustomField]['entity_id']); + $this->assertEquals('value 1', $result['values'][$secondCustomField]['latest']); + $this->assertEquals('value 1', $result['values'][$secondCustomField][0]); + + $this->assertEquals($contact_id, $result['values'][$thirdCustomField]['entity_id']); + $this->assertEquals('multi value 1', $result['values'][$thirdCustomField][1]); + $this->assertEquals('multi value 2', $result['values'][$thirdCustomField][2]); + + $this->assertEquals($contact_id, $result['values'][$firstCustomField]['entity_id']); + $this->assertEquals('second multi value 1', $result['values'][$firstCustomField][1]); + $this->assertEquals('', $result['values'][$firstCustomField][2]); + $this->assertEquals('second multi value 2', $result['values'][$firstCustomField][3]); + $this->assertEquals('second multi value 3', $result['values'][$firstCustomField][4]); + $this->assertEquals('second multi value 3', $result['values'][$firstCustomField]['latest']); + } +} \ No newline at end of file