Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Import_ContributionTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Import_ContributionTest extends ImportCiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testContributionImportIndividual() { |
6a488035 TO |
39 | |
40 | $this->webtestLogin(); | |
41 | ||
42 | // Get sample import data. | |
43 | list($headers, $rows) = $this->_contributionIndividualCSVData(); | |
44 | ||
45 | // Create and import csv from provided data and check imported data. | |
46 | $fieldMapper = array( | |
47 | 'mapper[0][0]' => 'email', | |
48 | 'mapper[2][0]' => 'financial_type', | |
49 | 'mapper[4][0]' => 'total_amount', | |
50 | ); | |
51 | $this->importCSVComponent('Contribution', $headers, $rows, 'Individual', 'Insert new contributions', $fieldMapper); | |
52 | } | |
53 | ||
00be9182 | 54 | public function testContributionImportOrganization() { |
6a488035 TO |
55 | |
56 | $this->webtestLogin(); | |
57 | ||
58 | // Get sample import data. | |
59 | list($headers, $rows) = $this->_contributionOrganizationCSVData(); | |
60 | $fieldMapper = array( | |
61 | 'mapper[0][0]' => 'organization_name', | |
92915c55 | 62 | 'mapper[2][0]' => 'financial_type', |
6a488035 TO |
63 | 'mapper[4][0]' => 'total_amount', |
64 | ); | |
65 | $this->importCSVComponent('Contribution', $headers, $rows, 'Organization', 'Insert new contributions', $fieldMapper); | |
66 | } | |
67 | ||
00be9182 | 68 | public function testContributionImportHousehold() { |
6a488035 TO |
69 | |
70 | $this->webtestLogin(); | |
71 | ||
72 | // Get sample import data. | |
73 | list($headers, $rows) = $this->_contributionHouseholdCSVData(); | |
74 | $fieldMapper = array( | |
75 | 'mapper[0][0]' => 'household_name', | |
92915c55 | 76 | 'mapper[2][0]' => 'financial_type', |
6a488035 TO |
77 | 'mapper[4][0]' => 'total_amount', |
78 | ); | |
79 | $this->importCSVComponent('Contribution', $headers, $rows, 'Household', 'Insert new contributions', $fieldMapper); | |
80 | } | |
81 | ||
4cbe18b8 EM |
82 | /** |
83 | * @return array | |
84 | */ | |
00be9182 | 85 | public function _contributionIndividualCSVData() { |
6a488035 TO |
86 | $firstName1 = substr(sha1(rand()), 0, 7); |
87 | $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
88 | $this->webtestAddContact($firstName1, 'Anderson', $email1); | |
89 | ||
90 | $firstName2 = substr(sha1(rand()), 0, 7); | |
91 | $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com'; | |
92 | $this->webtestAddContact($firstName2, 'Anderson', $email2); | |
76e86fd8 | 93 | |
6a488035 TO |
94 | $headers = array( |
95 | 'email' => 'Email', | |
96 | 'fee_amount' => 'Fee Amount', | |
97 | 'financial_type' => 'Financial Type', | |
98 | 'contribution_status_id' => 'Contribution Status', | |
99 | 'total_amount' => 'Total Amount', | |
100 | ); | |
101 | ||
102 | $rows = array( | |
103 | array( | |
104 | 'email' => $email1, | |
105 | 'fee_amount' => '200', | |
92915c55 | 106 | 'financial_type' => 'Donation', |
6a488035 TO |
107 | 'contribution_status_id' => 'Completed', |
108 | 'total_amount' => '200', | |
109 | ), | |
110 | array( | |
111 | 'email' => $email2, | |
112 | 'fee_amount' => '400', | |
92915c55 | 113 | 'financial_type' => 'Donation', |
6a488035 TO |
114 | 'contribution_status_id' => 'Completed', |
115 | 'total_amount' => '400', | |
116 | ), | |
117 | ); | |
118 | ||
119 | return array($headers, $rows); | |
120 | } | |
121 | ||
4cbe18b8 EM |
122 | /** |
123 | * @return array | |
124 | */ | |
00be9182 | 125 | public function _contributionHouseholdCSVData() { |
6a488035 TO |
126 | $household1 = substr(sha1(rand()), 0, 7) . ' home'; |
127 | $this->webtestAddHousehold($household1, TRUE); | |
128 | ||
129 | $household2 = substr(sha1(rand()), 0, 7) . ' home'; | |
130 | $this->webtestAddHousehold($household2, TRUE); | |
131 | ||
132 | $headers = array( | |
133 | 'household' => 'Household Name', | |
134 | 'fee_amount' => 'Fee Amount', | |
135 | 'financial_type' => 'financial Type', | |
136 | 'contribution_status_id' => 'Contribution Status', | |
137 | 'total_amount' => 'Total Amount', | |
138 | ); | |
139 | ||
140 | $rows = array( | |
141 | array( | |
142 | 'household' => $household1, | |
143 | 'fee_amount' => '200', | |
92915c55 | 144 | 'financial_type' => 'Donation', |
6a488035 TO |
145 | 'contribution_status_id' => 'Completed', |
146 | 'total_amount' => '200', | |
147 | ), | |
148 | array( | |
149 | 'household' => $household2, | |
150 | 'fee_amount' => '400', | |
92915c55 | 151 | 'financial_type' => 'Donation', |
6a488035 TO |
152 | 'contribution_status_id' => 'Completed', |
153 | 'total_amount' => '400', | |
154 | ), | |
155 | ); | |
156 | ||
157 | return array($headers, $rows); | |
158 | } | |
159 | ||
4cbe18b8 EM |
160 | /** |
161 | * @return array | |
162 | */ | |
00be9182 | 163 | public function _contributionOrganizationCSVData() { |
6a488035 TO |
164 | $organization1 = substr(sha1(rand()), 0, 7) . ' org'; |
165 | $this->webtestAddOrganization($organization1, TRUE); | |
166 | ||
167 | $organization2 = substr(sha1(rand()), 0, 7) . ' org'; | |
168 | $this->webtestAddOrganization($organization2, TRUE); | |
169 | ||
170 | $headers = array( | |
171 | 'organization' => 'Organization Name', | |
172 | 'fee_amount' => 'Fee Amount', | |
173 | 'financial_type' => 'Financial Type', | |
174 | 'contribution_status_id' => 'Contribution Status', | |
175 | 'total_amount' => 'Total Amount', | |
176 | ); | |
177 | ||
178 | $rows = array( | |
179 | array( | |
180 | 'organization' => $organization1, | |
181 | 'fee_amount' => '200', | |
92915c55 | 182 | 'financial_type' => 'Donation', |
6a488035 TO |
183 | 'contribution_status_id' => 'Completed', |
184 | 'total_amount' => '200', | |
185 | ), | |
186 | array( | |
187 | 'organization' => $organization2, | |
188 | 'fee_amount' => '400', | |
92915c55 | 189 | 'financial_type' => 'Donation', |
6a488035 TO |
190 | 'contribution_status_id' => 'Completed', |
191 | 'total_amount' => '400', | |
192 | ), | |
193 | ); | |
194 | ||
195 | return array($headers, $rows); | |
196 | } | |
96025800 | 197 | |
6a488035 | 198 | } |