Merge pull request #2842 from totten/master-api-rollback-soft-errors
[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 /**
562 * @param $pageId
563 * @param $cid
564 * @param $pageTitle
565 */
566 function _testOrganization($pageId, $cid, $pageTitle) {
567 //Open Live Contribution Page
568 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
569
570 $this->waitForElementPresent("onbehalf_state_province-3");
571
572 $this->waitForElementPresent("onbehalf_phone-3-1");
573 $this->type("onbehalf_phone-3-1", 9999999999);
574 $this->waitForElementPresent("onbehalf_email-3");
575 $this->type("onbehalf_email-3", "org@example.com");
576 $this->type("onbehalf_street_address-3", "Test Street Address");
577 $this->type("onbehalf_city-3", "Test City");
578 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
579 $this->click("onbehalf_country-3");
580 $this->select("onbehalf_country-3", "label=United States");
581 $this->click("onbehalf_state_province-3");
582 $this->select("onbehalf_state_province-3", "label=Alabama");
583
584 $this->waitForElementPresent("_qf_Main_upload-bottom");
585 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
586
587 $this->click("_qf_Confirm_next-bottom");
588 $this->waitForPageToLoad($this->getTimeoutMsec());
589
590 }
591
592 /**
593 * @param $pageId
594 * @param $cid
595 * @param $pageTitle
596 */
597 function _testAnomoyousOganization($pageId, $cid, $pageTitle) {
598 //Open Live Contribution Page
599 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
600
601 $this->click('CIVICRM_QFID_0_8');
602 $this->type('css=div.other_amount-section input', 60);
603
604 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
605 $lastName = 'An' . substr(sha1(rand()), 0, 7);
606 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
607 $this->type("email-5", $firstName . "@example.com");
608
609 // enable onbehalforganization block
610 $this->click("is_for_organization");
611 $this->waitForElementPresent("onbehalf_state_province-3");
612
613 // onbehalforganization info
614 $this->type("onbehalf_organization_name", $orgName);
615 $this->type("onbehalf_phone-3-1", 9999999999);
616 $this->type("onbehalf_email-3", "{$orgName}@example.com");
617 $this->type("onbehalf_street_address-3", "Test Street Address");
618 $this->type("onbehalf_city-3", "Test City");
619 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
620 $this->click("onbehalf_country-3");
621 $this->select("onbehalf_country-3", "label=United States");
622 $this->click("onbehalf_state_province-3");
623 $this->select("onbehalf_state_province-3", "label=Alabama");
624
625 // Credit Card Info
626 $this->select("credit_card_type", "value=Visa");
627 $this->type("credit_card_number", "4111111111111111");
628 $this->type("cvv2", "000");
629 $this->select("credit_card_exp_date[M]", "value=1");
630 $this->select("credit_card_exp_date[Y]", "value=2020");
631
632 //Billing Info
633 $this->type("billing_first_name", $firstName . 'billing');
634 $this->type("billing_last_name", $lastName . 'billing');
635 $this->type("billing_street_address-5", "0121 Mount Highschool.");
636 $this->type(" billing_city-5", "Shangai");
637 $this->select("billing_country_id-5", "value=1228");
638 $this->select("billing_state_province_id-5", "value=1004");
639 $this->type("billing_postal_code-5", "94129");
640 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
641
642 $this->click("_qf_Confirm_next-bottom");
643 $this->waitForPageToLoad($this->getTimeoutMsec());
644
645 //login to check contribution
646
647 // Log in using webtestLogin() method
648 $this->webtestLogin();
649
650 //Find Contribution
651 $this->openCiviPage("contribute/search", "reset=1");
652 $this->type("sort_name", $orgName);
653 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
654 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
655
656 // verify contrb created
657 $expected = array(
658 1 => $orgName,
659 2 => 'Donation',
660 10 => $pageTitle,
661 );
662 foreach ($expected as $value => $label) {
663 $this->verifyText("xpath=id( 'ContributionView' )/div[2]/table[1]/tbody/tr[$value]/td[2]", preg_quote($label));
664 }
665 }
666
667 /**
668 * @param $pageId
669 * @param $cid
670 * @param $pageTitle
671 */
672 function _testUserWithOneRelationship($pageId, $cid, $pageTitle) {
673 $this->webtestLogin('admin');
674
675 // Create new group
676 $groupName = $this->WebtestAddGroup();
677 $this->openCiviPage("group", "reset=1", "_qf_Search_refresh");
678 $groupId = $this->getText("xpath=//table[@id='crm-group-selector']/tbody//tr/td[text()='{$groupName}']/../td[2]");
679
680 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
681
682 $this->click('link=Edit');
683 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
684 $this->click('addressBlock');
685 $this->waitForElementPresent('link=Another Address');
686
687 //Billing Info
688 $this->select('address_1_location_type_id', 'label=Billing');
689 $this->type('address_1_street_address', '0121 Mount Highschool.');
690 $this->type('address_1_city', "Shangai");
691 $this->type('address_1_postal_code', "94129");
692 $this->select('address_1_country_id', "value=1228");
693 $this->select('address_1_state_province_id', "value=1004");
694 $this->click('_qf_Contact_upload_view-bottom');
695 $this->waitForPageToLoad($this->getTimeoutMsec());
696
697 // add contact to group
698 // visit group tab
699 $this->click("css=li#tab_group a");
700 $this->waitForElementPresent("group_id");
701
702 // add to group
703 $this->select("group_id", "label={$groupName}");
704 $this->click("_qf_GroupContact_next");
705 $this->waitForPageToLoad($this->getTimeoutMsec());
706
707 $this->openCiviPage("admin/custom/group", "action=add&reset=1", "_qf_Group_next-bottom");
708
709 // fill in a unique title for the custom group
710 $groupTitle = "Custom Group" . substr(sha1(rand()), 0, 7);
711 $this->type("title", $groupTitle);
712
713 // select the group this custom data set extends
714 $this->select("extends[0]", "value=Contribution");
715 $this->waitForElementPresent("extends[1]");
716
717 // save the custom group
718 $this->click("_qf_Group_next-bottom");
719 $this->waitForElementPresent("_qf_Field_next_new-bottom");
720 $this->assertTrue($this->isTextPresent("Your custom field set '$groupTitle' has been added. You can add custom fields now."));
721
722 // add a custom field to the custom group
723 $fieldTitle = "Custom Field " . substr(sha1(rand()), 0, 7);
724 $this->type("label", $fieldTitle);
725
726 $this->select("data_type[1]", "value=Text");
727 $this->click('_qf_Field_next-bottom');
728
729 $this->waitForPageToLoad($this->getTimeoutMsec());
730 $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
731 $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"));
732
733 // Enable CiviCampaign module if necessary
734 $this->enableComponents("CiviCampaign");
735
736 // add the required permission
737 $permission = array('edit-2-administer-civicampaign');
738 $this->changePermissions($permission);
739
740 // Log in as normal user
741 $this->webtestLogin();
742
743 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
744
745 $title = 'Campaign ' . substr(sha1(rand()), 0, 7);
746 $this->type("title", $title);
747
748 // select the campaign type
749 $this->select("campaign_type_id", "value=2");
750
751 // fill in the description
752 $this->type("description", "This is a test campaign");
753
754 // include groups for the campaign
755 $this->addSelection("includeGroups-f", "label={$groupName}");
756 $this->click("//option[@value={$groupId}]");
757 $this->click("add");
758
759 // fill the end date for campaign
760 $this->webtestFillDate("end_date", "+1 year");
761
762 // select campaign status
763 $this->select("status_id", "value=2");
764
765 // click save
766 $this->click("_qf_Campaign_upload-bottom");
767 $this->waitForElementPresent("xpath=//div[@id='campaigns_wrapper']//table[@id='campaigns']/tbody//tr/td[3][text()='{$title}']");
768 $this->assertTrue($this->isTextPresent("Campaign {$title} has been saved."), "Status message didn't show up after saving!");
769
770 $this->openCiviPage("admin/uf/group", "reset=1");
771 $this->click("link=Reserved Profiles");
772
773 $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']");
774 $this->waitForPageToLoad($this->getTimeoutMsec());
775
776 $this->click("link=Add Field");
777 $this->waitForElementPresent('_qf_Field_next-bottom');
778 $this->select('field_name[0]', 'value=Contribution');
779 $this->select('field_name[1]', 'label=Campaign');
780 $this->click('field_name[1]');
781 $this->click('_qf_Field_next_new-bottom');
782 $this->waitForPageToLoad($this->getTimeoutMsec());
783
784 $this->select('field_name[0]', 'value=Contribution');
785 $this->select('field_name[1]', "label=$fieldTitle :: $groupTitle");
786 $this->click('field_name[1]');
787 $this->click('_qf_Field_next-bottom');
788 $this->waitForPageToLoad($this->getTimeoutMsec());
789 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$fieldTitle}' has been saved to 'On Behalf Of Organization'."));
790
791 // Open Page to create Organization
792 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
793 $orgName1 = 'org1_' . substr(sha1(rand()), 0, 7);
794
795 // Type Organization name
796 $this->type("organization_name", $orgName1);
797
798 // Type Organizatio email for main
799 $this->type("email_1_email", "{$orgName1}@example.com");
800 $this->select("email_1_location_type_id", "value=3");
801
802 // type phone no for main
803 $this->type("phone_1_phone", 9999999999);
804 $this->select("phone_1_location_type_id", "value=3");
805
806 //address section
807 $this->click("addressBlock");
808 $this->waitForElementPresent("address_1_street_address");
809
810 //fill in address 1 for main
811 $this->select("address_1_location_type_id", "value=3");
812 $this->type("address_1_street_address", "{$orgName1} street address");
813 $this->type("address_1_city", "{$orgName1} city");
814 $this->type("address_1_postal_code", substr(sha1(rand()), 0, 4));
815 $this->assertTrue($this->isTextPresent("- select - United States"));
816 $this->select("address_1_state_province_id", "value=1019");
817 $this->type("address_1_geo_code_1", "1234");
818 $this->type("address_1_geo_code_2", "5678");
819
820 // Save the Organization
821 $this->click("_qf_Contact_upload_view-bottom");
822 $this->waitForPageToLoad($this->getTimeoutMsec());
823
824 // open contact
825 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
826
827 // select relationship type
828 $this->click("relationship_type_id");
829 $this->select("relationship_type_id", "value=4_a_b");
830
831 // search organization
832 $this->type('contact_1', $orgName1);
833 $this->click("contact_1");
834 $this->waitForElementPresent("css=div.ac_results-inner li");
835 $this->click("css=div.ac_results-inner li");
836 $this->assertContains($orgName1, $this->getValue('contact_1'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('contact_1'));
837
838 $this->waitForElementPresent("add_current_employer");
839 $this->click("add_current_employer");
840
841 // give permission
842 $this->click("is_permission_a_b");
843 $this->click("is_permission_b_a");
844
845 // save relationship
846 $this->waitForElementPresent("details-save");
847 $this->click("details-save");
848
849 //Open Live Contribution Page
850 $this->openCiviPage("contribute/transact", "reset=1&id={$pageId}&cid=$cid", "onbehalf_state_province-3");
851 $this->click('CIVICRM_QFID_amount_other_radio_4');
852 $this->type('amount_other', 60);
853 $this->click('onbehalf_contribution_campaign_id');
854 $this->select('onbehalf_contribution_campaign_id', "label={$title}");
855 $this->type("onbehalf_custom_{$fieldId}", 'Test Subject');
856
857 // Credit Card Info
858 $this->select("credit_card_type", "value=Visa");
859 $this->type("credit_card_number", "4111111111111111");
860 $this->type("cvv2", "000");
861 $this->select("credit_card_exp_date[M]", "value=1");
862 $this->select("credit_card_exp_date[Y]", "value=2020");
863
864 //Billing Info
865 $this->type("billing_street_address-5", "0121 Mount Highschool.");
866 $this->type(" billing_city-5", "Shangai");
867 $this->select("billing_country_id-5", "value=1228");
868 $this->select("billing_state_province_id-5", "value=1004");
869 $this->type("billing_postal_code-5", "94129");
870
871 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
872 $this->click("_qf_Confirm_next-bottom");
873 $this->waitForPageToLoad($this->getTimeoutMsec());
874
875 //Find Contribution
876 $this->openCiviPage("contribute/search", "reset=1");
877 $this->type("sort_name", $orgName1);
878 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
879 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
880
881 // verify contrb created
882 $expected = array(
883 1 => $orgName1,
884 2 => 'Donation',
885 10 => $title,
886 11 => $pageTitle,
887 );
888 foreach ($expected as $value => $label) {
889 $this->verifyText("xpath=id( 'ContributionView' )/div[2]/table[1]/tbody/tr[$value]/td[2]", preg_quote($label));
890 }
891
892 $this->openCiviPage("admin/uf/group", "reset=1");
893 $this->click("link=Reserved Profiles");
894
895 $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']");
896 $this->waitForPageToLoad($this->getTimeoutMsec());
897
898 $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']");
899 $this->waitForElementPresent('_qf_Field_next-bottom');
900
901 $this->click('_qf_Field_next-bottom');
902 $this->waitForPageToLoad($this->getTimeoutMsec());
903 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'), "Status message didn't show up after saving!");
904
905 $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']");
906 $this->waitForElementPresent('_qf_Field_next-bottom');
907
908 $this->click('_qf_Field_next-bottom');
909 $this->waitForPageToLoad($this->getTimeoutMsec());
910 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'), "Status message didn't show up after saving!");
911 }
912
913 /**
914 * @param $pageId
915 * @param $cid
916 * @param $pageTitle
917 */
918 function _testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle) {
919 $this->webtestLogin('admin');
920 $this->waitForPageToLoad($this->getTimeoutMsec());
921
922 // Create new group
923 $groupName = $this->WebtestAddGroup();
924 $this->openCiviPage("group", "reset=1", '_qf_Search_refresh');
925 $this->click('_qf_Search_refresh');
926 $this->waitForElementPresent("xpath=//div[@id='group']/div[3]/table/tbody//tr/td[text()='{$groupName}']/../td[2]");
927 $groupId = $this->getText("xpath=//div[@id='group']/div[3]/table/tbody//tr/td[text()='{$groupName}']/../td[2]");
928
929 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
930
931 $this->click('link=Edit');
932 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
933 $this->click('addressBlock');
934 $this->waitForElementPresent('link=Another Address');
935
936 //Billing Info
937 $this->select('address_1_location_type_id', 'label=Billing');
938 $this->type('address_1_street_address', '0121 Mount Highschool.');
939 $this->type('address_1_city', "Shangai");
940 $this->type('address_1_postal_code', "94129");
941 $this->select('address_1_country_id', "value=1228");
942 $this->select('address_1_state_province_id', "value=1004");
943 $this->click('_qf_Contact_upload_view-bottom');
944 $this->waitForPageToLoad($this->getTimeoutMsec());
945
946 // add contact to group
947 // visit group tab
948 $this->click("css=li#tab_group a");
949 $this->waitForElementPresent("group_id");
950
951 // add to group
952 $this->select("group_id", "label=$groupName");
953 $this->click("_qf_GroupContact_next");
954 $this->waitForPageToLoad($this->getTimeoutMsec());
955
956 $this->openCiviPage("admin/custom/group", "action=add&reset=1", "_qf_Group_next-bottom");
957
958 // fill in a unique title for the c$groupIdustom group
959 $groupTitle = "Members Custom Group" . substr(sha1(rand()), 0, 7);
960 $this->type("title", $groupTitle);
961
962 // select the group this custom data set extends
963 $this->select("extends[0]", "value=Membership");
964 $this->waitForElementPresent("extends[1]");
965
966 // save the custom group
967 $this->click("_qf_Group_next-bottom");
968
969 $this->waitForElementPresent("_qf_Field_next_new-bottom");
970 $this->assertTrue($this->isTextPresent("Your custom field set '$groupTitle' has been added. You can add custom fields now."));
971
972 // add a custom field to the custom group
973 $fieldTitle = "Member Custom Field " . substr(sha1(rand()), 0, 7);
974 $this->type("label", $fieldTitle);
975
976 $this->select("data_type[1]", "value=Text");
977 $this->click('_qf_Field_next-bottom');
978
979 $this->waitForPageToLoad($this->getTimeoutMsec());
980 $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
981 $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"));
982
983 // Enable CiviCampaign module if necessary
984 $this->enableComponents("CiviCampaign");
985
986 // add the required permission
987 $permission = array('edit-2-administer-civicampaign');
988 $this->changePermissions($permission);
989
990 // Log in as normal user
991 $this->webtestLogin();
992
993 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
994
995 $title = 'Campaign ' . substr(sha1(rand()), 0, 7);
996 $this->type("title", $title);
997
998 // select the campaign type
999 $this->select("campaign_type_id", "value=2");
1000
1001 // fill in the description
1002 $this->type("description", "This is a test campaign");
1003
1004 // include groups for the campaign
1005 $this->addSelection("includeGroups-f", "label={$groupName}");
1006 $this->click("//option[@value={$groupId}]");
1007 $this->click("add");
1008
1009 // fill the end date for campaign
1010 $this->webtestFillDate("end_date", "+1 year");
1011
1012 // select campaign status
1013 $this->select("status_id", "value=2");
1014
1015 // click save
1016 $this->click("_qf_Campaign_upload-bottom");
1017 $this->waitForPageToLoad($this->getTimeoutMsec());
1018
1019 $this->assertTrue($this->isTextPresent("Campaign {$title} has been saved."), "Status message didn't show up after saving!");
1020
1021 $this->openCiviPage("admin/uf/group", "reset=1");
1022 $this->click("link=Reserved Profiles");
1023 $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']");
1024 $this->waitForPageToLoad($this->getTimeoutMsec());
1025
1026 $this->click("link=Add Field");
1027 $this->waitForElementPresent('_qf_Field_next-bottom');
1028 $this->select('field_name[0]', 'value=Membership');
1029 $this->select('field_name[1]', 'label=Campaign');
1030 $this->click('field_name[1]');
1031 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_cancel-bottom');
1032
1033 $this->select('field_name[0]', 'value=Membership');
1034 $this->select('field_name[1]', "label=$fieldTitle :: $groupTitle");
1035 $this->click('field_name[1]');
1036 $this->click('_qf_Field_next-bottom');
1037 $this->waitForPageToLoad($this->getTimeoutMsec());
1038 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$fieldTitle}' has been saved to 'On Behalf Of Organization'."),
1039 "Status message didn't show up after saving!"
1040 );
1041
1042 // Open Page to create Organization 1
1043 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
1044 $orgName1 = 'org1_' . substr(sha1(rand()), 0, 7);
1045
1046 // Type Organization name
1047 $this->type("organization_name", $orgName1);
1048
1049 // Type Organizatio email for main
1050 $this->type("email_1_email", "{$orgName1}@example.com");
1051 $this->select("email_1_location_type_id", "value=3");
1052
1053 // type phone no for main
1054 $this->type("phone_1_phone", substr(sha1(rand()), 0, 4));
1055 $this->select("phone_1_location_type_id", "value=3");
1056
1057 //address section
1058 $this->click("addressBlock");
1059 $this->waitForElementPresent("address_1_street_address");
1060
1061 //fill in address 1 for main
1062 $this->select("address_1_location_type_id", "value=3");
1063 $this->type("address_1_street_address", "{$orgName1} street address");
1064 $this->type("address_1_city", "{$orgName1} city");
1065 $this->type("address_1_postal_code", "9999999999");
1066 $this->assertTrue($this->isTextPresent("- select - United States"));
1067 $this->select("address_1_state_province_id", "value=1019");
1068 $this->type("address_1_geo_code_1", "1234");
1069 $this->type("address_1_geo_code_2", "5678");
1070
1071 // Save the Organization
1072 $this->click("_qf_Contact_upload_view-bottom");
1073 $this->waitForPageToLoad($this->getTimeoutMsec());
1074
1075 // create second orzanization
1076 $this->openCiviPage("contact/add", "reset=1&ct=Organization", "_qf_Contact_upload_view-bottom");
1077 $orgName2 = 'org2_' . substr(sha1(rand()), 0, 7);
1078
1079 // Type Organization name
1080 $this->type("organization_name", $orgName2);
1081
1082 // Type Organizatio email for main
1083 $this->type("email_1_email", "{$orgName2}@example.com");
1084 $this->select("email_1_location_type_id", "value=3");
1085
1086 // type phone no for main
1087 $this->type("phone_1_phone", substr(sha1(rand()), 0, 4));
1088 $this->select("phone_1_location_type_id", "value=3");
1089
1090 //address section
1091 $this->click("addressBlock");
1092 $this->waitForElementPresent("address_1_street_address");
1093
1094 //fill in address 1 for main
1095 $this->select("address_1_location_type_id", "value=3");
1096 $this->type("address_1_street_address", "{$orgName2} street address");
1097 $this->type("address_1_city", "{$orgName2} city");
1098 $this->type("address_1_postal_code", "7777777777");
1099 $this->assertTrue($this->isTextPresent("- select - United States"));
1100 $this->select("address_1_state_province_id", "value=1019");
1101 $this->type("address_1_geo_code_1", "1224");
1102 $this->type("address_1_geo_code_2", "5628");
1103
1104 // Save the Organization
1105 $this->click("_qf_Contact_upload_view-bottom");
1106 $this->waitForPageToLoad($this->getTimeoutMsec());
1107
1108 // create Membership type
1109 $title1 = "Membership Type" . substr(sha1(rand()), 0, 7);
1110 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
1111
1112 $this->click("link=Add Membership Type");
1113 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
1114
1115 $this->type('name', $title1);
1116 $this->type('member_org', $orgName1);
1117 $this->click('_qf_MembershipType_refresh');
1118 $this->waitForElementPresent("xpath=//div[@id='membership_type_form']/fieldset/table[2]/tbody/tr[2]/td[2]");
1119
1120 $this->type('minimum_fee', '50');
1121
1122 $this->select( 'financial_type_id', 'value=2' );
1123
1124 $this->type('duration_interval', 1);
1125 $this->select('duration_unit', "label=year");
1126
1127 $this->select('period_type', "label=fixed");
1128 $this->waitForElementPresent('fixed_period_rollover_day[d]');
1129
1130 $this->select('fixed_period_start_day[M]', 'value=4');
1131 $this->select('fixed_period_rollover_day[M]', 'value=1');
1132
1133 $this->select('relationship_type_id', 'value=4_b_a');
1134
1135 $this->click('_qf_MembershipType_upload-bottom');
1136 $this->waitForElementPresent('link=Add Membership Type');
1137 $this->assertTrue($this->isTextPresent("The membership type '$title1' has been saved."));
1138 $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"));
1139
1140 // open contact
1141 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
1142
1143 // select relationship type
1144 $this->click("relationship_type_id");
1145 $this->select("relationship_type_id", "value=4_a_b");
1146
1147 // search organization
1148 $this->type('contact_1', $orgName1);
1149 $this->click("contact_1");
1150 $this->waitForElementPresent("css=div.ac_results-inner li");
1151 $this->click("css=div.ac_results-inner li");
1152 $this->assertContains($orgName1, $this->getValue('contact_1'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('contact_1'));
1153
1154 // give permission
1155 $this->click("is_permission_a_b");
1156 $this->click("is_permission_b_a");
1157
1158 // save relationship
1159 $this->click("details-save");
1160
1161 // open contact
1162 $this->openCiviPage("contact/view/rel", "cid={$cid}&action=add&reset=1");
1163
1164 // select relationship type
1165 $this->click("relationship_type_id");
1166 $this->select("relationship_type_id", "value=4_a_b");
1167
1168 // search organization
1169 $this->type('contact_1', $orgName2);
1170 $this->click("contact_1");
1171 $this->waitForElementPresent("css=div.ac_results-inner li");
1172 $this->click("css=div.ac_results-inner li");
1173 $this->assertContains($orgName2, $this->getValue('contact_1'), "autocomplete expected $orgName2 but didn’t find it in " . $this->getValue('contact_1'));
1174
1175 // give permission
1176 $this->click("is_permission_a_b");
1177 $this->click("is_permission_b_a");
1178
1179 // save relationship
1180 $this->click("details-save");
1181
1182 // set membership type
1183 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id=$pageId", "_qf_MembershipBlock_upload_done-bottom");
1184 $this->click("member_is_active");
1185 $this->click("membership_type[{$typeId}]");
1186 $this->click("xpath=//div[@id='memberFields']//table[@class='report']/tbody//tr/td[1]/label[text()='{$title1}']/../../td[2]/input");
1187 $this->click('_qf_MembershipBlock_upload_done-bottom');
1188 $this->waitForPageToLoad($this->getTimeoutMsec());
1189
1190 //Open Live Membership Page
1191 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&cid=$cid", "_qf_Main_upload-bottom");
1192 $this->click('CIVICRM_QFID_amount_other_radio_4');
1193 $this->type('amount_other', 60);
1194 $this->click('onbehalf_organization_name');
1195 $this->type('onbehalf_organization_name', $orgName1);
1196 $this->typeKeys('onbehalf_organization_name', $orgName1);
1197 $this->click("onbehalf_organization_name");
1198 $this->waitForElementPresent("css=div.ac_results-inner li");
1199 $this->click("css=div.ac_results-inner li");
1200 // Because it tends to cause problems, all uses of sleep() must be justified in comments
1201 // Sleep should never be used for wait for anything to load from the server
1202 // Justification for this instance: FIXME
1203 sleep(5);
1204 $this->click('onbehalf_member_campaign_id');
1205 $this->select('onbehalf_member_campaign_id', "label={$title}");
1206 $this->type("onbehalf_custom_{$fieldId}", 'Test Subject');
1207
1208 $this->assertContains($orgName1, $this->getValue('onbehalf_organization_name'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('onbehalf_organization_name'));
1209
1210 // Credit Card Info
1211 $this->select("credit_card_type", "value=Visa");
1212 $this->type("credit_card_number", "4111111111111111");
1213 $this->type("cvv2", "000");
1214 $this->select("credit_card_exp_date[M]", "value=1");
1215 $this->select("credit_card_exp_date[Y]", "value=2020");
1216
1217 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
1218 $this->click("_qf_Confirm_next-bottom");
1219 $this->waitForPageToLoad($this->getTimeoutMsec());
1220
1221 //Find Membership for organization
1222 $this->openCiviPage("member/search", "reset=1");
1223 $this->type("sort_name", $orgName1);
1224 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
1225 $this->clickLink("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_MembershipView_cancel-bottom");
1226
1227 //verify contrb created
1228 $expected = array(
1229 1 => $orgName1,
1230 2 => $title1,
1231 3 => 'New',
1232 );
1233 foreach ($expected as $value => $label) {
1234 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1235 }
1236
1237 // find membership for contact in relationship
1238 $this->openCiviPage("contact/view", "reset=1&force=1&cid={$cid}");
1239 $this->click("css=li#tab_member a");
1240 $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']");
1241 $this->click("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']/../td[7]/span/a[text()='View']");
1242 $this->waitForPageToLoad($this->getTimeoutMsec());
1243
1244 //verify contrb created
1245 $expected = array(
1246 3 => $title1,
1247 4 => 'New',
1248 );
1249 foreach ($expected as $value => $label) {
1250 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1251 }
1252
1253 $this->openCiviPage("admin/uf/group", "reset=1");
1254 $this->click("link=Reserved Profiles");
1255 $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']");
1256 $this->waitForPageToLoad($this->getTimeoutMsec());
1257
1258 $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']");
1259 $this->waitForElementPresent('_qf_Field_next-bottom');
1260
1261 $this->click('_qf_Field_next-bottom');
1262 $this->waitForPageToLoad($this->getTimeoutMsec());
1263 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1264 "Status message didn't show up after saving!"
1265 );
1266
1267 $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']");
1268 $this->waitForElementPresent('_qf_Field_next-bottom');
1269
1270 $this->click('_qf_Field_next-bottom');
1271 $this->waitForPageToLoad($this->getTimeoutMsec());
1272 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1273 "Status message didn't show up after saving!"
1274 );
1275
1276 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
1277 $this->click("css=li#tab_rel a");
1278
1279 $this->waitForElementPresent("xpath=//div[@id='current-relationships']/div/table/tbody//tr/td[2]/a[text()='{$orgName1}']");
1280 $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']");
1281
1282 // Check confirmation alert.
1283 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this relationship?/",
1284 $this->getConfirmation()
1285 ));
1286 $this->chooseOkOnNextConfirmation();
1287 $this->waitForPageToLoad($this->getTimeoutMsec());
1288 $this->assertTrue($this->isTextPresent('Selected relationship has been deleted successfully.'),
1289 "Status message didn't show up after saving!"
1290 );
1291 }
1292
1293 function testOnBehalfOfOrganizationWithImage() {
1294 $this->webtestLogin();
1295
1296 $this->openCiviPage("profile/edit", "reset=1&gid=4");
1297 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
1298 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
1299
1300 $this->waitForPageToLoad($this->getTimeoutMsec());
1301 $this->waitForElementPresent("_qf_Edit_next");
1302 $this->type("first_name", $firstName);
1303 $this->type("last_name", $lastName);
1304 $this->clickLink("_qf_Edit_next", "profilewrap4");
1305
1306 $cid = $this->urlArg('id');
1307 $this->assertType('numeric', $cid);
1308 // Is status message correct?
1309 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
1310
1311 $this->openCiviPage("admin/uf/group", "reset=1");
1312 $this->click("link=Reserved Profiles");
1313
1314 $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']");
1315 $this->waitForPageToLoad($this->getTimeoutMsec());
1316
1317 $this->click("link=Add Field");
1318 $this->waitForElementPresent('_qf_Field_next-bottom');
1319
1320 $this->select('field_name[0]', 'value=Contact');
1321 $this->select('field_name[1]', 'label=Image Url');
1322 $this->click('field_name[1]');
1323 $this->click('_qf_Field_next-bottom');
1324 $this->waitForPageToLoad($this->getTimeoutMsec());
1325
1326 // We need a payment processor
1327 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
1328 $processorType = 'Dummy';
1329 $pageTitle = substr(sha1(rand()), 0, 7);
1330 $rand = 100;
1331 $hash = substr(sha1(rand()), 0, 7);
1332 $amountSection = TRUE;
1333 $payLater = TRUE;
1334 $onBehalf = TRUE;
1335 $pledges = FALSE;
1336 $recurring = FALSE;
1337 $memberships = FALSE;
1338 $memPriceSetId = NULL;
1339 $friend = TRUE;
1340 $profilePreId = NULL;
1341 $profilePostId = NULL;
1342 $premiums = FALSE;
1343 $widget = FALSE;
1344 $pcp = FALSE;
1345 $honoreeSection = FALSE;
1346 $isAddPaymentProcessor = TRUE;
1347 $isPcpApprovalNeeded = FALSE;
1348 $isSeparatePayment = FALSE;
1349
1350 // create a new online contribution page
1351 // create contribution page with randomized title and default params
1352 $pageId = $this->webtestAddContributionPage($hash,
1353 $rand,
1354 $pageTitle,
1355 array($processorName => $processorType),
1356 $amountSection,
1357 $payLater,
1358 $onBehalf,
1359 $pledges,
1360 $recurring,
1361 $memberships,
1362 $memPriceSetId,
1363 $friend,
1364 $profilePreId,
1365 $profilePostId,
1366 $premiums,
1367 $widget,
1368 $pcp,
1369 $isAddPaymentProcessor,
1370 $isPcpApprovalNeeded,
1371 $isSeparatePayment,
1372 $honoreeSection
1373 );
1374
1375 $this->_testOrganizationWithImageUpload($pageId, $cid, $pageTitle);
1376
1377 $this->openCiviPage("admin/uf/group", "reset=1");
1378 $this->click("link=Reserved Profiles");
1379
1380 $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']");
1381 $this->waitForPageToLoad($this->getTimeoutMsec());
1382 $this->click("xpath=//table[@id='option11']/tbody//tr/td/span[text()='Image Url']/../following-sibling::td[8]/span[2]/ul/li[2]/a");
1383 $this->waitForPageToLoad($this->getTimeoutMsec());
1384 $this->click('_qf_Field_next-bottom');
1385 $this->waitForPageToLoad($this->getTimeoutMsec());
1386 $this->waitForText('crm-notification-container', "Selected Profile Field has been deleted.");
1387 }
1388
1389 /**
1390 * @param $pageId
1391 * @param $cid
1392 * @param $pageTitle
1393 */
1394 function _testOrganizationWithImageUpload($pageId, $cid, $pageTitle) {
1395 //Open Live Contribution Page
1396 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", '_qf_Main_upload-bottom');
1397
1398 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
1399 $lastName = 'An' . substr(sha1(rand()), 0, 7);
1400 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
1401 $this->type("email-5", $firstName . "@example.com");
1402
1403 // onbehalforganization info
1404 $this->type("onbehalf_organization_name", $orgName);
1405 $this->type("onbehalf_phone-3-1", 9999999999);
1406 $this->type("onbehalf_email-3", "{$orgName}@example.com");
1407 $this->type("onbehalf_street_address-3", "Test Street Address");
1408 $this->type("onbehalf_city-3", "Test City");
1409 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
1410 $this->click("onbehalf_country-3");
1411 $this->select("onbehalf_country-3", "label=United States");
1412 $this->click("onbehalf_state_province-3");
1413 $this->select("onbehalf_state_province-3", "label=Alabama");
1414
1415 // check for upload field.
1416 $this->waitForElementPresent("onbehalf_image_URL");
1417
1418 //header("Content-Type: image/png");
1419 $im = imagecreate(110, 20)
1420 or die("Cannot Initialize new GD image stream");
1421 $background_color = imagecolorallocate($im, 0, 0, 0);
1422 $text_color = imagecolorallocate($im, 233, 14, 91);
1423 imagestring($im, 1, 5, 5, "On Behalf-Org Logo", $text_color);
1424 imagepng($im,"/tmp/file.png");
1425
1426 $imagePath = "/tmp/file.png";
1427 $this->webtestAttachFile('onbehalf_image_URL', $imagePath);
1428 unlink($imagePath);
1429
1430 // Credit Card Info
1431 $this->select("credit_card_type", "value=Visa");
1432 $this->type("credit_card_number", "4111111111111111");
1433 $this->type("cvv2", "000");
1434 $this->select("credit_card_exp_date[M]", "value=1");
1435 $this->select("credit_card_exp_date[Y]", "value=2020");
1436
1437 //Billing Info
1438 $this->type("billing_first_name", $firstName . 'billing');
1439 $this->type("billing_last_name", $lastName . 'billing');
1440 $this->type("billing_street_address-5", "0121 Mount Highschool.");
1441 $this->type(" billing_city-5", "Shangai");
1442 $this->select("billing_country_id-5", "value=1228");
1443 $this->select("billing_state_province_id-5", "value=1004");
1444 $this->type("billing_postal_code-5", "94129");
1445 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
1446
1447 $this->click("_qf_Confirm_next-bottom");
1448 $this->waitForPageToLoad($this->getTimeoutMsec());
1449
1450 // Type search name in autocomplete.
1451 $this->click('sort_name_navigation');
1452 $this->type('css=input#sort_name_navigation', $orgName);
1453 $this->typeKeys('css=input#sort_name_navigation', $orgName);
1454
1455 // Wait for result list.
1456 $this->waitForElementPresent("css=div.ac_results-inner li");
1457
1458 // Visit organization page.
1459 $this->click("css=div.ac_results-inner li");
1460 $this->waitForPageToLoad($this->getTimeoutMsec());
1461
1462 //check whether the image is present
1463 $this->assertTrue($this->isElementPresent("xpath=//div[@id='crm-contact-thumbnail']/div/a/img"));
1464 }
1465 }
1466