Merge pull request #198 from pradpnayak/CRM-12127
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / OnBehalfOfOrganization.php
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
30 protected $pageno = '';
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testOnBehalfOfOrganization() {
36 $this->webtestLogin();
37
38 // create new individual
39 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
40 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
41 $email = "{$firstName}.{$lastName}@example.com";
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
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->click("_qf_Edit_next");
127 $this->waitForPageToLoad($this->getTimeoutMsec());
128 $this->waitForElementPresent("profilewrap4");
129
130 // Is status message correct?
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
134
135 $this->openCiviPage("admin/custom/group", "action=add&reset=1");
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."));
230
231 //add the above custom data to the On Behalf of Profile
232 $this->openCiviPage("admin/uf/group", "reset=1");
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
268 // fill in Membership Organization and Type
269 $this->select('membership_type_id[0]', "value=1");
270 $this->select('membership_type_id[1]', "value=1");
271
272 // fill in Source
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
280 // select newly created processor
281 $xpath = "xpath=//label[text() = '{$checkboxOptionLabel1}']/preceding-sibling::input[1]";
282 $this->assertTrue($this->isTextPresent($checkboxOptionLabel1));
283 $this->check($xpath);
284
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");
306 // search organization
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
313 // give permission
314 $this->click("is_permission_a_b");
315 $this->click("is_permission_b_a");
316
317 // save relationship
318 $this->click("details-save");
319 $this->waitForPageToLoad($this->getTimeoutMsec());
320
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 );
369
370 //check for formRule
371 //scenario 1 : add membership data in pre / post profile and check for formRule
372 //add new profile
373 $this->openCiviPage("admin/uf/group", "reset=1");
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}'."));
394
395 $this->openCiviPage("admin/contribute/custom", "reset=1&action=update&id={$pageId}", '_qf_Custom_next-bottom');
396 $this->select('custom_pre_id', "label={$profileTitle}");
397 $this->click('_qf_Custom_next-bottom');
398 $this->waitForPageToLoad($this->getTimeoutMsec());
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
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");
404
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());
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
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");
414
415 //scenario 2 : disable 'on behalf of', add membership data in pre / post profile
416 //then try to add 'on behalf of' and check for formRule
417 //disable 'on behalf of'
418 $this->openCiviPage("admin/contribute/settings", "reset=1&action=update&id={$pageId}", '_qf_Settings_next-bottom');
419 $this->uncheck('is_organization');
420 $this->click('_qf_Settings_next-bottom');
421 $this->waitForPageToLoad($this->getTimeoutMsec());
422
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());
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
439 sleep(3);
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");
441
442 //logout
443 $this->webtestLogout();
444 }
445
446 function testOnBehalfOfOrganizationWithOrgData() {
447 $this->webtestLogin();
448
449 $this->openCiviPage("profile/edit", "reset=1&gid=4");
450 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
451 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
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);
465 // Is status message correct?
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
468
469 //add org fields to profile
470 $this->openCiviPage("admin/uf/group", "reset=1");
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');
478
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());
490
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");
506 // search organization
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
513 // give permission
514 $this->click("is_permission_a_b");
515 $this->click("is_permission_b_a");
516
517 // save relationship
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
568 $this->_testOrganization($pageId, $cid, $pageTitle);
569 }
570
571
572 function _testOrganization($pageId, $cid, $pageTitle) {
573 //Open Live Contribution Page
574 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
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
604 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
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);
610 $lastName = 'An' . substr(sha1(rand()), 0, 7);
611 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
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
655
656 // Log in using webtestLogin() method
657 $this->webtestLogin();
658
659 //Find Contribution
660 $this->openCiviPage("contribute/search", "reset=1");
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) {
683 $this->webtestLogin('admin');
684
685 // Create new group
686 $groupName = $this->WebtestAddGroup();
687 $this->openCiviPage("group", "reset=1", "_qf_Search_refresh");
688 $groupId = $this->getText("xpath=//table[@id='crm-group-selector']/tbody//tr/td[text()='{$groupName}']/../td[2]");
689
690 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
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
717 $this->openCiviPage("admin/custom/group", "action=add&reset=1", "_qf_Group_next-bottom");
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
745 $this->enableComponents("CiviCampaign");
746
747 // add the required permission
748 $permission = array('edit-2-administer-civicampaign');
749 $this->changePermissions($permission);
750
751 // Log in as normal user
752 $this->webtestLogin();
753
754 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
755
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
781 $this->openCiviPage("admin/uf/group", "reset=1");
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
803 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
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
836 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
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
861 $this->openCiviPage("contribute/transact", "reset=1&id={$pageId}&cid=$cid", "onbehalf_state_province-3");
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
889 $this->openCiviPage("contribute/search", "reset=1");
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
910 $this->openCiviPage("admin/uf/group", "reset=1");
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) {
932 $this->webtestLogin('admin');
933 $this->waitForPageToLoad($this->getTimeoutMsec());
934
935 // Create new group
936 $groupName = $this->WebtestAddGroup();
937 $this->openCiviPage("group", "reset=1", '_qf_Search_refresh');
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
942 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
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
969 $this->openCiviPage("admin/custom/group", "action=add&reset=1", "_qf_Group_next-bottom");
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
998 $this->enableComponents("CiviCampaign");
999
1000 // add the required permission
1001 $permission = array('edit-2-administer-civicampaign');
1002 $this->changePermissions($permission);
1003
1004 // Log in as normal user
1005 $this->webtestLogin();
1006
1007 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
1008
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
1035 $this->openCiviPage("admin/uf/group", "reset=1");
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
1059 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
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
1092 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
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);
1127 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
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
1139 $this->select( 'financial_type_id', 'value=2' );
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
1159 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
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
1180 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
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
1201 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id=$pageId", "_qf_MembershipBlock_upload_done-bottom");
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
1209 $this->open($this->sboxPath . "civicrm/contribute/transact?reset=1&id=" . $pageId . "&cid=" . $cid);
1210 $this->waitForElementPresent("_qf_Main_upload-bottom");
1211 $this->click('CIVICRM_QFID_amount_other_radio_4');
1212 $this->type('amount_other', 60);
1213 $this->click('onbehalf_organization_name');
1214 $this->type('onbehalf_organization_name', $orgName1);
1215 $this->typeKeys('onbehalf_organization_name', $orgName1);
1216 $this->click("onbehalf_organization_name");
1217 $this->waitForElementPresent("css=div.ac_results-inner li");
1218 $this->click("css=div.ac_results-inner li");
1219 // Because it tends to cause problems, all uses of sleep() must be justified in comments
1220 // Sleep should never be used for wait for anything to load from the server
1221 // Justification for this instance: FIXME
1222 sleep(5);
1223 $this->click('onbehalf_member_campaign_id');
1224 $this->select('onbehalf_member_campaign_id', "label={$title}");
1225 $this->type("onbehalf_custom_{$fieldId}", 'Test Subject');
1226
1227 $this->assertContains($orgName1, $this->getValue('onbehalf_organization_name'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('onbehalf_organization_name'));
1228
1229 // Credit Card Info
1230 $this->select("credit_card_type", "value=Visa");
1231 $this->type("credit_card_number", "4111111111111111");
1232 $this->type("cvv2", "000");
1233 $this->select("credit_card_exp_date[M]", "value=1");
1234 $this->select("credit_card_exp_date[Y]", "value=2020");
1235
1236 $this->click("_qf_Main_upload-bottom");
1237 $this->waitForPageToLoad($this->getTimeoutMsec());
1238 $this->waitForElementPresent("_qf_Confirm_next-bottom");
1239 $this->click("_qf_Confirm_next-bottom");
1240 $this->waitForPageToLoad($this->getTimeoutMsec());
1241
1242 //Find Membership for organization
1243 $this->openCiviPage("member/search", "reset=1");
1244 $this->type("sort_name", $orgName1);
1245 $this->click("_qf_Search_refresh");
1246 $this->waitForPageToLoad($this->getTimeoutMsec());
1247 $this->waitForElementPresent("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
1248 $this->click("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
1249 $this->waitForPageToLoad($this->getTimeoutMsec());
1250 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
1251
1252 //verify contrb created
1253 $expected = array(
1254 1 => $orgName1,
1255 2 => $title1,
1256 3 => 'New',
1257 );
1258 foreach ($expected as $value => $label) {
1259 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1260 }
1261
1262 // find membership for contact in relationship
1263 $this->openCiviPage("contact/view", "reset=1&force=1&cid={$cid}");
1264 $this->click("css=li#tab_member a");
1265 $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']");
1266 $this->click("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']/../td[7]/span/a[text()='View']");
1267 $this->waitForPageToLoad($this->getTimeoutMsec());
1268
1269 //verify contrb created
1270 $expected = array(
1271 3 => $title1,
1272 4 => 'New',
1273 );
1274 foreach ($expected as $value => $label) {
1275 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1276 }
1277
1278 $this->openCiviPage("admin/uf/group", "reset=1");
1279 $this->click("link=Reserved Profiles");
1280 $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']");
1281 $this->waitForPageToLoad($this->getTimeoutMsec());
1282
1283 $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']");
1284 $this->waitForElementPresent('_qf_Field_next-bottom');
1285
1286 $this->click('_qf_Field_next-bottom');
1287 $this->waitForPageToLoad($this->getTimeoutMsec());
1288 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1289 "Status message didn't show up after saving!"
1290 );
1291
1292 $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']");
1293 $this->waitForElementPresent('_qf_Field_next-bottom');
1294
1295 $this->click('_qf_Field_next-bottom');
1296 $this->waitForPageToLoad($this->getTimeoutMsec());
1297 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1298 "Status message didn't show up after saving!"
1299 );
1300
1301 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
1302 $this->click("css=li#tab_rel a");
1303
1304 $this->waitForElementPresent("xpath=//div[@id='current-relationships']/div/table/tbody//tr/td[2]/a[text()='{$orgName1}']");
1305 $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']");
1306
1307 // Check confirmation alert.
1308 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this relationship?/",
1309 $this->getConfirmation()
1310 ));
1311 $this->chooseOkOnNextConfirmation();
1312 $this->waitForPageToLoad($this->getTimeoutMsec());
1313 $this->assertTrue($this->isTextPresent('Selected relationship has been deleted successfully.'),
1314 "Status message didn't show up after saving!"
1315 );
1316 }
1317
1318
1319 function testOnBehalfOfOrganizationWithImage() {
1320 $this->webtestLogin();
1321
1322 $this->openCiviPage("profile/edit", "reset=1&gid=4");
1323 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
1324 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
1325
1326 $this->waitForPageToLoad($this->getTimeoutMsec());
1327 $this->waitForElementPresent("_qf_Edit_next");
1328 $this->type("first_name", $firstName);
1329 $this->type("last_name", $lastName);
1330 $this->click("_qf_Edit_next");
1331 $this->waitForPageToLoad($this->getTimeoutMsec());
1332 $this->waitForElementPresent("profilewrap4");
1333
1334 $urlElements = $this->parseURL();
1335 $cid = $urlElements['queryString']['id'];
1336 $this->assertType('numeric', $cid);
1337 // Is status message correct?
1338 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
1339
1340 $this->openCiviPage("admin/uf/group", "reset=1");
1341 $this->click("link=Reserved Profiles");
1342
1343 $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']");
1344 $this->waitForPageToLoad($this->getTimeoutMsec());
1345
1346 $this->click("link=Add Field");
1347 $this->waitForElementPresent('_qf_Field_next-bottom');
1348
1349 $this->select('field_name[0]', 'value=Contact');
1350 $this->select('field_name[1]', 'label=Image Url');
1351 $this->click('field_name[1]');
1352 $this->click('_qf_Field_next-bottom');
1353 $this->waitForPageToLoad($this->getTimeoutMsec());
1354
1355 // We need a payment processor
1356 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
1357 $processorType = 'Dummy';
1358 $pageTitle = substr(sha1(rand()), 0, 7);
1359 $rand = 100;
1360 $hash = substr(sha1(rand()), 0, 7);
1361 $amountSection = TRUE;
1362 $payLater = TRUE;
1363 $onBehalf = TRUE;
1364 $pledges = FALSE;
1365 $recurring = FALSE;
1366 $memberships = FALSE;
1367 $memPriceSetId = NULL;
1368 $friend = TRUE;
1369 $profilePreId = NULL;
1370 $profilePostId = NULL;
1371 $premiums = FALSE;
1372 $widget = FALSE;
1373 $pcp = FALSE;
1374 $honoreeSection = FALSE;
1375 $isAddPaymentProcessor = TRUE;
1376 $isPcpApprovalNeeded = FALSE;
1377 $isSeparatePayment = FALSE;
1378
1379 // create a new online contribution page
1380 // create contribution page with randomized title and default params
1381 $pageId = $this->webtestAddContributionPage($hash,
1382 $rand,
1383 $pageTitle,
1384 array($processorName => $processorType),
1385 $amountSection,
1386 $payLater,
1387 $onBehalf,
1388 $pledges,
1389 $recurring,
1390 $memberships,
1391 $memPriceSetId,
1392 $friend,
1393 $profilePreId,
1394 $profilePostId,
1395 $premiums,
1396 $widget,
1397 $pcp,
1398 $isAddPaymentProcessor,
1399 $isPcpApprovalNeeded,
1400 $isSeparatePayment,
1401 $honoreeSection
1402 );
1403
1404 $this->_testOrganizationWithImageUpload($pageId, $cid, $pageTitle);
1405
1406 $this->openCiviPage("admin/uf/group", "reset=1");
1407 $this->click("link=Reserved Profiles");
1408
1409 $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']");
1410 $this->waitForPageToLoad($this->getTimeoutMsec());
1411 $this->click("xpath=//table[@id='option11']/tbody//tr/td/span[text()='Image Url']/../following-sibling::td[8]/span[2]/ul/li[2]/a");
1412 $this->waitForPageToLoad($this->getTimeoutMsec());
1413 $this->click('_qf_Field_next-bottom');
1414 $this->waitForPageToLoad($this->getTimeoutMsec());
1415 $this->assertElementContainsText('crm-notification-container', "Selected Profile Field has been deleted.");
1416 }
1417
1418 function _testOrganizationWithImageUpload($pageId, $cid, $pageTitle) {
1419 //Open Live Contribution Page
1420 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId");
1421
1422 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
1423 $lastName = 'An' . substr(sha1(rand()), 0, 7);
1424 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
1425 $this->type("email-5", $firstName . "@example.com");
1426
1427 // onbehalforganization info
1428 $this->type("onbehalf_organization_name", $orgName);
1429 $this->type("onbehalf_phone-3-1", 9999999999);
1430 $this->type("onbehalf_email-3", "{$orgName}@example.com");
1431 $this->type("onbehalf_street_address-3", "Test Street Address");
1432 $this->type("onbehalf_city-3", "Test City");
1433 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
1434 $this->click("onbehalf_country-3");
1435 $this->select("onbehalf_country-3", "label=United States");
1436 $this->click("onbehalf_state_province-3");
1437 $this->select("onbehalf_state_province-3", "label=Alabama");
1438
1439 // check for upload field.
1440 $this->waitForElementPresent("onbehalf_image_URL");
1441
1442 //header("Content-Type: image/png");
1443 $im = imagecreate(110, 20)
1444 or die("Cannot Initialize new GD image stream");
1445 $background_color = imagecolorallocate($im, 0, 0, 0);
1446 $text_color = imagecolorallocate($im, 233, 14, 91);
1447 imagestring($im, 1, 5, 5, "On Behalf-Org Logo", $text_color);
1448 imagepng($im,"/tmp/file.png");
1449
1450 $imagePath = "/tmp/file.png";
1451 $this->webtestAttachFile('onbehalf_image_URL', $imagePath);
1452 unlink($imagePath);
1453
1454 // Credit Card Info
1455 $this->select("credit_card_type", "value=Visa");
1456 $this->type("credit_card_number", "4111111111111111");
1457 $this->type("cvv2", "000");
1458 $this->select("credit_card_exp_date[M]", "value=1");
1459 $this->select("credit_card_exp_date[Y]", "value=2020");
1460
1461 //Billing Info
1462 $this->type("billing_first_name", $firstName . 'billing');
1463 $this->type("billing_last_name", $lastName . 'billing');
1464 $this->type("billing_street_address-5", "0121 Mount Highschool.");
1465 $this->type(" billing_city-5", "Shangai");
1466 $this->select("billing_country_id-5", "value=1228");
1467 $this->select("billing_state_province_id-5", "value=1004");
1468 $this->type("billing_postal_code-5", "94129");
1469 $this->click("_qf_Main_upload-bottom");
1470
1471 $this->waitForPageToLoad($this->getTimeoutMsec());
1472 $this->waitForElementPresent("_qf_Confirm_next-bottom");
1473
1474 $this->click("_qf_Confirm_next-bottom");
1475 $this->waitForPageToLoad($this->getTimeoutMsec());
1476
1477 // Type search name in autocomplete.
1478 $this->click('sort_name_navigation');
1479 $this->type('css=input#sort_name_navigation', $orgName);
1480 $this->typeKeys('css=input#sort_name_navigation', $orgName);
1481
1482 // Wait for result list.
1483 $this->waitForElementPresent("css=div.ac_results-inner li");
1484
1485 // Visit organization page.
1486 $this->click("css=div.ac_results-inner li");
1487 $this->waitForPageToLoad($this->getTimeoutMsec());
1488
1489 //check whether the image is present
1490 $this->assertTrue($this->isElementPresent("xpath=//div[@id='crm-contact-thumbnail']/div/a/img"));
1491 }
1492 }
1493