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