Ian province abbreviation patch - issue 724
[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 public 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 public function tearDown() {
75 $this->relationshipTypeDelete($this->_relationshipTypeId);
76 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
77 $this->membershipStatusDelete($this->_mebershipStatusID);
78 $this->contactDelete($this->_orgContactID);
79 }
80
81 /**
82 * Test add()
83 */
84 public function testadd() {
85 $contactId = Contact::createIndividual();
86
87 $params = array(
88 'contact_id' => $contactId,
89 'membership_type_id' => $this->_membershipTypeID,
90 'join_date' => date('Ymd', strtotime('2006-01-21')),
91 'start_date' => date('Ymd', strtotime('2006-01-21')),
92 'end_date' => date('Ymd', strtotime('2006-12-21')),
93 'source' => 'Payment',
94 'is_override' => 1,
95 'status_id' => $this->_mebershipStatusID,
96 );
97
98 $ids = array();
99 $membership = CRM_Member_BAO_Membership::create($params, $ids);
100 $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', $membership->id,
101 'membership_id', 'id',
102 'Database checked on membershiplog record.'
103 );
104
105 $this->membershipDelete($membership->id);
106 $this->contactDelete($contactId);
107 }
108
109 /**
110 * Test del()
111 */
112 public function testdel() {
113 $contactId = Contact::createIndividual();
114
115 $params = array(
116 'contact_id' => $contactId,
117 'membership_type_id' => $this->_membershipTypeID,
118 'join_date' => date('Ymd', strtotime('2006-01-21')),
119 'start_date' => date('Ymd', strtotime('2006-01-21')),
120 'end_date' => date('Ymd', strtotime('2006-12-21')),
121 'source' => 'Payment',
122 'is_override' => 1,
123 'status_id' => $this->_mebershipStatusID,
124 );
125 $ids = array(
126 'userId' => $contactId,
127 );
128 $membership = CRM_Member_BAO_Membership::create($params, $ids);
129 $membershipDelete = CRM_Member_BAO_MembershipLog::del($membership->id);
130 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $membership->id, 'membership_id',
131 'id', 'Database check for deleted membership log.'
132 );
133
134 $this->membershipDelete($membership->id);
135 $this->contactDelete($contactId);
136 }
137
138 /**
139 * Test resetmodified()
140 */
141 public function testresetmodifiedId() {
142 $contactId = Contact::createIndividual();
143
144 $params = array(
145 'contact_id' => $contactId,
146 'membership_type_id' => $this->_membershipTypeID,
147 'join_date' => date('Ymd', strtotime('2006-01-21')),
148 'start_date' => date('Ymd', strtotime('2006-01-21')),
149 'end_date' => date('Ymd', strtotime('2006-12-21')),
150 'source' => 'Payment',
151 'is_override' => 1,
152 'status_id' => $this->_mebershipStatusID,
153 );
154 $ids = array(
155 'userId' => $contactId,
156 );
157 $membership = CRM_Member_BAO_Membership::create($params, $ids);
158 $resetModifiedId = CRM_Member_BAO_MembershipLog::resetModifiedID($contactId);
159 $this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactId, 'modified_id',
160 'modified_id', 'Database check for NULL modified id.'
161 );
162
163 $this->membershipDelete($membership->id);
164 $this->contactDelete($contactId);
165 }
166
167 }