Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-11-26-11-43-18
[civicrm-core.git] / tests / phpunit / WebTest / Import / ContributionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28 class WebTest_Import_ContributionTest extends ImportCiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testContributionImportIndividual() {
35
36 $this->webtestLogin();
37
38 // Get sample import data.
39 list($headers, $rows) = $this->_contributionIndividualCSVData();
40
41 // Create and import csv from provided data and check imported data.
42 $fieldMapper = array(
43 'mapper[0][0]' => 'email',
44 'mapper[2][0]' => 'financial_type',
45 'mapper[4][0]' => 'total_amount',
46 );
47 $this->importCSVComponent('Contribution', $headers, $rows, 'Individual', 'Insert new contributions', $fieldMapper);
48 }
49
50 function testContributionImportOrganization() {
51
52 $this->webtestLogin();
53
54 // Get sample import data.
55 list($headers, $rows) = $this->_contributionOrganizationCSVData();
56 $fieldMapper = array(
57 'mapper[0][0]' => 'organization_name',
58 'mapper[2][0]' => 'financial_type',
59 'mapper[4][0]' => 'total_amount',
60 );
61 $this->importCSVComponent('Contribution', $headers, $rows, 'Organization', 'Insert new contributions', $fieldMapper);
62 }
63
64 function testContributionImportHousehold() {
65
66 $this->webtestLogin();
67
68 // Get sample import data.
69 list($headers, $rows) = $this->_contributionHouseholdCSVData();
70 $fieldMapper = array(
71 'mapper[0][0]' => 'household_name',
72 'mapper[2][0]' => 'financial_type',
73 'mapper[4][0]' => 'total_amount',
74 );
75 $this->importCSVComponent('Contribution', $headers, $rows, 'Household', 'Insert new contributions', $fieldMapper);
76 }
77
78 function _contributionIndividualCSVData() {
79 $firstName1 = substr(sha1(rand()), 0, 7);
80 $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
81 $this->webtestAddContact($firstName1, 'Anderson', $email1);
82
83 $firstName2 = substr(sha1(rand()), 0, 7);
84 $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
85 $this->webtestAddContact($firstName2, 'Anderson', $email2);
86
87 $headers = array(
88 'email' => 'Email',
89 'fee_amount' => 'Fee Amount',
90 'financial_type' => 'Financial Type',
91 'contribution_status_id' => 'Contribution Status',
92 'total_amount' => 'Total Amount',
93 );
94
95 $rows = array(
96 array(
97 'email' => $email1,
98 'fee_amount' => '200',
99 'financial_type' => 'Donation',
100 'contribution_status_id' => 'Completed',
101 'total_amount' => '200',
102 ),
103 array(
104 'email' => $email2,
105 'fee_amount' => '400',
106 'financial_type' => 'Donation',
107 'contribution_status_id' => 'Completed',
108 'total_amount' => '400',
109 ),
110 );
111
112 return array($headers, $rows);
113 }
114
115 function _contributionHouseholdCSVData() {
116 $household1 = substr(sha1(rand()), 0, 7) . ' home';
117 $this->webtestAddHousehold($household1, TRUE);
118
119 $household2 = substr(sha1(rand()), 0, 7) . ' home';
120 $this->webtestAddHousehold($household2, TRUE);
121
122 $headers = array(
123 'household' => 'Household Name',
124 'fee_amount' => 'Fee Amount',
125 'financial_type' => 'financial Type',
126 'contribution_status_id' => 'Contribution Status',
127 'total_amount' => 'Total Amount',
128 );
129
130 $rows = array(
131 array(
132 'household' => $household1,
133 'fee_amount' => '200',
134 'financial_type' => 'Donation',
135 'contribution_status_id' => 'Completed',
136 'total_amount' => '200',
137 ),
138 array(
139 'household' => $household2,
140 'fee_amount' => '400',
141 'financial_type' => 'Donation',
142 'contribution_status_id' => 'Completed',
143 'total_amount' => '400',
144 ),
145 );
146
147 return array($headers, $rows);
148 }
149
150 function _contributionOrganizationCSVData() {
151 $organization1 = substr(sha1(rand()), 0, 7) . ' org';
152 $this->webtestAddOrganization($organization1, TRUE);
153
154 $organization2 = substr(sha1(rand()), 0, 7) . ' org';
155 $this->webtestAddOrganization($organization2, TRUE);
156
157 $headers = array(
158 'organization' => 'Organization Name',
159 'fee_amount' => 'Fee Amount',
160 'financial_type' => 'Financial Type',
161 'contribution_status_id' => 'Contribution Status',
162 'total_amount' => 'Total Amount',
163 );
164
165 $rows = array(
166 array(
167 'organization' => $organization1,
168 'fee_amount' => '200',
169 'financial_type' => 'Donation',
170 'contribution_status_id' => 'Completed',
171 'total_amount' => '200',
172 ),
173 array(
174 'organization' => $organization2,
175 'fee_amount' => '400',
176 'financial_type' => 'Donation',
177 'contribution_status_id' => 'Completed',
178 'total_amount' => '400',
179 ),
180 );
181
182 return array($headers, $rows);
183 }
184 }
185