Skip to content

Commit

Permalink
Add serialization metadata for MembershipType api
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 2, 2019
1 parent 7480315 commit 96c40ac
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CRM/Member/DAO/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Member/MembershipType.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:b166299a8c5c846f5cb4f34fd6532f55)
* (GenCodeChecksum:f0aee394cff9d0c7eee0245021a4a3e1)
*/

/**
Expand Down Expand Up @@ -405,6 +405,7 @@ public static function &fields() {
'entity' => 'MembershipType',
'bao' => 'CRM_Member_BAO_MembershipType',
'localizable' => 0,
'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED,
],
'relationship_direction' => [
'name' => 'relationship_direction',
Expand All @@ -417,6 +418,7 @@ public static function &fields() {
'entity' => 'MembershipType',
'bao' => 'CRM_Member_BAO_MembershipType',
'localizable' => 0,
'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED,
],
'max_related' => [
'name' => 'max_related',
Expand Down
65 changes: 65 additions & 0 deletions tests/phpunit/CRM/Contact/BAO/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,69 @@ public function getRelationshipTypeDuplicates() {
return $data;
}

/**
* Test that two similar memberships are not created for two relationships
*
* @throws \CRM_Core_Exception
*/
public function testSingleMembershipForTwoRelationships() {
$individualID = $this->individualCreate(['display_name' => 'Individual A']);
$organisationID = $this->organizationCreate(['organization_name' => 'Organization B']);
$membershipOrganisationID = $this->organizationCreate(['organization_name' => 'Membership Organization']);
$orgToPersonTypeId1 = $this->relationshipTypeCreate(['name_a_b' => 'Inherited_Relationship_1_A_B', 'name_b_a' => 'Inherited_Relationship_1_B_A']);
$orgToPersonTypeId2 = $this->relationshipTypeCreate(['name_a_b' => 'Inherited_Relationship_2_A_B', 'name_b_a' => 'Inherited_Relationship_2_B_A']);

$membershipType = $this->callAPISuccess('MembershipType', 'create', [
'member_of_contact_id' => $membershipOrganisationID,
'financial_type_id' => 'Member Dues',
'duration_unit' => 'year',
'duration_interval' => 1,
'period_type' => 'rolling',
'name' => 'Inherited Membership',
'relationship_type_id' => [$orgToPersonTypeId1, $orgToPersonTypeId2],
'relationship_direction' => ['b_a', 'a_b'],
]);
$membershipType = $this->callAPISuccessGetSingle('MembershipType', ['id' => $membershipType['id']]);
// Check the metadata worked....
$this->assertEquals([$orgToPersonTypeId1, $orgToPersonTypeId2], $membershipType['relationship_type_id']);
$this->assertEquals(['b_a', 'a_b'], $membershipType['relationship_direction']);

$this->callAPISuccess('Membership', 'create', [
'membership_type_id' => $membershipType['id'],
'contact_id' => $organisationID,
]);

$relationshipOne = $this->callAPISuccess('Relationship', 'create', [
'contact_id_a' => $individualID,
'contact_id_b' => $organisationID,
'relationship_type_id' => $orgToPersonTypeId1,
]);
$relationshipTwo = $this->callAPISuccess('Relationship', 'create', [
'contact_id_a' => $individualID,
'contact_id_b' => $organisationID,
'relationship_type_id' => $orgToPersonTypeId2,
]);

/*
* @todo this section not yet working due to bug in would-be-tested code.
$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
$relationshipTwo['is_active'] = 0;
$this->callAPISuccess('Relationship', 'create', $relationshipTwo);
$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
$relationshipOne['is_active'] = 0;
$this->callAPISuccess('Relationship', 'create', $relationshipOne);
$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 0);
$relationshipOne['is_active'] = 1;
$this->callAPISuccess('Relationship', 'create', $relationshipOne);
$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
$relationshipTwo['is_active'] = 1;
$this->callAPISuccess('Relationship', 'create', $relationshipTwo);
$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
$this->callAPISuccess('Relationship', 'delete', ['id' => $relationshipTwo['id']]);
$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
$this->callAPISuccess('Relationship', 'delete', ['id' => $relationshipOne['id']]);
$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 0);
*/
}

}
2 changes: 2 additions & 0 deletions xml/schema/Member/MembershipType.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<length>64</length>
<comment>FK to Relationship Type ID</comment>
<add>1.5</add>
<serialize>SEPARATOR_TRIMMED</serialize>
</field>
<foreignKey>
<name>relationship_type_id</name>
Expand All @@ -207,6 +208,7 @@
<type>varchar</type>
<length>128</length>
<add>1.7</add>
<serialize>SEPARATOR_TRIMMED</serialize>
</field>
<field>
<name>max_related</name>
Expand Down

0 comments on commit 96c40ac

Please sign in to comment.