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