Merge pull request #7047 from johanv/CRM-17430-dont_change_domain_version_1st_attempt
[civicrm-core.git] / tests / phpunit / CRM / Member / Import / Parser / MembershipTest.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 * @group headless
32 */
33 class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase {
34 /**
35 * Membership type name used in test function.
36 * @var String
37 */
38 protected $_membershipTypeName = NULL;
39
40 /**
41 * Membership type id used in test function.
42 * @var String
43 */
44 protected $_membershipTypeID = NULL;
45
46 public function setUp() {
47 parent::setUp();
48
49 $params = array(
50 'contact_type_a' => 'Individual',
51 'contact_type_b' => 'Organization',
52 'name_a_b' => 'Test Employee of',
53 'name_b_a' => 'Test Employer of',
54 );
55 $this->_relationshipTypeId = $this->relationshipTypeCreate($params);
56 $this->_orgContactID = $this->organizationCreate();
57 $this->_financialTypeId = 1;
58 $this->_membershipTypeName = 'Mickey Mouse Club Member';
59 $params = array(
60 'name' => $this->_membershipTypeName,
61 'description' => NULL,
62 'minimum_fee' => 10,
63 'duration_unit' => 'year',
64 'member_of_contact_id' => $this->_orgContactID,
65 'period_type' => 'fixed',
66 'duration_interval' => 1,
67 'financial_type_id' => $this->_financialTypeId,
68 'relationship_type_id' => $this->_relationshipTypeId,
69 'visibility' => 'Public',
70 'is_active' => 1,
71 'fixed_period_start_day' => 101,
72 'fixed_period_rollover_day' => 1231,
73 );
74 $ids = array();
75 $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
76 $this->_membershipTypeID = $membershipType->id;
77
78 $this->_mebershipStatusID = $this->membershipStatusCreate('test status');
79 $session = CRM_Core_Session::singleton();
80 $session->set('dateTypes', 1);
81 }
82
83 /**
84 * Tears down the fixture, for example, closes a network connection.
85 * This method is called after a test is executed.
86 */
87 public function tearDown() {
88 $tablesToTruncate = array(
89 'civicrm_membership',
90 'civicrm_membership_log',
91 'civicrm_contribution',
92 'civicrm_membership_payment',
93 );
94 $this->quickCleanup($tablesToTruncate);
95 $this->relationshipTypeDelete($this->_relationshipTypeId);
96 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
97 $this->membershipStatusDelete($this->_mebershipStatusID);
98 $this->contactDelete($this->_orgContactID);
99 }
100
101 /**
102 * Test Import.
103 */
104 public function testImport() {
105 $contactId = $this->individualCreate();
106 $contact2Params = array(
107 'first_name' => 'Anthonita',
108 'middle_name' => 'J.',
109 'last_name' => 'Anderson',
110 'prefix_id' => 3,
111 'suffix_id' => 3,
112 'email' => 'b@c.com',
113 'contact_type' => 'Individual',
114 );
115 $contactId = $this->individualCreate($contact2Params);
116 $year = date('Y') - 1;
117 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
118 $params = array(
119 array(
120 'anthony_anderson@civicrm.org',
121 $this->_membershipTypeID,
122 date('Y-m-d'),
123 ),
124 array(
125 $contact2Params['email'],
126 $this->_membershipTypeName,
127 $startDate2,
128 ),
129 );
130 $fieldMapper = array(
131 'mapper[0][0]' => 'email',
132 'mapper[1][0]' => 'membership_type_id',
133 'mapper[2][0]' => 'membership_start_date',
134 );
135 /*
136
137 $params = array(
138 'contact_id' => $contactId,
139 'membership_type_id' => $this->_membershipTypeID,
140 'join_date' => '2006-01-21',
141 'start_date' => '2006-01-21',
142 'end_date' => '2006-12-21',
143 'source' => 'Payment',
144 'is_override' => 1,
145 'status_id' => $this->_mebershipStatusID,
146 );
147 */
148 $importObject = new CRM_Member_Import_Parser_Membership($fieldMapper);
149 $importObject->init();
150 $importObject->_contactType = 'Individual';
151 foreach ($params as $values) {
152 $this->assertEquals(CRM_Import_Parser::VALID, $importObject->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), $values[0]);
153 }
154 $result = $this->callAPISuccess('membership', 'get', array());
155 $this->assertEquals(2, $result['count']);
156 }
157
158 }