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