add missing comments - tests directory
[civicrm-core.git] / tests / phpunit / WebTest / Import / ContributionTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035
TO
27require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28class WebTest_Import_ContributionTest extends ImportCiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testContributionImportIndividual() {
6a488035
TO
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() {
6a488035
TO
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() {
6a488035
TO
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
4cbe18b8
EM
78 /**
79 * @return array
80 */
6a488035
TO
81 function _contributionIndividualCSVData() {
82 $firstName1 = substr(sha1(rand()), 0, 7);
83 $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
84 $this->webtestAddContact($firstName1, 'Anderson', $email1);
85
86 $firstName2 = substr(sha1(rand()), 0, 7);
87 $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
88 $this->webtestAddContact($firstName2, 'Anderson', $email2);
76e86fd8 89
6a488035
TO
90 $headers = array(
91 'email' => 'Email',
92 'fee_amount' => 'Fee Amount',
93 'financial_type' => 'Financial Type',
94 'contribution_status_id' => 'Contribution Status',
95 'total_amount' => 'Total Amount',
96 );
97
98 $rows = array(
99 array(
100 'email' => $email1,
101 'fee_amount' => '200',
102 'financial_type' => 'Donation',
103 'contribution_status_id' => 'Completed',
104 'total_amount' => '200',
105 ),
106 array(
107 'email' => $email2,
108 'fee_amount' => '400',
109 'financial_type' => 'Donation',
110 'contribution_status_id' => 'Completed',
111 'total_amount' => '400',
112 ),
113 );
114
115 return array($headers, $rows);
116 }
117
4cbe18b8
EM
118 /**
119 * @return array
120 */
6a488035
TO
121 function _contributionHouseholdCSVData() {
122 $household1 = substr(sha1(rand()), 0, 7) . ' home';
123 $this->webtestAddHousehold($household1, TRUE);
124
125 $household2 = substr(sha1(rand()), 0, 7) . ' home';
126 $this->webtestAddHousehold($household2, TRUE);
127
128 $headers = array(
129 'household' => 'Household Name',
130 'fee_amount' => 'Fee Amount',
131 'financial_type' => 'financial Type',
132 'contribution_status_id' => 'Contribution Status',
133 'total_amount' => 'Total Amount',
134 );
135
136 $rows = array(
137 array(
138 'household' => $household1,
139 'fee_amount' => '200',
140 'financial_type' => 'Donation',
141 'contribution_status_id' => 'Completed',
142 'total_amount' => '200',
143 ),
144 array(
145 'household' => $household2,
146 'fee_amount' => '400',
147 'financial_type' => 'Donation',
148 'contribution_status_id' => 'Completed',
149 'total_amount' => '400',
150 ),
151 );
152
153 return array($headers, $rows);
154 }
155
4cbe18b8
EM
156 /**
157 * @return array
158 */
6a488035
TO
159 function _contributionOrganizationCSVData() {
160 $organization1 = substr(sha1(rand()), 0, 7) . ' org';
161 $this->webtestAddOrganization($organization1, TRUE);
162
163 $organization2 = substr(sha1(rand()), 0, 7) . ' org';
164 $this->webtestAddOrganization($organization2, TRUE);
165
166 $headers = array(
167 'organization' => 'Organization Name',
168 'fee_amount' => 'Fee Amount',
169 'financial_type' => 'Financial Type',
170 'contribution_status_id' => 'Contribution Status',
171 'total_amount' => 'Total Amount',
172 );
173
174 $rows = array(
175 array(
176 'organization' => $organization1,
177 'fee_amount' => '200',
178 'financial_type' => 'Donation',
179 'contribution_status_id' => 'Completed',
180 'total_amount' => '200',
181 ),
182 array(
183 'organization' => $organization2,
184 'fee_amount' => '400',
185 'financial_type' => 'Donation',
186 'contribution_status_id' => 'Completed',
187 'total_amount' => '400',
188 ),
189 );
190
191 return array($headers, $rows);
192 }
193}
194