4 * File for the TestActivityType class
10 * This file is part of CiviCRM
12 * CiviCRM is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * CiviCRM is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
22 * You should have received a copy of the GNU Affero General Public
23 * License along with this program. If not, see
24 * <http://www.gnu.org/licenses/>.
28 * Test CRM/Member/BAO Membership Log add , delete functions
33 class CRM_Member_BAO_MembershipLogTest
extends CiviUnitTestCase
{
38 private $relationshipTypeID;
43 private $organizationContactID;
48 private $financialTypeID;
53 private $membershipStatusID;
58 private $membershipTypeID;
63 * @throws \CRM_Core_Exception
64 * @throws \CiviCRM_API3_Exception
66 public function setUp() {
70 'contact_type_a' => 'Individual',
71 'contact_type_b' => 'Organization',
72 'name_a_b' => 'Test Employee of',
73 'name_b_a' => 'Test Employer of',
75 $this->relationshipTypeID
= $this->relationshipTypeCreate($params);
76 $this->organizationContactID
= $this->organizationCreate();
77 $this->financialTypeID
= 1;
80 'name' => 'test type',
81 'description' => NULL,
83 'duration_unit' => 'year',
84 'member_of_contact_id' => $this->organizationContactID
,
85 'period_type' => 'fixed',
86 'fixed_period_start_day' => '0101',
87 'fixed_period_rollover_day' => '0101',
88 'duration_interval' => 1,
89 'financial_type_id' => $this->financialTypeID
,
90 'relationship_type_id' => $this->relationshipTypeID
,
91 'visibility' => 'Public',
94 $membershipType = CRM_Member_BAO_MembershipType
::add($params);
95 $this->membershipTypeID
= $membershipType->id
;
96 $this->membershipStatusID
= $this->membershipStatusCreate('test status');
100 * Tears down the fixture.
102 * @throws \CRM_Core_Exception
104 public function tearDown() {
105 $this->relationshipTypeDelete($this->relationshipTypeID
);
106 $this->quickCleanUpFinancialEntities();
107 $this->restoreMembershipTypes();
108 $this->contactDelete($this->organizationContactID
);
115 * @throws \CRM_Core_Exception
116 * @throws \CiviCRM_API3_Exception
118 public function testDel() {
119 list($contactID, $membershipID) = $this->setupMembership();
120 CRM_Member_BAO_MembershipLog
::del($membershipID);
121 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $membershipID, 'membership_id',
122 'id', 'Database check for deleted membership log.'
125 $this->membershipDelete($membershipID);
126 $this->contactDelete($contactID);
130 * Test reset modified ID.
132 * @throws \CRM_Core_Exception
134 public function testResetModifiedID() {
135 list($contactID, $membershipID) = $this->setupMembership();
136 CRM_Member_BAO_MembershipLog
::resetModifiedID($contactID);
137 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactID, 'modified_id',
138 'modified_id', 'Database check for NULL modified id.'
141 $this->membershipDelete($membershipID);
142 $this->contactDelete($contactID);
146 * Test that the value for modified_id can be set.
148 * @throws \CRM_Core_Exception
150 public function testCreateMembershipWithPassedInModifiedID() {
151 $modifier = $this->individualCreate();
152 $membershipID = $this->setupMembership($modifier)[1];
153 $this->assertEquals($modifier, $this->callAPISuccessGetValue('MembershipLog', ['membership_id' => $membershipID, 'return' => 'modified_id']));
159 * @param int|null $modifiedID
163 * @throws \CRM_Core_Exception
165 private function setupMembership($modifiedID = NULL): array {
166 $contactID = $this->individualCreate();
167 $modifiedID = $modifiedID ??
$contactID;
170 'contact_id' => $contactID,
171 'membership_type_id' => $this->membershipTypeID
,
172 'join_date' => date('Ymd', strtotime('2006-01-21')),
173 'start_date' => date('Ymd', strtotime('2006-01-21')),
174 'end_date' => date('Ymd', strtotime('2006-12-21')),
175 'source' => 'Payment',
177 'status_id' => $this->membershipStatusID
,
178 'modified_id' => $modifiedID,
181 $membershipID = $this->callAPISuccess('Membership', 'create', $params)['id'];
182 $this->assertEquals($modifiedID, CRM_Core_DAO
::singleValueQuery(
183 'SELECT modified_id FROM civicrm_membership_log WHERE membership_id = %1',
184 [1 => [$membershipID, 'Integer']]
186 return [$contactID, $membershipID];