From 7b1ed533d5747c6b666edb16110dc8b47b1548c0 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Tue, 2 Oct 2018 10:57:00 -0400 Subject: [PATCH] ensure all valid relationship types are available When adding relationships to search results, ensure all relationship types, including ones that apply to any contact, are available to choose. https://lab.civicrm.org/dev/core/issues/418 --- CRM/Contact/BAO/Relationship.php | 2 +- .../BAO/ContactType/RelationshipTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index df64ddcbba..d25bae75aa 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1469,7 +1469,7 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) $allRelationshipType = CRM_Core_PseudoConstant::relationshipType(); foreach ($allRelationshipType as $key => $type) { - if ($type['contact_type_b'] == $targetContactType) { + if ($type['contact_type_b'] == $targetContactType || empty($type['contact_type_b'])) { $relationshipType[$key . '_a_b'] = $type['label_a_b']; } } diff --git a/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php b/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php index e8651abdde..96c6e05649 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php @@ -299,4 +299,22 @@ DELETE FROM civicrm_contact_type $this->relationshipTypeDelete($relType->id); } + public function testGetAnyToAnyRelTypes() { + // Create an any to any relationship. + $relTypeParams = array( + 'name_a_b' => 'MookieIs', + 'name_b_a' => 'MookieOf', + 'contact_type_a' => '', + 'contact_type_b' => '', + ); + $relType = CRM_Contact_BAO_RelationshipType::add($relTypeParams); + $indTypes = CRM_Contact_BAO_Relationship::getRelationType('Individual'); + $orgTypes = CRM_Contact_BAO_Relationship::getRelationType('Organization'); + + $this->assertContains('MookieIs', $indTypes); + $this->assertContains('MookieIs', $orgTypes); + $this->relationshipTypeDelete($relType->id); + + } + } -- 2.25.1