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