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