7c1fda99272441a9c0b7ee9bd9f110c269bca5b1
[civicrm-core.git] / tests / phpunit / CRM / Member / BAO / MembershipLogTest.php
1 <?php
2
3 /**
4 * File for the TestActivityType class
5 *
6 * (PHP 5)
7 *
8 * @package CiviCRM
9 *
10 * This file is part of CiviCRM
11 *
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.
16 *
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.
21 *
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/>.
25 */
26
27 /**
28 * Test CRM/Member/BAO Membership Log add , delete functions
29 *
30 * @package CiviCRM
31 * @group headless
32 */
33 class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase {
34
35 public function setUp() {
36 parent::setUp();
37
38 $params = array(
39 'contact_type_a' => 'Individual',
40 'contact_type_b' => 'Organization',
41 'name_a_b' => 'Test Employee of',
42 'name_b_a' => 'Test Employer of',
43 );
44 $this->_relationshipTypeId = $this->relationshipTypeCreate($params);
45 $this->_orgContactID = $this->organizationCreate();
46 $this->_financialTypeId = 1;
47
48 $params = array(
49 'name' => 'test type',
50 'description' => NULL,
51 'minimum_fee' => 10,
52 'duration_unit' => 'year',
53 'member_of_contact_id' => $this->_orgContactID,
54 'period_type' => 'fixed',
55 'duration_interval' => 1,
56 'financial_type_id' => $this->_financialTypeId,
57 'relationship_type_id' => $this->_relationshipTypeId,
58 'visibility' => 'Public',
59 'is_active' => 1,
60 );
61 $ids = array();
62 $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
63 $this->_membershipTypeID = $membershipType->id;
64 $this->_mebershipStatusID = $this->membershipStatusCreate('test status');
65 }
66
67 /**
68 * Tears down the fixture, for example, closes a network connection.
69 * This method is called after a test is executed.
70 */
71 public function tearDown() {
72 $this->relationshipTypeDelete($this->_relationshipTypeId);
73 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
74 $this->membershipStatusDelete($this->_mebershipStatusID);
75 $this->contactDelete($this->_orgContactID);
76 }
77
78 /**
79 * Test add()
80 */
81 public function testadd() {
82 $contactId = $this->individualCreate();
83
84 $params = array(
85 'contact_id' => $contactId,
86 'membership_type_id' => $this->_membershipTypeID,
87 'join_date' => date('Ymd', strtotime('2006-01-21')),
88 'start_date' => date('Ymd', strtotime('2006-01-21')),
89 'end_date' => date('Ymd', strtotime('2006-12-21')),
90 'source' => 'Payment',
91 'is_override' => 1,
92 'status_id' => $this->_mebershipStatusID,
93 );
94
95 $ids = array();
96 $membership = CRM_Member_BAO_Membership::create($params, $ids);
97 $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', $membership->id,
98 'membership_id', 'id',
99 'Database checked on membershiplog record.'
100 );
101
102 $this->membershipDelete($membership->id);
103 $this->contactDelete($contactId);
104 }
105
106 /**
107 * Test del()
108 */
109 public function testdel() {
110 $contactId = $this->individualCreate();
111
112 $params = array(
113 'contact_id' => $contactId,
114 'membership_type_id' => $this->_membershipTypeID,
115 'join_date' => date('Ymd', strtotime('2006-01-21')),
116 'start_date' => date('Ymd', strtotime('2006-01-21')),
117 'end_date' => date('Ymd', strtotime('2006-12-21')),
118 'source' => 'Payment',
119 'is_override' => 1,
120 'status_id' => $this->_mebershipStatusID,
121 );
122 $ids = array(
123 'userId' => $contactId,
124 );
125 $membership = CRM_Member_BAO_Membership::create($params, $ids);
126 $membershipDelete = CRM_Member_BAO_MembershipLog::del($membership->id);
127 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $membership->id, 'membership_id',
128 'id', 'Database check for deleted membership log.'
129 );
130
131 $this->membershipDelete($membership->id);
132 $this->contactDelete($contactId);
133 }
134
135 /**
136 * Test resetmodified()
137 */
138 public function testresetmodifiedId() {
139 $contactId = $this->individualCreate();
140
141 $params = array(
142 'contact_id' => $contactId,
143 'membership_type_id' => $this->_membershipTypeID,
144 'join_date' => date('Ymd', strtotime('2006-01-21')),
145 'start_date' => date('Ymd', strtotime('2006-01-21')),
146 'end_date' => date('Ymd', strtotime('2006-12-21')),
147 'source' => 'Payment',
148 'is_override' => 1,
149 'status_id' => $this->_mebershipStatusID,
150 );
151 $ids = array(
152 'userId' => $contactId,
153 );
154 $membership = CRM_Member_BAO_Membership::create($params, $ids);
155 $resetModifiedId = CRM_Member_BAO_MembershipLog::resetModifiedID($contactId);
156 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactId, 'modified_id',
157 'modified_id', 'Database check for NULL modified id.'
158 );
159
160 $this->membershipDelete($membership->id);
161 $this->contactDelete($contactId);
162 }
163
164 }