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