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/>.
27 use Civi\Api4\MembershipType
;
30 * Test CRM/Member/BAO Membership Log add , delete functions
35 class CRM_Member_BAO_MembershipLogTest
extends CiviUnitTestCase
{
40 private $relationshipTypeID;
45 private $organizationContactID;
50 private $financialTypeID;
55 private $membershipStatusID;
60 private $membershipTypeID;
65 * @throws \CRM_Core_Exception
66 * @throws \API_Exception
68 public function setUp(): void
{
72 'contact_type_a' => 'Individual',
73 'contact_type_b' => 'Organization',
74 'name_a_b' => 'Test Employee of',
75 'name_b_a' => 'Test Employer of',
77 $this->relationshipTypeID
= $this->relationshipTypeCreate($params);
78 $this->organizationContactID
= $this->organizationCreate();
79 $this->financialTypeID
= 1;
82 'name' => 'test type',
83 'description' => NULL,
85 'duration_unit' => 'year',
86 'member_of_contact_id' => $this->organizationContactID
,
87 'period_type' => 'fixed',
88 'fixed_period_start_day' => '0101',
89 'fixed_period_rollover_day' => '0101',
90 'duration_interval' => 1,
91 'financial_type_id' => $this->financialTypeID
,
92 'relationship_type_id' => $this->relationshipTypeID
,
93 'visibility' => 'Public',
96 $this->membershipTypeID
= MembershipType
::create()->setValues($params)->execute()->first()['id'];
97 $this->membershipStatusID
= $this->membershipStatusCreate('test status');
101 * Tears down the fixture.
103 * @throws \API_Exception
105 public function tearDown(): void
{
106 $this->relationshipTypeDelete($this->relationshipTypeID
);
107 $this->quickCleanUpFinancialEntities();
108 $this->restoreMembershipTypes();
109 $this->contactDelete($this->organizationContactID
);
116 * @throws \CRM_Core_Exception
117 * @throws \CiviCRM_API3_Exception
119 public function testDel() {
120 list($contactID, $membershipID) = $this->setupMembership();
121 CRM_Member_BAO_MembershipLog
::del($membershipID);
122 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $membershipID, 'membership_id',
123 'id', 'Database check for deleted membership log.'
126 $this->membershipDelete($membershipID);
127 $this->contactDelete($contactID);
131 * Test reset modified ID.
133 * @throws \CRM_Core_Exception
135 public function testResetModifiedID() {
136 list($contactID, $membershipID) = $this->setupMembership();
137 CRM_Member_BAO_MembershipLog
::resetModifiedID($contactID);
138 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactID, 'modified_id',
139 'modified_id', 'Database check for NULL modified id.'
142 $this->membershipDelete($membershipID);
143 $this->contactDelete($contactID);
147 * Test that the value for modified_id can be set.
149 * @throws \CRM_Core_Exception
151 public function testCreateMembershipWithPassedInModifiedID(): void
{
152 $modifier = $this->individualCreate();
153 $membershipID = $this->setupMembership($modifier)[1];
154 $this->assertEquals($modifier, $this->callAPISuccessGetValue('MembershipLog', ['membership_id' => $membershipID, 'return' => 'modified_id']));
160 * @param int|null $modifiedID
164 * @throws \CRM_Core_Exception
166 private function setupMembership($modifiedID = NULL): array {
167 $contactID = $this->individualCreate();
168 $modifiedID = $modifiedID ??
$contactID;
171 'contact_id' => $contactID,
172 'membership_type_id' => $this->membershipTypeID
,
173 'join_date' => date('Ymd', strtotime('2006-01-21')),
174 'start_date' => date('Ymd', strtotime('2006-01-21')),
175 'end_date' => date('Ymd', strtotime('2006-12-21')),
176 'source' => 'Payment',
178 'status_id' => $this->membershipStatusID
,
179 'modified_id' => $modifiedID,
182 $membershipID = $this->callAPISuccess('Membership', 'create', $params)['id'];
183 $this->assertEquals($modifiedID, CRM_Core_DAO
::singleValueQuery(
184 'SELECT modified_id FROM civicrm_membership_log WHERE membership_id = %1',
185 [1 => [$membershipID, 'Integer']]
187 return [$contactID, $membershipID];