From a12d81e14a4ffb258764a7c3fed804cb7481c044 Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Sat, 5 Sep 2015 20:16:04 +0200 Subject: [PATCH] CRM-13725 - Extra (failing) unit tests. If you have an existing relationship and a new relationship, and the new relationship has the same standard fields than the existing one, but only one of the two relationships has custom fields, CiviCRM will not accept the new relationship, because it will consider the new one as a duplicate. Two unit tests, they will obviously fail. ---------------------------------------- * 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 | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index 40a29eda5f..b23160fb9f 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -660,6 +660,78 @@ 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. In this case, the + * existing relationship does not have custom values, but the new one + * does. + */ + public function testRelationshipCreateDuplicateWithCustomFields2() { + $this->createCustomGroup(); + $this->_ids = $this->createCustomField(); + + $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_1 = 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_2 = array_merge($params_1, $custom_params_2); + + $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); + } + + /** + * CRM-13725 - Two relationships of same type with same start and end date + * should be OK if the custom field values differ. In this case, the + * existing relationship does have custom values, but the new one + * does not. + */ + public function testRelationshipCreateDuplicateWithCustomFields3() { + $this->createCustomGroup(); + $this->_ids = $this->createCustomField(); + + $custom_params_1 = 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_2 = 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_2, $custom_params_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