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