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