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