Fixed some contribution pages
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / OnBehalfOfOrganization.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
30 protected $pageno = '';
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testOnBehalfOfOrganization() {
6a488035
TO
36 $this->webtestLogin();
37
38 // create new individual
42daf119
CW
39 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
40 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
41 $email = "{$firstName}.{$lastName}@example.com";
6a488035
TO
42 $contactParams = array(
43 'first_name' => $firstName,
44 'last_name' => $lastName,
45 'email-5' => $email,
46 );
47 $streetAddress = "100 Main Street";
48
49 //adding contact for membership sign up
50 $this->webtestAddContact($firstName, $lastName, $email);
51 $urlElements = $this->parseURL();
52 print_r($urlElements);
53 $cid = $urlElements['queryString']['cid'];
54 $this->assertType('numeric', $cid);
55
56 // We need a payment processor
57 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
58 $processorType = 'Dummy';
59 $pageTitle = substr(sha1(rand()), 0, 7);
60 $rand = 100;
61 $hash = substr(sha1(rand()), 0, 7);
62 $amountSection = TRUE;
63 $payLater = TRUE;
64 $onBehalf = 'optional';
65 $pledges = FALSE;
66 $recurring = FALSE;
67 $memberships = FALSE;
68 $memPriceSetId = NULL;
69 $friend = TRUE;
70 $profilePreId = NULL;
71 $profilePostId = NULL;
72 $premiums = FALSE;
73 $widget = FALSE;
74 $pcp = FALSE;
75 $honoreeSection = FALSE;
76 $isAddPaymentProcessor = TRUE;
77 $isPcpApprovalNeeded = FALSE;
78 $isSeparatePayment = FALSE;
79
80 // create a new online contribution page
81 // create contribution page with randomized title and default params
82 $pageId = $this->webtestAddContributionPage($hash,
83 $rand,
84 $pageTitle,
85 array($processorName => $processorType),
86 $amountSection,
87 $payLater,
88 $onBehalf,
89 $pledges,
90 $recurring,
91 $memberships,
92 $memPriceSetId,
93 $friend,
94 $profilePreId,
95 $profilePostId,
96 $premiums,
97 $widget,
98 $pcp,
99 $isAddPaymentProcessor,
100 $isPcpApprovalNeeded,
101 $isSeparatePayment,
102 $honoreeSection
103 );
104
105 //logout
42daf119 106 $this->webtestLogout();
6a488035 107 //$this->_testAnomoyousOganization($pageId, $cid, $pageTitle);
42daf119 108 $this->webtestLogout();
6a488035 109 $this->_testUserWithOneRelationship($pageId, $cid, $pageTitle);
42daf119 110 $this->webtestLogout();
6a488035
TO
111 $this->_testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle);
112 }
113
114 function testOnBehalfOfOrganizationWithMembershipData() {
6a488035
TO
115 $this->webtestLogin();
116
117 // create new individual
071a6d2e 118 $this->openCiviPage("profile/edit", "reset=1&gid=4");
42daf119
CW
119 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
120 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
6a488035
TO
121
122 $this->waitForPageToLoad($this->getTimeoutMsec());
123 $this->waitForElementPresent("_qf_Edit_next");
124 $this->type("first_name", $firstName);
125 $this->type("last_name", $lastName);
126 $this->click("_qf_Edit_next");
127 $this->waitForPageToLoad($this->getTimeoutMsec());
128 $this->waitForElementPresent("profilewrap4");
129
42daf119 130 // Is status message correct?
6a488035
TO
131 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
132
133 //custom data
42daf119 134
071a6d2e 135 $this->openCiviPage("admin/custom/group", "action=add&reset=1");
6a488035
TO
136
137 //fill custom group title
138 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
139 $this->click("title");
140 $this->type("title", $customGroupTitle);
141
142 //custom group extends
143 $this->click("extends[0]");
144 $this->select("extends[0]", "value=Membership");
145 //$this->click("//option[@value='Contact']");
146 $this->click("_qf_Group_next-bottom");
147 $this->waitForElementPresent("_qf_Field_cancel-bottom");
148
149 //Is custom group created?
150 $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."));
151
152 //add custom field - alphanumeric checkbox
153 $checkboxFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
154 $this->click("label");
155 $this->type("label", $checkboxFieldLabel);
156 $this->click("data_type[1]");
157 $this->select("data_type[1]", "value=CheckBox");
158 $this->click("//option[@value='CheckBox']");
159 $checkboxOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
160 $this->type("option_label_1", $checkboxOptionLabel1);
161 $this->type("option_value_1", "1");
162 $checkboxOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
163 $this->type("option_label_2", $checkboxOptionLabel2);
164 $this->type("option_value_2", "2");
165 $this->click("link=another choice");
166 $checkboxOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
167 $this->type("option_label_3", $checkboxOptionLabel3);
168 $this->type("option_value_3", "3");
169
170 //enter options per line
171 $this->type("options_per_line", "2");
172
173 //enter pre help message
174 $this->type("help_pre", "this is field pre help");
175
176 //enter post help message
177 $this->type("help_post", "this field post help");
178
179 //Is searchable?
180 $this->click("is_searchable");
181
182 //clicking save
183 $this->click("_qf_Field_next");
184 $this->waitForPageToLoad($this->getTimeoutMsec());
185
186 //Is custom field created?
187 $this->assertTrue($this->isTextPresent("Your custom field '$checkboxFieldLabel' has been saved."));
188
189 //create another custom field - Integer Radio
190 $this->click("//a[@id='newCustomField']/span");
191 $this->waitForPageToLoad($this->getTimeoutMsec());
192 $this->click("data_type[0]");
193 $this->select("data_type[0]", "value=1");
194 $this->click("//option[@value='1']");
195 $this->click("data_type[1]");
196 $this->select("data_type[1]", "value=Radio");
197 $this->click("//option[@value='Radio']");
198
199 $radioFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
200 $this->type("label", $radioFieldLabel);
201 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
202 $this->type("option_label_1", $radioOptionLabel1);
203 $this->type("option_value_1", "1");
204 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
205 $this->type("option_label_2", $radioOptionLabel2);
206 $this->type("option_value_2", "2");
207 $this->click("link=another choice");
208 $radioOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
209 $this->type("option_label_3", $radioOptionLabel3);
210 $this->type("option_value_3", "3");
211
212 //select options per line
213 $this->type("options_per_line", "3");
214
215 //enter pre help msg
216 $this->type("help_pre", "this is field pre help");
217
218 //enter post help msg
219 $this->type("help_post", "this is field post help");
220
221 //Is searchable?
222 $this->click("is_searchable");
223
224 //clicking save
225 $this->click("_qf_Field_next");
226 $this->waitForPageToLoad($this->getTimeoutMsec());
227
228 //Is custom field created
229 $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved."));
42daf119 230
6a488035 231 //add the above custom data to the On Behalf of Profile
071a6d2e 232 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035
TO
233 $this->click("link=Reserved Profiles");
234
235 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
236 $this->waitForPageToLoad($this->getTimeoutMsec());
237
238 $this->click("link=Add Field");
239 $this->waitForElementPresent('_qf_Field_next-bottom');
240 $this->select('field_name[0]', 'value=Membership');
241 $label = $checkboxFieldLabel.' :: '. $customGroupTitle;
242 $this->select('field_name[1]', "label=$label");
243 $this->click('field_name[1]');
244 $this->click('_qf_Field_next_new-bottom');
245 $this->waitForPageToLoad($this->getTimeoutMsec());
246
247 $this->select('field_name[0]', 'value=Membership');
248 $label = $radioFieldLabel.' :: '. $customGroupTitle;
249 $this->select('field_name[1]', "label=$label");
250 $this->click('field_name[1]');
251 $this->click('_qf_Field_next-bottom');
252 $this->waitForPageToLoad($this->getTimeoutMsec());
253 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$radioFieldLabel}' has been saved to 'On Behalf Of Organization'."));
254
255 //create organisation
256 $orgName = "Org WebAccess ". substr(sha1(rand()), 0, 7);
257 $orgEmail = "org". substr(sha1(rand()), 0, 7) . "@web.com";
258 $this->webtestAddOrganization($orgName, $orgEmail);
259
260 $this->waitForPageToLoad($this->getTimeoutMsec());
261 $this->click("css=li#tab_member a");
262
263 $this->waitForElementPresent('link=Add Membership');
264 $this->click('link=Add Membership');
265
266 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
267
42daf119 268 // fill in Membership Organization and Type
6a488035
TO
269 $this->select('membership_type_id[0]', "value=1");
270 $this->select('membership_type_id[1]', "value=1");
271
42daf119 272 // fill in Source
6a488035
TO
273 $sourceText = 'On behalf Membership Webtest';
274 $this->type('source', $sourceText);
275
276 $this->waitForElementPresent("css=div#{$customGroupTitle} div.crm-accordion-header");
277 $this->click("css=div#{$customGroupTitle} div.crm-accordion-header");
278 //$this->waitForElementPresent('_qf_Membership_cancel-bottom111');
279
42daf119 280 // select newly created processor
6a488035
TO
281 $xpath = "xpath=//label[text() = '{$checkboxOptionLabel1}']/preceding-sibling::input[1]";
282 $this->assertTrue($this->isTextPresent($checkboxOptionLabel1));
283 $this->check($xpath);
42daf119 284
6a488035
TO
285 $xpath = "xpath=//label[text() = '{$checkboxOptionLabel3}']/preceding-sibling::input[1]";
286 $this->assertTrue($this->isTextPresent($checkboxOptionLabel3));
287 $this->check($xpath);
288
289 $xpath = "xpath=//label[text() = '{$radioOptionLabel1}']/preceding-sibling::input[1]";
290 $this->assertTrue($this->isTextPresent($radioOptionLabel1));
291 $this->check($xpath);
292
293 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
294 $this->click('_qf_Membership_upload-bottom');
295
296
297 $this->waitForPageToLoad($this->getTimeoutMsec());
298 $this->click("css=li#tab_rel a");
299
300 $this->waitForElementPresent('link=Add Relationship');
301 $this->click('link=Add Relationship');
302
303 $this->waitForElementPresent('relationship_type_id');
304 $this->click("relationship_type_id");
305 $this->select("relationship_type_id", "label=Employer of");
42daf119 306 // search organization
6a488035
TO
307 $this->type('contact_1', $firstName);
308 $this->click("contact_1");
309 $this->waitForElementPresent("css=div.ac_results-inner li");
310 $this->click("css=div.ac_results-inner li");
311 $this->assertContains($firstName, $this->getValue('contact_1'), "autocomplete expected $firstName but didn’t find it in " . $this->getValue('contact_1'));
312
42daf119 313 // give permission
6a488035
TO
314 $this->click("is_permission_a_b");
315 $this->click("is_permission_b_a");
316
42daf119 317 // save relationship
6a488035
TO
318 $this->click("details-save");
319 $this->waitForPageToLoad($this->getTimeoutMsec());
42daf119 320
6a488035
TO
321 // We need a payment processor
322 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
323 $processorType = 'Dummy';
324 $pageTitle = substr(sha1(rand()), 0, 7);
325 $rand = 100;
326 $hash = substr(sha1(rand()), 0, 7);
327 $amountSection = TRUE;
328 $payLater = TRUE;
329 $onBehalf = TRUE;
330 $pledges = FALSE;
331 $recurring = FALSE;
332 $memberships = TRUE;
333 $memPriceSetId = NULL;
334 $friend = TRUE;
335 $profilePreId = NULL;
336 $profilePostId = NULL;
337 $premiums = FALSE;
338 $widget = FALSE;
339 $pcp = FALSE;
340 $honoreeSection = FALSE;
341 $isAddPaymentProcessor = TRUE;
342 $isPcpApprovalNeeded = FALSE;
343 $isSeparatePayment = FALSE;
344
345 // create a new online contribution page
346 // create contribution page with randomized title and default params
347 $pageId = $this->webtestAddContributionPage($hash,
348 $rand,
349 $pageTitle,
350 array($processorName => $processorType),
351 $amountSection,
352 $payLater,
353 $onBehalf,
354 $pledges,
355 $recurring,
356 $memberships,
357 $memPriceSetId,
358 $friend,
359 $profilePreId,
360 $profilePostId,
361 $premiums,
362 $widget,
363 $pcp,
364 $isAddPaymentProcessor,
365 $isPcpApprovalNeeded,
366 $isSeparatePayment,
367 $honoreeSection
368 );
42daf119 369
6a488035
TO
370 //check for formRule
371 //scenario 1 : add membership data in pre / post profile and check for formRule
42daf119 372 //add new profile
071a6d2e 373 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035
TO
374 $this->click('link=Add Profile');
375
376 $profileTitle = "test profile" . substr(sha1(rand()), 0, 7);
377 // Add membership custom data field to profile
378 $this->waitForElementPresent('_qf_Group_cancel-bottom');
379 $this->type('title', $profileTitle);
380 $this->click('_qf_Group_next-bottom');
381
382 $this->waitForElementPresent('_qf_Field_cancel-bottom');
383 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."));
384
385 $this->select('field_name[0]', "value=Membership");
386 $this->select('field_name[1]', "label={$checkboxFieldLabel} :: {$customGroupTitle}");
387 $this->click('field_name[1]');
388 $this->click('label');
389
390 // Clicking save and new
391 $this->click('_qf_Field_next_new-bottom');
392 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$checkboxFieldLabel}' has been saved to '{$profileTitle}'."));
42daf119
CW
394
395 $this->openCiviPage("admin/contribute/custom", "reset=1&action=update&id={$pageId}", '_qf_Custom_next-bottom');
6a488035
TO
396 $this->select('custom_pre_id', "label={$profileTitle}");
397 $this->click('_qf_Custom_next-bottom');
398 $this->waitForPageToLoad($this->getTimeoutMsec());
efb29358
CW
399 // Because it tends to cause problems, all uses of sleep() must be justified in comments
400 // Sleep should never be used for wait for anything to load from the server
401 // Justification for this instance: FIXME
6a488035
TO
402 sleep(3);
403 $this->assertTrue($this->isTextPresent('You should move the membership related fields in the "On Behalf" profile for this Contribution Page'), "Form rule didn't showed up while incorrectly configuring membership fields profile for 'on behalf of' contribution page");
42daf119 404
6a488035
TO
405 $this->select('custom_pre_id', "- select -");
406 $this->select('custom_post_id', "label={$profileTitle}");
407 $this->click('_qf_Custom_next-bottom');
408 $this->waitForPageToLoad($this->getTimeoutMsec());
efb29358
CW
409 // Because it tends to cause problems, all uses of sleep() must be justified in comments
410 // Sleep should never be used for wait for anything to load from the server
411 // Justification for this instance: FIXME
6a488035
TO
412 sleep(3);
413 $this->assertTrue($this->isTextPresent('You should move the membership related fields in the "On Behalf" profile for this Contribution Page'), "Form rule didn't showed up while incorrectly configuring membership fields profile for 'on behalf of' contribution page");
42daf119
CW
414
415 //scenario 2 : disable 'on behalf of', add membership data in pre / post profile
6a488035
TO
416 //then try to add 'on behalf of' and check for formRule
417 //disable 'on behalf of'
42daf119 418 $this->openCiviPage("admin/contribute/settings", "reset=1&action=update&id={$pageId}", '_qf_Settings_next-bottom');
6a488035
TO
419 $this->uncheck('is_organization');
420 $this->click('_qf_Settings_next-bottom');
421 $this->waitForPageToLoad($this->getTimeoutMsec());
42daf119 422
6a488035
TO
423 //set a membership field profile for this contribution page
424 $this->click('css=li#tab_custom a');
425 $this->waitForElementPresent('_qf_Custom_next-bottom');
426 $this->select('custom_pre_id', "label={$profileTitle}");
427 $this->click('_qf_Custom_next-bottom');
428 $this->waitForPageToLoad($this->getTimeoutMsec());
429
430 //now visit the title settings page and configure the profile as on behalf of
431 $this->click('css=li#tab_settings a');
432 $this->waitForElementPresent('_qf_Settings_next-bottom');
433 $this->check('is_organization');
434 $this->click('_qf_Settings_next-bottom');
435 $this->waitForPageToLoad($this->getTimeoutMsec());
efb29358
CW
436 // Because it tends to cause problems, all uses of sleep() must be justified in comments
437 // Sleep should never be used for wait for anything to load from the server
438 // Justification for this instance: FIXME
42daf119 439 sleep(3);
6a488035 440 $this->assertTrue($this->isTextPresent("You should move the membership related fields configured in 'Includes Profile (top of page)' to the 'On Behalf' profile for this Contribution Page"), "Form rule 'You should move the membership related fields configured in 'Includes Profile (top of page)' to the 'On Behalf' profile for this Contribution Page' didn't showed up");
42daf119 441
6a488035 442 //logout
42daf119 443 $this->webtestLogout();
6a488035
TO
444 }
445
071a6d2e 446 function testOnBehalfOfOrganizationWithOrgData() {
6a488035
TO
447 $this->webtestLogin();
448
071a6d2e 449 $this->openCiviPage("profile/edit", "reset=1&gid=4");
42daf119
CW
450 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
451 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
6a488035
TO
452
453 $this->waitForPageToLoad($this->getTimeoutMsec());
454 $this->waitForElementPresent("_qf_Edit_next");
455 $this->type("first_name", $firstName);
456 $this->type("last_name", $lastName);
457 $this->click("_qf_Edit_next");
458 $this->waitForPageToLoad($this->getTimeoutMsec());
459 $this->waitForElementPresent("profilewrap4");
460
461 $urlElements = $this->parseURL();
462 print_r($urlElements);
463 $cid = $urlElements['queryString']['id'];
464 $this->assertType('numeric', $cid);
42daf119 465 // Is status message correct?
6a488035
TO
466 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
467
42daf119 468
6a488035 469 //add org fields to profile
071a6d2e 470 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035
TO
471 $this->click("link=Reserved Profiles");
472
473 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
474 $this->waitForPageToLoad($this->getTimeoutMsec());
475
476 $this->click("link=Add Field");
477 $this->waitForElementPresent('_qf_Field_next-bottom');
42daf119 478
6a488035
TO
479 $this->select('field_name[0]', 'value=Organization');
480 $this->select('field_name[1]', 'label=Legal Identifier');
481 $this->click('field_name[1]');
482 $this->click('_qf_Field_next_new-bottom');
483 $this->waitForPageToLoad($this->getTimeoutMsec());
484
485 $this->select('field_name[0]', 'value=Organization');
486 $this->select('field_name[1]', 'label=Legal Name');
487 $this->click('field_name[1]');
488 $this->click('_qf_Field_next-bottom');
489 $this->waitForPageToLoad($this->getTimeoutMsec());
42daf119 490
6a488035
TO
491
492 //create organisation
493 $orgName = "Org WebAccess ". substr(sha1(rand()), 0, 7);
494 $orgEmail = "org". substr(sha1(rand()), 0, 7) . "@web.com";
495 $this->webtestAddOrganization($orgName, $orgEmail);
496
497 $this->waitForPageToLoad($this->getTimeoutMsec());
498 $this->click("css=li#tab_rel a");
499
500 $this->waitForElementPresent('link=Add Relationship');
501 $this->click('link=Add Relationship');
502
503 $this->waitForElementPresent('relationship_type_id');
504 $this->click("relationship_type_id");
505 $this->select("relationship_type_id", "label=Employer of");
42daf119 506 // search organization
6a488035
TO
507 $this->type('contact_1', $firstName);
508 $this->click("contact_1");
509 $this->waitForElementPresent("css=div.ac_results-inner li");
510 $this->click("css=div.ac_results-inner li");
511 $this->assertContains($firstName, $this->getValue('contact_1'), "autocomplete expected $firstName but didn’t find it in " . $this->getValue('contact_1'));
512
42daf119 513 // give permission
6a488035
TO
514 $this->click("is_permission_a_b");
515 $this->click("is_permission_b_a");
516
42daf119 517 // save relationship
6a488035
TO
518 $this->waitForElementPresent("details-save");
519 $this->click("details-save");
520 $this->waitForElementPresent("Relationships");
521
522 $pageTitle = substr(sha1(rand()), 0, 7);
523 $rand = 100;
524 $hash = substr(sha1(rand()), 0, 7);
525 $amountSection = TRUE;
526 $payLater = TRUE;
527 $onBehalf = TRUE;
528 $pledges = FALSE;
529 $recurring = FALSE;
530 $memberships = TRUE;
531 $memPriceSetId = NULL;
532 $friend = TRUE;
533 $profilePreId = NULL;
534 $profilePostId = NULL;
535 $premiums = FALSE;
536 $widget = FALSE;
537 $pcp = FALSE;
538 $honoreeSection = FALSE;
539 $isAddPaymentProcessor = FALSE;
540 $isPcpApprovalNeeded = FALSE;
541 $isSeparatePayment = FALSE;
542
543 // create a new online contribution page
544 // create contribution page with randomized title and default params
545 $pageId = $this->webtestAddContributionPage($hash,
546 $rand,
547 $pageTitle,
548 null,
549 $amountSection,
550 $payLater,
551 $onBehalf,
552 $pledges,
553 $recurring,
554 $memberships,
555 $memPriceSetId,
556 $friend,
557 $profilePreId,
558 $profilePostId,
559 $premiums,
560 $widget,
561 $pcp,
562 $isAddPaymentProcessor,
563 $isPcpApprovalNeeded,
564 $isSeparatePayment,
565 $honoreeSection
566 );
567
42daf119 568 $this->_testOrganization($pageId, $cid, $pageTitle);
6a488035
TO
569 }
570
571
572 function _testOrganization($pageId, $cid, $pageTitle) {
573 //Open Live Contribution Page
071a6d2e 574 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
6a488035
TO
575
576 $this->waitForElementPresent("onbehalf_state_province-3");
577
578 $this->waitForElementPresent("onbehalf_phone-3-1");
579 $this->type("onbehalf_phone-3-1", 9999999999);
580 $this->waitForElementPresent("onbehalf_email-3");
581 $this->type("onbehalf_email-3", "org@example.com");
582 $this->type("onbehalf_street_address-3", "Test Street Address");
583 $this->type("onbehalf_city-3", "Test City");
584 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
585 $this->click("onbehalf_country-3");
586 $this->select("onbehalf_country-3", "label=United States");
587 $this->click("onbehalf_state_province-3");
588 $this->select("onbehalf_state_province-3", "label=Alabama");
589
590 $this->waitForElementPresent("_qf_Main_upload-bottom");
591 $this->click("_qf_Main_upload-bottom");
592
593 $this->waitForPageToLoad($this->getTimeoutMsec());
594
595 $this->waitForElementPresent("_qf_Confirm_next-bottom");
596
597 $this->click("_qf_Confirm_next-bottom");
598 $this->waitForPageToLoad($this->getTimeoutMsec());
599
600 }
601
602 function _testAnomoyousOganization($pageId, $cid, $pageTitle) {
603 //Open Live Contribution Page
071a6d2e 604 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
6a488035
TO
605
606 $this->click('CIVICRM_QFID_0_8');
607 $this->type('css=div.other_amount-section input', 60);
608
609 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
42daf119
CW
610 $lastName = 'An' . substr(sha1(rand()), 0, 7);
611 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
6a488035
TO
612 $this->type("email-5", $firstName . "@example.com");
613
614 // enable onbehalforganization block
615 $this->click("is_for_organization");
616 $this->waitForElementPresent("onbehalf_state_province-3");
617
618 // onbehalforganization info
619 $this->type("onbehalf_organization_name", $orgName);
620 $this->type("onbehalf_phone-3-1", 9999999999);
621 $this->type("onbehalf_email-3", "{$orgName}@example.com");
622 $this->type("onbehalf_street_address-3", "Test Street Address");
623 $this->type("onbehalf_city-3", "Test City");
624 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
625 $this->click("onbehalf_country-3");
626 $this->select("onbehalf_country-3", "label=United States");
627 $this->click("onbehalf_state_province-3");
628 $this->select("onbehalf_state_province-3", "label=Alabama");
629
630
631 // Credit Card Info
632 $this->select("credit_card_type", "value=Visa");
633 $this->type("credit_card_number", "4111111111111111");
634 $this->type("cvv2", "000");
635 $this->select("credit_card_exp_date[M]", "value=1");
636 $this->select("credit_card_exp_date[Y]", "value=2020");
637
638 //Billing Info
639 $this->type("billing_first_name", $firstName . 'billing');
640 $this->type("billing_last_name", $lastName . 'billing');
641 $this->type("billing_street_address-5", "0121 Mount Highschool.");
642 $this->type(" billing_city-5", "Shangai");
643 $this->select("billing_country_id-5", "value=1228");
644 $this->select("billing_state_province_id-5", "value=1004");
645 $this->type("billing_postal_code-5", "94129");
646 $this->click("_qf_Main_upload-bottom");
647
648 $this->waitForPageToLoad($this->getTimeoutMsec());
649 $this->waitForElementPresent("_qf_Confirm_next-bottom");
650
651 $this->click("_qf_Confirm_next-bottom");
652 $this->waitForPageToLoad($this->getTimeoutMsec());
653
654 //login to check contribution
6a488035
TO
655
656 // Log in using webtestLogin() method
657 $this->webtestLogin();
658
659 //Find Contribution
071a6d2e 660 $this->openCiviPage("contribute/search", "reset=1");
6a488035
TO
661 $this->type("sort_name", $orgName);
662 $this->click("_qf_Search_refresh");
663
664 $this->waitForPageToLoad($this->getTimeoutMsec());
665
666 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
667 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
668 $this->waitForPageToLoad($this->getTimeoutMsec());
669 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
670
671 // verify contrb created
672 $expected = array(
673 1 => $orgName,
674 2 => 'Donation',
675 10 => $pageTitle,
676 );
677 foreach ($expected as $value => $label) {
678 $this->verifyText("xpath=id( 'ContributionView' )/div[2]/table[1]/tbody/tr[$value]/td[2]", preg_quote($label));
679 }
680 }
681
682 function _testUserWithOneRelationship($pageId, $cid, $pageTitle) {
42daf119 683 $this->webtestLogin('admin');
6a488035
TO
684
685 // Create new group
686 $groupName = $this->WebtestAddGroup();
42daf119 687 $this->openCiviPage("group", "reset=1", "_qf_Search_refresh");
6a488035
TO
688 $groupId = $this->getText("xpath=//table[@id='crm-group-selector']/tbody//tr/td[text()='{$groupName}']/../td[2]");
689
071a6d2e 690 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
6a488035
TO
691
692 $this->click('link=Edit');
693 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
694 $this->click('addressBlock');
695 $this->waitForElementPresent('link=Another Address');
696
697 //Billing Info
698 $this->select('address_1_location_type_id', 'label=Billing');
699 $this->type('address_1_street_address', '0121 Mount Highschool.');
700 $this->type('address_1_city', "Shangai");
701 $this->type('address_1_postal_code', "94129");
702 $this->select('address_1_country_id', "value=1228");
703 $this->select('address_1_state_province_id', "value=1004");
704 $this->click('_qf_Contact_upload_view-bottom');
705 $this->waitForPageToLoad($this->getTimeoutMsec());
706
707 // add contact to group
708 // visit group tab
709 $this->click("css=li#tab_group a");
710 $this->waitForElementPresent("group_id");
711
712 // add to group
713 $this->select("group_id", "label={$groupName}");
714 $this->click("_qf_GroupContact_next");
715 $this->waitForPageToLoad($this->getTimeoutMsec());
716
42daf119 717 $this->openCiviPage("admin/custom/group", "action=add&reset=1", "_qf_Group_next-bottom");
6a488035
TO
718
719 // fill in a unique title for the custom group
720 $groupTitle = "Custom Group" . substr(sha1(rand()), 0, 7);
721 $this->type("title", $groupTitle);
722
723 // select the group this custom data set extends
724 $this->select("extends[0]", "value=Contribution");
725 $this->waitForElementPresent("extends[1]");
726
727 // save the custom group
728 $this->click("_qf_Group_next-bottom");
729 $this->waitForElementPresent("_qf_Field_next_new-bottom");
730 $this->assertTrue($this->isTextPresent("Your custom field set '$groupTitle' has been added. You can add custom fields now."));
731
732 // add a custom field to the custom group
733 $fieldTitle = "Custom Field " . substr(sha1(rand()), 0, 7);
734 $this->type("label", $fieldTitle);
735
736 $this->select("data_type[1]", "value=Text");
737 $this->click('_qf_Field_next-bottom');
738
739 $this->waitForPageToLoad($this->getTimeoutMsec());
740 $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
741 $url = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']/div[2]/table/tbody//tr/td[1][text()='$fieldTitle']/../td[8]/span/a@href"));
742 $fieldId = $url[1];
743
744 // Enable CiviCampaign module if necessary
b9715b8a 745 $this->enableComponents("CiviCampaign");
6a488035 746
42daf119 747 // add the required permission
6a488035
TO
748 $permission = array('edit-2-administer-civicampaign');
749 $this->changePermissions($permission);
750
42daf119
CW
751 // Log in as normal user
752 $this->webtestLogin();
6a488035 753
42daf119 754 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
6a488035 755
6a488035
TO
756 $title = 'Campaign ' . substr(sha1(rand()), 0, 7);
757 $this->type("title", $title);
758
759 // select the campaign type
760 $this->select("campaign_type_id", "value=2");
761
762 // fill in the description
763 $this->type("description", "This is a test campaign");
764
765 // include groups for the campaign
766 $this->addSelection("includeGroups-f", "label={$groupName}");
767 $this->click("//option[@value={$groupId}]");
768 $this->click("add");
769
770 // fill the end date for campaign
771 $this->webtestFillDate("end_date", "+1 year");
772
773 // select campaign status
774 $this->select("status_id", "value=2");
775
776 // click save
777 $this->click("_qf_Campaign_upload-bottom");
778 $this->waitForElementPresent("xpath=//div[@id='campaigns_wrapper']//table[@id='campaigns']/tbody//tr/td[3][text()='{$title}']");
779 $this->assertTrue($this->isTextPresent("Campaign {$title} has been saved."), "Status message didn't show up after saving!");
780
071a6d2e 781 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035
TO
782 $this->click("link=Reserved Profiles");
783
784 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
785 $this->waitForPageToLoad($this->getTimeoutMsec());
786
787 $this->click("link=Add Field");
788 $this->waitForElementPresent('_qf_Field_next-bottom');
789 $this->select('field_name[0]', 'value=Contribution');
790 $this->select('field_name[1]', 'label=Campaign');
791 $this->click('field_name[1]');
792 $this->click('_qf_Field_next_new-bottom');
793 $this->waitForPageToLoad($this->getTimeoutMsec());
794
795 $this->select('field_name[0]', 'value=Contribution');
796 $this->select('field_name[1]', "label=$fieldTitle :: $groupTitle");
797 $this->click('field_name[1]');
798 $this->click('_qf_Field_next-bottom');
799 $this->waitForPageToLoad($this->getTimeoutMsec());
800 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$fieldTitle}' has been saved to 'On Behalf Of Organization'."));
801
802 // Open Page to create Organization
42daf119 803 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
6a488035
TO
804 $orgName1 = 'org1_' . substr(sha1(rand()), 0, 7);
805
806 // Type Organization name
807 $this->type("organization_name", $orgName1);
808
809 // Type Organizatio email for main
810 $this->type("email_1_email", "{$orgName1}@example.com");
811 $this->select("email_1_location_type_id", "value=3");
812
813 // type phone no for main
814 $this->type("phone_1_phone", 9999999999);
815 $this->select("phone_1_location_type_id", "value=3");
816
817 //address section
818 $this->click("addressBlock");
819 $this->waitForElementPresent("address_1_street_address");
820
821 //fill in address 1 for main
822 $this->select("address_1_location_type_id", "value=3");
823 $this->type("address_1_street_address", "{$orgName1} street address");
824 $this->type("address_1_city", "{$orgName1} city");
825 $this->type("address_1_postal_code", substr(sha1(rand()), 0, 4));
826 $this->assertTrue($this->isTextPresent("- select - United States"));
827 $this->select("address_1_state_province_id", "value=1019");
828 $this->type("address_1_geo_code_1", "1234");
829 $this->type("address_1_geo_code_2", "5678");
830
831 // Save the Organization
832 $this->click("_qf_Contact_upload_view-bottom");
833 $this->waitForPageToLoad($this->getTimeoutMsec());
834
835 // open contact
071a6d2e 836 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
6a488035
TO
837
838 // select relationship type
839 $this->click("relationship_type_id");
840 $this->select("relationship_type_id", "value=4_a_b");
841
842 // search organization
843 $this->type('contact_1', $orgName1);
844 $this->click("contact_1");
845 $this->waitForElementPresent("css=div.ac_results-inner li");
846 $this->click("css=div.ac_results-inner li");
847 $this->assertContains($orgName1, $this->getValue('contact_1'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('contact_1'));
848
849 $this->waitForElementPresent("add_current_employer");
850 $this->click("add_current_employer");
851
852 // give permission
853 $this->click("is_permission_a_b");
854 $this->click("is_permission_b_a");
855
856 // save relationship
857 $this->waitForElementPresent("details-save");
858 $this->click("details-save");
859
860 //Open Live Contribution Page
071a6d2e 861 $this->openCiviPage("contribute/transact", "reset=1&id={$pageId}&cid=$cid", "onbehalf_state_province-3");
6a488035
TO
862 $this->click('CIVICRM_QFID_amount_other_radio_4');
863 $this->type('amount_other', 60);
864 $this->click('onbehalf_contribution_campaign_id');
865 $this->select('onbehalf_contribution_campaign_id', "label={$title}");
866 $this->type("onbehalf_custom_{$fieldId}", 'Test Subject');
867
868 // Credit Card Info
869 $this->select("credit_card_type", "value=Visa");
870 $this->type("credit_card_number", "4111111111111111");
871 $this->type("cvv2", "000");
872 $this->select("credit_card_exp_date[M]", "value=1");
873 $this->select("credit_card_exp_date[Y]", "value=2020");
874
875 //Billing Info
876 $this->type("billing_street_address-5", "0121 Mount Highschool.");
877 $this->type(" billing_city-5", "Shangai");
878 $this->select("billing_country_id-5", "value=1228");
879 $this->select("billing_state_province_id-5", "value=1004");
880 $this->type("billing_postal_code-5", "94129");
881
882 $this->click("_qf_Main_upload-bottom");
883 $this->waitForPageToLoad($this->getTimeoutMsec());
884 $this->waitForElementPresent("_qf_Confirm_next-bottom");
885 $this->click("_qf_Confirm_next-bottom");
886 $this->waitForPageToLoad($this->getTimeoutMsec());
887
888 //Find Contribution
071a6d2e 889 $this->openCiviPage("contribute/search", "reset=1");
6a488035
TO
890 $this->type("sort_name", $orgName1);
891 $this->click("_qf_Search_refresh");
892 $this->waitForPageToLoad($this->getTimeoutMsec());
893 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
894 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
895 $this->waitForPageToLoad($this->getTimeoutMsec());
896 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
897
898 // verify contrb created
899 $expected = array(
900 1 => $orgName1,
901 2 => 'Donation',
902 10 => $title,
903 11 => $pageTitle,
904 );
905 foreach ($expected as $value => $label) {
906 $this->verifyText("xpath=id( 'ContributionView' )/div[2]/table[1]/tbody/tr[$value]/td[2]", preg_quote($label));
907 }
908
909
071a6d2e 910 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035
TO
911 $this->click("link=Reserved Profiles");
912
913 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
914 $this->waitForPageToLoad($this->getTimeoutMsec());
915
916 $this->click("xpath=//div[@id='field_page']/div[3]/table/tbody//tr/td[1][text()='Campaign']/../td[9]/span[2][text()='more ']/ul/li[2]/a[text()='Delete']");
917 $this->waitForElementPresent('_qf_Field_next-bottom');
918
919 $this->click('_qf_Field_next-bottom');
920 $this->waitForPageToLoad($this->getTimeoutMsec());
921 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'), "Status message didn't show up after saving!");
922
923 $this->click("xpath=//div[@id='field_page']/div[3]/table/tbody//tr/td[1][text()='{$fieldTitle}']/../td[9]/span[2][text()='more ']/ul/li[2]/a[text()='Delete']");
924 $this->waitForElementPresent('_qf_Field_next-bottom');
925
926 $this->click('_qf_Field_next-bottom');
927 $this->waitForPageToLoad($this->getTimeoutMsec());
928 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'), "Status message didn't show up after saving!");
929 }
930
931 function _testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle) {
42daf119 932 $this->webtestLogin('admin');
6a488035
TO
933 $this->waitForPageToLoad($this->getTimeoutMsec());
934
935 // Create new group
936 $groupName = $this->WebtestAddGroup();
42daf119 937 $this->openCiviPage("group", "reset=1", '_qf_Search_refresh');
6a488035
TO
938 $this->click('_qf_Search_refresh');
939 $this->waitForElementPresent("xpath=//div[@id='group']/div[3]/table/tbody//tr/td[text()='{$groupName}']/../td[2]");
940 $groupId = $this->getText("xpath=//div[@id='group']/div[3]/table/tbody//tr/td[text()='{$groupName}']/../td[2]");
941
071a6d2e 942 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
6a488035
TO
943
944 $this->click('link=Edit');
945 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
946 $this->click('addressBlock');
947 $this->waitForElementPresent('link=Another Address');
948
949 //Billing Info
950 $this->select('address_1_location_type_id', 'label=Billing');
951 $this->type('address_1_street_address', '0121 Mount Highschool.');
952 $this->type('address_1_city', "Shangai");
953 $this->type('address_1_postal_code', "94129");
954 $this->select('address_1_country_id', "value=1228");
955 $this->select('address_1_state_province_id', "value=1004");
956 $this->click('_qf_Contact_upload_view-bottom');
957 $this->waitForPageToLoad($this->getTimeoutMsec());
958
959 // add contact to group
960 // visit group tab
961 $this->click("css=li#tab_group a");
962 $this->waitForElementPresent("group_id");
963
964 // add to group
965 $this->select("group_id", "label=$groupName");
966 $this->click("_qf_GroupContact_next");
967 $this->waitForPageToLoad($this->getTimeoutMsec());
968
42daf119 969 $this->openCiviPage("admin/custom/group", "action=add&reset=1", "_qf_Group_next-bottom");
6a488035
TO
970
971 // fill in a unique title for the c$groupIdustom group
972 $groupTitle = "Members Custom Group" . substr(sha1(rand()), 0, 7);
973 $this->type("title", $groupTitle);
974
975 // select the group this custom data set extends
976 $this->select("extends[0]", "value=Membership");
977 $this->waitForElementPresent("extends[1]");
978
979 // save the custom group
980 $this->click("_qf_Group_next-bottom");
981
982 $this->waitForElementPresent("_qf_Field_next_new-bottom");
983 $this->assertTrue($this->isTextPresent("Your custom field set '$groupTitle' has been added. You can add custom fields now."));
984
985 // add a custom field to the custom group
986 $fieldTitle = "Member Custom Field " . substr(sha1(rand()), 0, 7);
987 $this->type("label", $fieldTitle);
988
989 $this->select("data_type[1]", "value=Text");
990 $this->click('_qf_Field_next-bottom');
991
992 $this->waitForPageToLoad($this->getTimeoutMsec());
993 $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
994 $url = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']/div[2]/table/tbody//tr/td[1]/span[text()='$fieldTitle']/../td[8]/span/a@href"));
995 $fieldId = $url[1];
996
997 // Enable CiviCampaign module if necessary
b9715b8a 998 $this->enableComponents("CiviCampaign");
6a488035 999
42daf119 1000 // add the required permission
6a488035
TO
1001 $permission = array('edit-2-administer-civicampaign');
1002 $this->changePermissions($permission);
1003
42daf119
CW
1004 // Log in as normal user
1005 $this->webtestLogin();
6a488035 1006
42daf119 1007 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
6a488035 1008
6a488035
TO
1009 $title = 'Campaign ' . substr(sha1(rand()), 0, 7);
1010 $this->type("title", $title);
1011
1012 // select the campaign type
1013 $this->select("campaign_type_id", "value=2");
1014
1015 // fill in the description
1016 $this->type("description", "This is a test campaign");
1017
1018 // include groups for the campaign
1019 $this->addSelection("includeGroups-f", "label={$groupName}");
1020 $this->click("//option[@value={$groupId}]");
1021 $this->click("add");
1022
1023 // fill the end date for campaign
1024 $this->webtestFillDate("end_date", "+1 year");
1025
1026 // select campaign status
1027 $this->select("status_id", "value=2");
1028
1029 // click save
1030 $this->click("_qf_Campaign_upload-bottom");
1031 $this->waitForPageToLoad($this->getTimeoutMsec());
1032
1033 $this->assertTrue($this->isTextPresent("Campaign {$title} has been saved."), "Status message didn't show up after saving!");
1034
071a6d2e 1035 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035
TO
1036 $this->click("link=Reserved Profiles");
1037 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
1038 $this->waitForPageToLoad($this->getTimeoutMsec());
1039
1040 $this->click("link=Add Field");
1041 $this->waitForElementPresent('_qf_Field_next-bottom');
1042 $this->select('field_name[0]', 'value=Membership');
1043 $this->select('field_name[1]', 'label=Campaign');
1044 $this->click('field_name[1]');
1045 $this->click('_qf_Field_next_new-bottom');
1046 $this->waitForPageToLoad($this->getTimeoutMsec());
1047 $this->waitForElementPresent('_qf_Field_cancel-bottom');
1048
1049 $this->select('field_name[0]', 'value=Membership');
1050 $this->select('field_name[1]', "label=$fieldTitle :: $groupTitle");
1051 $this->click('field_name[1]');
1052 $this->click('_qf_Field_next-bottom');
1053 $this->waitForPageToLoad($this->getTimeoutMsec());
1054 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$fieldTitle}' has been saved to 'On Behalf Of Organization'."),
1055 "Status message didn't show up after saving!"
1056 );
1057
1058 // Open Page to create Organization 1
42daf119 1059 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
6a488035
TO
1060 $orgName1 = 'org1_' . substr(sha1(rand()), 0, 7);
1061
1062 // Type Organization name
1063 $this->type("organization_name", $orgName1);
1064
1065 // Type Organizatio email for main
1066 $this->type("email_1_email", "{$orgName1}@example.com");
1067 $this->select("email_1_location_type_id", "value=3");
1068
1069 // type phone no for main
1070 $this->type("phone_1_phone", substr(sha1(rand()), 0, 4));
1071 $this->select("phone_1_location_type_id", "value=3");
1072
1073 //address section
1074 $this->click("addressBlock");
1075 $this->waitForElementPresent("address_1_street_address");
1076
1077 //fill in address 1 for main
1078 $this->select("address_1_location_type_id", "value=3");
1079 $this->type("address_1_street_address", "{$orgName1} street address");
1080 $this->type("address_1_city", "{$orgName1} city");
1081 $this->type("address_1_postal_code", "9999999999");
1082 $this->assertTrue($this->isTextPresent("- select - United States"));
1083 $this->select("address_1_state_province_id", "value=1019");
1084 $this->type("address_1_geo_code_1", "1234");
1085 $this->type("address_1_geo_code_2", "5678");
1086
1087 // Save the Organization
1088 $this->click("_qf_Contact_upload_view-bottom");
1089 $this->waitForPageToLoad($this->getTimeoutMsec());
1090
1091 // create second orzanization
42daf119 1092 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
6a488035
TO
1093 $orgName2 = 'org2_' . substr(sha1(rand()), 0, 7);
1094
1095 // Type Organization name
1096 $this->type("organization_name", $orgName2);
1097
1098 // Type Organizatio email for main
1099 $this->type("email_1_email", "{$orgName2}@example.com");
1100 $this->select("email_1_location_type_id", "value=3");
1101
1102 // type phone no for main
1103 $this->type("phone_1_phone", substr(sha1(rand()), 0, 4));
1104 $this->select("phone_1_location_type_id", "value=3");
1105
1106 //address section
1107 $this->click("addressBlock");
1108 $this->waitForElementPresent("address_1_street_address");
1109
1110 //fill in address 1 for main
1111 $this->select("address_1_location_type_id", "value=3");
1112 $this->type("address_1_street_address", "{$orgName2} street address");
1113 $this->type("address_1_city", "{$orgName2} city");
1114 $this->type("address_1_postal_code", "7777777777");
1115 $this->assertTrue($this->isTextPresent("- select - United States"));
1116 $this->select("address_1_state_province_id", "value=1019");
1117 $this->type("address_1_geo_code_1", "1224");
1118 $this->type("address_1_geo_code_2", "5628");
1119
1120 // Save the Organization
1121 $this->click("_qf_Contact_upload_view-bottom");
1122 $this->waitForPageToLoad($this->getTimeoutMsec());
1123
1124
1125 // create Membership type
1126 $title1 = "Membership Type" . substr(sha1(rand()), 0, 7);
071a6d2e 1127 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
6a488035
TO
1128
1129 $this->click("link=Add Membership Type");
1130 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
1131
1132 $this->type('name', $title1);
1133 $this->type('member_org', $orgName1);
1134 $this->click('_qf_MembershipType_refresh');
1135 $this->waitForElementPresent("xpath=//div[@id='membership_type_form']/fieldset/table[2]/tbody/tr[2]/td[2]");
1136
1137 $this->type('minimum_fee', '50');
1138
42daf119 1139 $this->select( 'financial_type_id', 'value=2' );
6a488035
TO
1140
1141 $this->type('duration_interval', 1);
1142 $this->select('duration_unit', "label=year");
1143
1144 $this->select('period_type', "label=fixed");
1145 $this->waitForElementPresent('fixed_period_rollover_day[d]');
1146
1147 $this->select('fixed_period_start_day[M]', 'value=4');
1148 $this->select('fixed_period_rollover_day[M]', 'value=1');
1149
1150 $this->select('relationship_type_id', 'value=4_b_a');
1151
1152 $this->click('_qf_MembershipType_upload-bottom');
1153 $this->waitForElementPresent('link=Add Membership Type');
1154 $this->assertTrue($this->isTextPresent("The membership type '$title1' has been saved."));
1155 $typeUrl = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[1][text()='{$title1}']/../td[10]/span/a[3]@href"));
1156 $typeId = $typeUrl[1];
1157
1158 // open contact
071a6d2e 1159 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
6a488035
TO
1160
1161 // select relationship type
1162 $this->click("relationship_type_id");
1163 $this->select("relationship_type_id", "value=4_a_b");
1164
1165 // search organization
1166 $this->type('contact_1', $orgName1);
1167 $this->click("contact_1");
1168 $this->waitForElementPresent("css=div.ac_results-inner li");
1169 $this->click("css=div.ac_results-inner li");
1170 $this->assertContains($orgName1, $this->getValue('contact_1'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('contact_1'));
1171
1172 // give permission
1173 $this->click("is_permission_a_b");
1174 $this->click("is_permission_b_a");
1175
1176 // save relationship
1177 $this->click("details-save");
1178
1179 // open contact
071a6d2e 1180 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
6a488035
TO
1181
1182 // select relationship type
1183 $this->click("relationship_type_id");
1184 $this->select("relationship_type_id", "value=4_a_b");
1185
1186 // search organization
1187 $this->type('contact_1', $orgName2);
1188 $this->click("contact_1");
1189 $this->waitForElementPresent("css=div.ac_results-inner li");
1190 $this->click("css=div.ac_results-inner li");
1191 $this->assertContains($orgName2, $this->getValue('contact_1'), "autocomplete expected $orgName2 but didn’t find it in " . $this->getValue('contact_1'));
1192
1193 // give permission
1194 $this->click("is_permission_a_b");
1195 $this->click("is_permission_b_a");
1196
1197 // save relationship
1198 $this->click("details-save");
1199
1200 // set membership type
071a6d2e 1201 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id=$pageId", "_qf_MembershipBlock_upload_done-bottom");
6a488035
TO
1202 $this->click("member_is_active");
1203 $this->click("membership_type[{$typeId}]");
1204 $this->click("xpath=//div[@id='memberFields']//table[@class='report']/tbody//tr/td[1]/label[text()='{$title1}']/../../td[2]/input");
1205 $this->click('_qf_MembershipBlock_upload_done-bottom');
1206 $this->waitForPageToLoad($this->getTimeoutMsec());
1207
1208 //Open Live Membership Page
b45c587e 1209 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&cid=$cid", "_qf_Main_upload-bottom");
6a488035
TO
1210 $this->click('CIVICRM_QFID_amount_other_radio_4');
1211 $this->type('amount_other', 60);
1212 $this->click('onbehalf_organization_name');
1213 $this->type('onbehalf_organization_name', $orgName1);
1214 $this->typeKeys('onbehalf_organization_name', $orgName1);
1215 $this->click("onbehalf_organization_name");
1216 $this->waitForElementPresent("css=div.ac_results-inner li");
1217 $this->click("css=div.ac_results-inner li");
efb29358
CW
1218 // Because it tends to cause problems, all uses of sleep() must be justified in comments
1219 // Sleep should never be used for wait for anything to load from the server
1220 // Justification for this instance: FIXME
6a488035
TO
1221 sleep(5);
1222 $this->click('onbehalf_member_campaign_id');
1223 $this->select('onbehalf_member_campaign_id', "label={$title}");
1224 $this->type("onbehalf_custom_{$fieldId}", 'Test Subject');
1225
1226 $this->assertContains($orgName1, $this->getValue('onbehalf_organization_name'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('onbehalf_organization_name'));
1227
1228 // Credit Card Info
1229 $this->select("credit_card_type", "value=Visa");
1230 $this->type("credit_card_number", "4111111111111111");
1231 $this->type("cvv2", "000");
1232 $this->select("credit_card_exp_date[M]", "value=1");
1233 $this->select("credit_card_exp_date[Y]", "value=2020");
1234
1235 $this->click("_qf_Main_upload-bottom");
1236 $this->waitForPageToLoad($this->getTimeoutMsec());
1237 $this->waitForElementPresent("_qf_Confirm_next-bottom");
1238 $this->click("_qf_Confirm_next-bottom");
1239 $this->waitForPageToLoad($this->getTimeoutMsec());
1240
1241 //Find Membership for organization
071a6d2e 1242 $this->openCiviPage("member/search", "reset=1");
6a488035
TO
1243 $this->type("sort_name", $orgName1);
1244 $this->click("_qf_Search_refresh");
1245 $this->waitForPageToLoad($this->getTimeoutMsec());
1246 $this->waitForElementPresent("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
1247 $this->click("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
1248 $this->waitForPageToLoad($this->getTimeoutMsec());
1249 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
1250
1251 //verify contrb created
1252 $expected = array(
1253 1 => $orgName1,
1254 2 => $title1,
1255 3 => 'New',
1256 );
1257 foreach ($expected as $value => $label) {
1258 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1259 }
1260
1261 // find membership for contact in relationship
071a6d2e 1262 $this->openCiviPage("contact/view", "reset=1&force=1&cid={$cid}");
6a488035
TO
1263 $this->click("css=li#tab_member a");
1264 $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']");
1265 $this->click("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']/../td[7]/span/a[text()='View']");
1266 $this->waitForPageToLoad($this->getTimeoutMsec());
1267
1268 //verify contrb created
1269 $expected = array(
1270 3 => $title1,
1271 4 => 'New',
1272 );
1273 foreach ($expected as $value => $label) {
1274 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1275 }
1276
071a6d2e 1277 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035
TO
1278 $this->click("link=Reserved Profiles");
1279 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
1280 $this->waitForPageToLoad($this->getTimeoutMsec());
1281
1282 $this->click("xpath=//div[@id='field_page']/div[3]/table/tbody//tr/td[1][text()='Campaign']/../td[9]/span[2][text()='more ']/ul/li[2]/a[text()='Delete']");
1283 $this->waitForElementPresent('_qf_Field_next-bottom');
1284
1285 $this->click('_qf_Field_next-bottom');
1286 $this->waitForPageToLoad($this->getTimeoutMsec());
1287 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1288 "Status message didn't show up after saving!"
1289 );
1290
1291 $this->click("xpath=//div[@id='field_page']/div[3]/table/tbody//tr/td[1][text()='{$fieldTitle}']/../td[9]/span[2][text()='more ']/ul/li[2]/a[text()='Delete']");
1292 $this->waitForElementPresent('_qf_Field_next-bottom');
1293
1294 $this->click('_qf_Field_next-bottom');
1295 $this->waitForPageToLoad($this->getTimeoutMsec());
1296 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1297 "Status message didn't show up after saving!"
1298 );
1299
071a6d2e 1300 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
6a488035
TO
1301 $this->click("css=li#tab_rel a");
1302
1303 $this->waitForElementPresent("xpath=//div[@id='current-relationships']/div/table/tbody//tr/td[2]/a[text()='{$orgName1}']");
1304 $this->click("xpath=//div[@id='current-relationships']/div/table/tbody//tr/td[2]/a[text()='{$orgName1}']/../../td[9]/span[2][text()='more ']/ul/li[2]/a[text()='Delete']");
1305
1306 // Check confirmation alert.
1307 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this relationship?/",
1308 $this->getConfirmation()
1309 ));
1310 $this->chooseOkOnNextConfirmation();
1311 $this->waitForPageToLoad($this->getTimeoutMsec());
1312 $this->assertTrue($this->isTextPresent('Selected relationship has been deleted successfully.'),
1313 "Status message didn't show up after saving!"
1314 );
1315 }
1316
1317
071a6d2e
CW
1318 function testOnBehalfOfOrganizationWithImage() {
1319 $this->webtestLogin();
42daf119 1320
071a6d2e 1321 $this->openCiviPage("profile/edit", "reset=1&gid=4");
42daf119
CW
1322 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
1323 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
1324
6a488035
TO
1325 $this->waitForPageToLoad($this->getTimeoutMsec());
1326 $this->waitForElementPresent("_qf_Edit_next");
1327 $this->type("first_name", $firstName);
1328 $this->type("last_name", $lastName);
1329 $this->click("_qf_Edit_next");
1330 $this->waitForPageToLoad($this->getTimeoutMsec());
1331 $this->waitForElementPresent("profilewrap4");
42daf119 1332
6a488035
TO
1333 $urlElements = $this->parseURL();
1334 $cid = $urlElements['queryString']['id'];
1335 $this->assertType('numeric', $cid);
42daf119 1336 // Is status message correct?
6a488035
TO
1337 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
1338
071a6d2e 1339 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035 1340 $this->click("link=Reserved Profiles");
42daf119 1341
6a488035
TO
1342 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
1343 $this->waitForPageToLoad($this->getTimeoutMsec());
42daf119 1344
6a488035
TO
1345 $this->click("link=Add Field");
1346 $this->waitForElementPresent('_qf_Field_next-bottom');
1347
1348 $this->select('field_name[0]', 'value=Contact');
1349 $this->select('field_name[1]', 'label=Image Url');
1350 $this->click('field_name[1]');
1351 $this->click('_qf_Field_next-bottom');
1352 $this->waitForPageToLoad($this->getTimeoutMsec());
1353
1354 // We need a payment processor
1355 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
1356 $processorType = 'Dummy';
1357 $pageTitle = substr(sha1(rand()), 0, 7);
1358 $rand = 100;
1359 $hash = substr(sha1(rand()), 0, 7);
1360 $amountSection = TRUE;
1361 $payLater = TRUE;
1362 $onBehalf = TRUE;
1363 $pledges = FALSE;
1364 $recurring = FALSE;
1365 $memberships = FALSE;
1366 $memPriceSetId = NULL;
1367 $friend = TRUE;
1368 $profilePreId = NULL;
1369 $profilePostId = NULL;
1370 $premiums = FALSE;
1371 $widget = FALSE;
1372 $pcp = FALSE;
1373 $honoreeSection = FALSE;
1374 $isAddPaymentProcessor = TRUE;
1375 $isPcpApprovalNeeded = FALSE;
1376 $isSeparatePayment = FALSE;
1377
1378 // create a new online contribution page
1379 // create contribution page with randomized title and default params
1380 $pageId = $this->webtestAddContributionPage($hash,
1381 $rand,
1382 $pageTitle,
1383 array($processorName => $processorType),
1384 $amountSection,
1385 $payLater,
1386 $onBehalf,
1387 $pledges,
1388 $recurring,
1389 $memberships,
1390 $memPriceSetId,
1391 $friend,
1392 $profilePreId,
1393 $profilePostId,
1394 $premiums,
1395 $widget,
1396 $pcp,
1397 $isAddPaymentProcessor,
1398 $isPcpApprovalNeeded,
1399 $isSeparatePayment,
1400 $honoreeSection
1401 );
1402
42daf119
CW
1403 $this->_testOrganizationWithImageUpload($pageId, $cid, $pageTitle);
1404
071a6d2e 1405 $this->openCiviPage("admin/uf/group", "reset=1");
6a488035 1406 $this->click("link=Reserved Profiles");
42daf119 1407
6a488035
TO
1408 $this->click("xpath=//div[@id='reserved-profiles']/div/div/table/tbody//tr/td[1][text()='On Behalf Of Organization']/../td[5]/span/a[text()='Fields']");
1409 $this->waitForPageToLoad($this->getTimeoutMsec());
1410 $this->click("xpath=//table[@id='option11']/tbody//tr/td/span[text()='Image Url']/../following-sibling::td[8]/span[2]/ul/li[2]/a");
1411 $this->waitForPageToLoad($this->getTimeoutMsec());
1412 $this->click('_qf_Field_next-bottom');
1413 $this->waitForPageToLoad($this->getTimeoutMsec());
1414 $this->assertElementContainsText('crm-notification-container', "Selected Profile Field has been deleted.");
1415 }
1416
1417 function _testOrganizationWithImageUpload($pageId, $cid, $pageTitle) {
1418 //Open Live Contribution Page
b45c587e 1419 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", '_qf_Main_upload-bottom');
6a488035
TO
1420
1421 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
42daf119
CW
1422 $lastName = 'An' . substr(sha1(rand()), 0, 7);
1423 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
6a488035
TO
1424 $this->type("email-5", $firstName . "@example.com");
1425
1426 // onbehalforganization info
1427 $this->type("onbehalf_organization_name", $orgName);
1428 $this->type("onbehalf_phone-3-1", 9999999999);
1429 $this->type("onbehalf_email-3", "{$orgName}@example.com");
1430 $this->type("onbehalf_street_address-3", "Test Street Address");
1431 $this->type("onbehalf_city-3", "Test City");
1432 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
1433 $this->click("onbehalf_country-3");
1434 $this->select("onbehalf_country-3", "label=United States");
1435 $this->click("onbehalf_state_province-3");
1436 $this->select("onbehalf_state_province-3", "label=Alabama");
1437
1438 // check for upload field.
1439 $this->waitForElementPresent("onbehalf_image_URL");
1440
1441 //header("Content-Type: image/png");
1442 $im = imagecreate(110, 20)
1443 or die("Cannot Initialize new GD image stream");
1444 $background_color = imagecolorallocate($im, 0, 0, 0);
1445 $text_color = imagecolorallocate($im, 233, 14, 91);
1446 imagestring($im, 1, 5, 5, "On Behalf-Org Logo", $text_color);
1447 imagepng($im,"/tmp/file.png");
42daf119 1448
6a488035
TO
1449 $imagePath = "/tmp/file.png";
1450 $this->webtestAttachFile('onbehalf_image_URL', $imagePath);
1451 unlink($imagePath);
1452
1453 // Credit Card Info
1454 $this->select("credit_card_type", "value=Visa");
1455 $this->type("credit_card_number", "4111111111111111");
1456 $this->type("cvv2", "000");
1457 $this->select("credit_card_exp_date[M]", "value=1");
1458 $this->select("credit_card_exp_date[Y]", "value=2020");
1459
1460 //Billing Info
1461 $this->type("billing_first_name", $firstName . 'billing');
1462 $this->type("billing_last_name", $lastName . 'billing');
1463 $this->type("billing_street_address-5", "0121 Mount Highschool.");
1464 $this->type(" billing_city-5", "Shangai");
1465 $this->select("billing_country_id-5", "value=1228");
1466 $this->select("billing_state_province_id-5", "value=1004");
1467 $this->type("billing_postal_code-5", "94129");
1468 $this->click("_qf_Main_upload-bottom");
1469
1470 $this->waitForPageToLoad($this->getTimeoutMsec());
1471 $this->waitForElementPresent("_qf_Confirm_next-bottom");
1472
1473 $this->click("_qf_Confirm_next-bottom");
1474 $this->waitForPageToLoad($this->getTimeoutMsec());
1475
1476 // Type search name in autocomplete.
1477 $this->click('sort_name_navigation');
1478 $this->type('css=input#sort_name_navigation', $orgName);
1479 $this->typeKeys('css=input#sort_name_navigation', $orgName);
1480
1481 // Wait for result list.
1482 $this->waitForElementPresent("css=div.ac_results-inner li");
42daf119 1483
6a488035
TO
1484 // Visit organization page.
1485 $this->click("css=div.ac_results-inner li");
1486 $this->waitForPageToLoad($this->getTimeoutMsec());
42daf119 1487
6a488035
TO
1488 //check whether the image is present
1489 $this->assertTrue($this->isElementPresent("xpath=//div[@id='crm-contact-thumbnail']/div/a/img"));
1490 }
1491}
1492