From 69f20614ba451ee94fa502c08f71336d7821d625 Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Sun, 16 Aug 2015 13:46:52 +0200 Subject: [PATCH] CRM-13725 - Duplicate relationship should consider custom fields, unit test. ---------------------------------------- * CRM-13725: Make check for duplicate relationship aware of custom fields https://issues.civicrm.org/jira/browse/CRM-13725 --- tests/phpunit/api/v3/RelationshipTest.php | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index f77e87ebfc..40a29eda5f 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -618,6 +618,48 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->relationshipTypeDelete($this->_relTypeID); } + /** + * CRM-13725 - Two relationships of same type with same start and end date + * should be OK if the custom field values differ. + */ + public function testRelationshipCreateDuplicateWithCustomFields() { + $this->createCustomGroup(); + $this->_ids = $this->createCustomField(); + + $custom_params_1 = array( + "custom_{$this->_ids[0]}" => 'Hello! this is custom data for relationship', + "custom_{$this->_ids[1]}" => 'Y', + "custom_{$this->_ids[2]}" => '2009-07-11 00:00:00', + "custom_{$this->_ids[3]}" => 'http://example.com', + ); + + $custom_params_2 = array( + "custom_{$this->_ids[0]}" => 'Hello! this is other custom data', + "custom_{$this->_ids[1]}" => 'Y', + "custom_{$this->_ids[2]}" => '2009-07-11 00:00:00', + "custom_{$this->_ids[3]}" => 'http://example.org', + ); + + $params = array( + 'contact_id_a' => $this->_cId_a, + 'contact_id_b' => $this->_cId_b, + 'relationship_type_id' => $this->_relTypeID, + 'start_date' => '2008-12-20', + 'is_active' => 1, + ); + + $params_1 = array_merge($params, $custom_params_1); + $params_2 = array_merge($params, $custom_params_2); + + $result_1 = $this->callAPISuccess('relationship', 'create', $params_1); + $result_2 = $this->callAPISuccess('relationship', 'create', $params_2); + + $this->assertNotNull($result_2['id']); + $this->assertEquals(0, $result_2['is_error']); + + $this->relationshipTypeDelete($this->_relTypeID); + } + /** * Check with valid params array. */ -- 2.25.1