3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contribute_OnBehalfOfOrganization
extends CiviSeleniumTestCase
{
30 protected $pageno = '';
31 protected function setUp() {
35 function testOnBehalfOfOrganization() {
37 // This is the path where our testing install resides.
38 // The rest of URL is defined in CiviSeleniumTestCase base class, in
40 $this->open($this->sboxPath
);
42 // Logging in. Remember to wait for page to load. In most cases,
43 // you can rely on 30000 as the value that allows your test to pass, however,
44 // sometimes your test might fail because of this. In such cases, it's better to pick one element
45 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
46 // page contents loaded and you can continue your test execution.
47 $this->webtestLogin();
49 // create new individual
50 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
51 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
52 $email = "{$firstName}.{$lastName}@example.com";
53 $contactParams = array(
54 'first_name' => $firstName,
55 'last_name' => $lastName,
58 $streetAddress = "100 Main Street";
60 //adding contact for membership sign up
61 $this->webtestAddContact($firstName, $lastName, $email);
62 $urlElements = $this->parseURL();
63 print_r($urlElements);
64 $cid = $urlElements['queryString']['cid'];
65 $this->assertType('numeric', $cid);
67 // We need a payment processor
68 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
69 $processorType = 'Dummy';
70 $pageTitle = substr(sha1(rand()), 0, 7);
72 $hash = substr(sha1(rand()), 0, 7);
73 $amountSection = TRUE;
75 $onBehalf = 'optional';
79 $memPriceSetId = NULL;
82 $profilePostId = NULL;
86 $honoreeSection = FALSE;
87 $isAddPaymentProcessor = TRUE;
88 $isPcpApprovalNeeded = FALSE;
89 $isSeparatePayment = FALSE;
91 // create a new online contribution page
92 // create contribution page with randomized title and default params
93 $pageId = $this->webtestAddContributionPage($hash,
96 array($processorName => $processorType),
110 $isAddPaymentProcessor,
111 $isPcpApprovalNeeded,
117 $this->open($this->sboxPath
. "civicrm/logout?reset=1");
118 $this->waitForPageToLoad($this->getTimeoutMsec());
119 //$this->_testAnomoyousOganization($pageId, $cid, $pageTitle);
120 $this->open($this->sboxPath
. "civicrm/logout?reset=1");
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122 $this->_testUserWithOneRelationship($pageId, $cid, $pageTitle);
123 $this->open($this->sboxPath
. "civicrm/logout?reset=1");
124 $this->waitForPageToLoad($this->getTimeoutMsec());
125 $this->_testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle);
128 function testOnBehalfOfOrganizationWithMembershipData() {
129 // This is the path where our testing install resides.
130 // The rest of URL is defined in CiviSeleniumTestCase base class, in
132 $this->open($this->sboxPath
);
134 // Logging in. Remember to wait for page to load. In most cases,
135 // you can rely on 30000 as the value that allows your test to pass, however,
136 // sometimes your test might fail because of this. In such cases, it's better to pick one element
137 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
138 // page contents loaded and you can continue your test execution.
139 $this->webtestLogin();
141 // create new individual
142 $this->open($this->sboxPath
. "civicrm/profile/edit?reset=1&gid=4");
143 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
144 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
146 $this->waitForPageToLoad($this->getTimeoutMsec());
147 $this->waitForElementPresent("_qf_Edit_next");
148 $this->type("first_name", $firstName);
149 $this->type("last_name", $lastName);
150 $this->click("_qf_Edit_next");
151 $this->waitForPageToLoad($this->getTimeoutMsec());
152 $this->waitForElementPresent("profilewrap4");
154 // Is status message correct?
155 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
158 // Go directly to the URL of the screen that you will be testing (New Custom Group).
159 $this->open($this->sboxPath
. "civicrm/admin/custom/group?action=add&reset=1");
160 $this->waitForPageToLoad($this->getTimeoutMsec());
162 //fill custom group title
163 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
164 $this->click("title");
165 $this->type("title", $customGroupTitle);
167 //custom group extends
168 $this->click("extends[0]");
169 $this->select("extends[0]", "value=Membership");
170 //$this->click("//option[@value='Contact']");
171 $this->click("_qf_Group_next-bottom");
172 $this->waitForElementPresent("_qf_Field_cancel-bottom");
174 //Is custom group created?
175 $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."));
177 //add custom field - alphanumeric checkbox
178 $checkboxFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
179 $this->click("label");
180 $this->type("label", $checkboxFieldLabel);
181 $this->click("data_type[1]");
182 $this->select("data_type[1]", "value=CheckBox");
183 $this->click("//option[@value='CheckBox']");
184 $checkboxOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
185 $this->type("option_label_1", $checkboxOptionLabel1);
186 $this->type("option_value_1", "1");
187 $checkboxOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
188 $this->type("option_label_2", $checkboxOptionLabel2);
189 $this->type("option_value_2", "2");
190 $this->click("link=another choice");
191 $checkboxOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
192 $this->type("option_label_3", $checkboxOptionLabel3);
193 $this->type("option_value_3", "3");
195 //enter options per line
196 $this->type("options_per_line", "2");
198 //enter pre help message
199 $this->type("help_pre", "this is field pre help");
201 //enter post help message
202 $this->type("help_post", "this field post help");
205 $this->click("is_searchable");
208 $this->click("_qf_Field_next");
209 $this->waitForPageToLoad($this->getTimeoutMsec());
211 //Is custom field created?
212 $this->assertTrue($this->isTextPresent("Your custom field '$checkboxFieldLabel' has been saved."));
214 //create another custom field - Integer Radio
215 $this->click("//a[@id='newCustomField']/span");
216 $this->waitForPageToLoad($this->getTimeoutMsec());
217 $this->click("data_type[0]");
218 $this->select("data_type[0]", "value=1");
219 $this->click("//option[@value='1']");
220 $this->click("data_type[1]");
221 $this->select("data_type[1]", "value=Radio");
222 $this->click("//option[@value='Radio']");
224 $radioFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
225 $this->type("label", $radioFieldLabel);
226 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
227 $this->type("option_label_1", $radioOptionLabel1);
228 $this->type("option_value_1", "1");
229 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
230 $this->type("option_label_2", $radioOptionLabel2);
231 $this->type("option_value_2", "2");
232 $this->click("link=another choice");
233 $radioOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
234 $this->type("option_label_3", $radioOptionLabel3);
235 $this->type("option_value_3", "3");
237 //select options per line
238 $this->type("options_per_line", "3");
241 $this->type("help_pre", "this is field pre help");
243 //enter post help msg
244 $this->type("help_post", "this is field post help");
247 $this->click("is_searchable");
250 $this->click("_qf_Field_next");
251 $this->waitForPageToLoad($this->getTimeoutMsec());
253 //Is custom field created
254 $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved."));
256 //add the above custom data to the On Behalf of Profile
257 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
258 $this->waitForPageToLoad($this->getTimeoutMsec());
259 $this->click("link=Reserved Profiles");
261 $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']");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
264 $this->click("link=Add Field");
265 $this->waitForElementPresent('_qf_Field_next-bottom');
266 $this->select('field_name[0]', 'value=Membership');
267 $label = $checkboxFieldLabel.' :: '. $customGroupTitle;
268 $this->select('field_name[1]', "label=$label");
269 $this->click('field_name[1]');
270 $this->click('_qf_Field_next_new-bottom');
271 $this->waitForPageToLoad($this->getTimeoutMsec());
273 $this->select('field_name[0]', 'value=Membership');
274 $label = $radioFieldLabel.' :: '. $customGroupTitle;
275 $this->select('field_name[1]', "label=$label");
276 $this->click('field_name[1]');
277 $this->click('_qf_Field_next-bottom');
278 $this->waitForPageToLoad($this->getTimeoutMsec());
279 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$radioFieldLabel}' has been saved to 'On Behalf Of Organization'."));
281 //create organisation
282 $orgName = "Org WebAccess ". substr(sha1(rand()), 0, 7);
283 $orgEmail = "org". substr(sha1(rand()), 0, 7) . "@web.com";
284 $this->webtestAddOrganization($orgName, $orgEmail);
286 $this->waitForPageToLoad($this->getTimeoutMsec());
287 $this->click("css=li#tab_member a");
289 $this->waitForElementPresent('link=Add Membership');
290 $this->click('link=Add Membership');
292 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
294 // fill in Membership Organization and Type
295 $this->select('membership_type_id[0]', "value=1");
296 $this->select('membership_type_id[1]', "value=1");
299 $sourceText = 'On behalf Membership Webtest';
300 $this->type('source', $sourceText);
302 $this->waitForElementPresent("css=div#{$customGroupTitle} div.crm-accordion-header");
303 $this->click("css=div#{$customGroupTitle} div.crm-accordion-header");
304 //$this->waitForElementPresent('_qf_Membership_cancel-bottom111');
306 // select newly created processor
307 $xpath = "xpath=//label[text() = '{$checkboxOptionLabel1}']/preceding-sibling::input[1]";
308 $this->assertTrue($this->isTextPresent($checkboxOptionLabel1));
309 $this->check($xpath);
311 $xpath = "xpath=//label[text() = '{$checkboxOptionLabel3}']/preceding-sibling::input[1]";
312 $this->assertTrue($this->isTextPresent($checkboxOptionLabel3));
313 $this->check($xpath);
315 $xpath = "xpath=//label[text() = '{$radioOptionLabel1}']/preceding-sibling::input[1]";
316 $this->assertTrue($this->isTextPresent($radioOptionLabel1));
317 $this->check($xpath);
319 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
320 $this->click('_qf_Membership_upload-bottom');
323 $this->waitForPageToLoad($this->getTimeoutMsec());
324 $this->click("css=li#tab_rel a");
326 $this->waitForElementPresent('link=Add Relationship');
327 $this->click('link=Add Relationship');
329 $this->waitForElementPresent('relationship_type_id');
330 $this->click("relationship_type_id");
331 $this->select("relationship_type_id", "label=Employer of");
332 // search organization
333 $this->type('contact_1', $firstName);
334 $this->click("contact_1");
335 $this->waitForElementPresent("css=div.ac_results-inner li");
336 $this->click("css=div.ac_results-inner li");
337 $this->assertContains($firstName, $this->getValue('contact_1'), "autocomplete expected $firstName but didn’t find it in " . $this->getValue('contact_1'));
340 $this->click("is_permission_a_b");
341 $this->click("is_permission_b_a");
344 $this->click("details-save");
345 $this->waitForPageToLoad($this->getTimeoutMsec());
347 // We need a payment processor
348 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
349 $processorType = 'Dummy';
350 $pageTitle = substr(sha1(rand()), 0, 7);
352 $hash = substr(sha1(rand()), 0, 7);
353 $amountSection = TRUE;
359 $memPriceSetId = NULL;
361 $profilePreId = NULL;
362 $profilePostId = NULL;
366 $honoreeSection = FALSE;
367 $isAddPaymentProcessor = TRUE;
368 $isPcpApprovalNeeded = FALSE;
369 $isSeparatePayment = FALSE;
371 // create a new online contribution page
372 // create contribution page with randomized title and default params
373 $pageId = $this->webtestAddContributionPage($hash,
376 array($processorName => $processorType),
390 $isAddPaymentProcessor,
391 $isPcpApprovalNeeded,
397 //scenario 1 : add membership data in pre / post profile and check for formRule
399 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
401 $this->waitForPageToLoad($this->getTimeoutMsec());
402 $this->click('link=Add Profile');
404 $profileTitle = "test profile" . substr(sha1(rand()), 0, 7);
405 // Add membership custom data field to profile
406 $this->waitForElementPresent('_qf_Group_cancel-bottom');
407 $this->type('title', $profileTitle);
408 $this->click('_qf_Group_next-bottom');
410 $this->waitForElementPresent('_qf_Field_cancel-bottom');
411 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."));
413 $this->select('field_name[0]', "value=Membership");
414 $this->select('field_name[1]', "label={$checkboxFieldLabel} :: {$customGroupTitle}");
415 $this->click('field_name[1]');
416 $this->click('label');
418 // Clicking save and new
419 $this->click('_qf_Field_next_new-bottom');
420 $this->waitForPageToLoad($this->getTimeoutMsec());
421 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$checkboxFieldLabel}' has been saved to '{$profileTitle}'."));
423 $this->open($this->sboxPath
. "civicrm/admin/contribute/custom?reset=1&action=update&id={$pageId}");
424 $this->waitForElementPresent('_qf_Custom_next-bottom');
425 $this->select('custom_pre_id', "label={$profileTitle}");
426 $this->click('_qf_Custom_next-bottom');
427 $this->waitForPageToLoad($this->getTimeoutMsec());
429 $this->assertTrue($this->isTextPresent('You should move the membership related fields in the "On Behalf" profile for this Contribution Page'), "Form rule didn't showed up while incorrectly configuring membership fields profile for 'on behalf of' contribution page");
431 $this->select('custom_pre_id', "- select -");
432 $this->select('custom_post_id', "label={$profileTitle}");
433 $this->click('_qf_Custom_next-bottom');
434 $this->waitForPageToLoad($this->getTimeoutMsec());
436 $this->assertTrue($this->isTextPresent('You should move the membership related fields in the "On Behalf" profile for this Contribution Page'), "Form rule didn't showed up while incorrectly configuring membership fields profile for 'on behalf of' contribution page");
438 //scenario 2 : disable 'on behalf of', add membership data in pre / post profile
439 //then try to add 'on behalf of' and check for formRule
440 //disable 'on behalf of'
441 $this->open($this->sboxPath
. "civicrm/admin/contribute/settings?reset=1&action=update&id={$pageId}");
442 $this->waitForElementPresent('_qf_Settings_next-bottom');
443 $this->uncheck('is_organization');
444 $this->click('_qf_Settings_next-bottom');
445 $this->waitForPageToLoad($this->getTimeoutMsec());
447 //set a membership field profile for this contribution page
448 $this->click('css=li#tab_custom a');
449 $this->waitForElementPresent('_qf_Custom_next-bottom');
450 $this->select('custom_pre_id', "label={$profileTitle}");
451 $this->click('_qf_Custom_next-bottom');
452 $this->waitForPageToLoad($this->getTimeoutMsec());
454 //now visit the title settings page and configure the profile as on behalf of
455 $this->click('css=li#tab_settings a');
456 $this->waitForElementPresent('_qf_Settings_next-bottom');
457 $this->check('is_organization');
458 $this->click('_qf_Settings_next-bottom');
459 $this->waitForPageToLoad($this->getTimeoutMsec());
461 $this->assertTrue($this->isTextPresent("You should move the membership related fields configured in 'Includes Profile (top of page)' to the 'On Behalf' profile for this Contribution Page"), "Form rule 'You should move the membership related fields configured in 'Includes Profile (top of page)' to the 'On Behalf' profile for this Contribution Page' didn't showed up");
464 $this->open($this->sboxPath
. "civicrm/logout?reset=1");
465 $this->waitForPageToLoad($this->getTimeoutMsec());
468 function testOnBehalfOfOrganizationWithOrgData()
471 // This is the path where our testing install resides.
472 // The rest of URL is defined in CiviSeleniumTestCase base class, in
474 $this->open($this->sboxPath
);
476 // Logging in. Remember to wait for page to load. In most cases,
477 // you can rely on 30000 as the value that allows your test to pass, however,
478 // sometimes your test might fail because of this. In such cases, it's better to pick one element
479 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
480 // page contents loaded and you can continue your test execution.
481 $this->webtestLogin();
483 $this->open($this->sboxPath
. "civicrm/profile/edit?reset=1&gid=4");
484 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
485 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
487 $this->waitForPageToLoad($this->getTimeoutMsec());
488 $this->waitForElementPresent("_qf_Edit_next");
489 $this->type("first_name", $firstName);
490 $this->type("last_name", $lastName);
491 $this->click("_qf_Edit_next");
492 $this->waitForPageToLoad($this->getTimeoutMsec());
493 $this->waitForElementPresent("profilewrap4");
495 $urlElements = $this->parseURL();
496 print_r($urlElements);
497 $cid = $urlElements['queryString']['id'];
498 $this->assertType('numeric', $cid);
499 // Is status message correct?
500 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
503 //add org fields to profile
504 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
505 $this->waitForPageToLoad($this->getTimeoutMsec());
506 $this->click("link=Reserved Profiles");
508 $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']");
509 $this->waitForPageToLoad($this->getTimeoutMsec());
511 $this->click("link=Add Field");
512 $this->waitForElementPresent('_qf_Field_next-bottom');
514 $this->select('field_name[0]', 'value=Organization');
515 $this->select('field_name[1]', 'label=Legal Identifier');
516 $this->click('field_name[1]');
517 $this->click('_qf_Field_next_new-bottom');
518 $this->waitForPageToLoad($this->getTimeoutMsec());
520 $this->select('field_name[0]', 'value=Organization');
521 $this->select('field_name[1]', 'label=Legal Name');
522 $this->click('field_name[1]');
523 $this->click('_qf_Field_next-bottom');
524 $this->waitForPageToLoad($this->getTimeoutMsec());
527 //create organisation
528 $orgName = "Org WebAccess ". substr(sha1(rand()), 0, 7);
529 $orgEmail = "org". substr(sha1(rand()), 0, 7) . "@web.com";
530 $this->webtestAddOrganization($orgName, $orgEmail);
532 $this->waitForPageToLoad($this->getTimeoutMsec());
533 $this->click("css=li#tab_rel a");
535 $this->waitForElementPresent('link=Add Relationship');
536 $this->click('link=Add Relationship');
538 $this->waitForElementPresent('relationship_type_id');
539 $this->click("relationship_type_id");
540 $this->select("relationship_type_id", "label=Employer of");
541 // search organization
542 $this->type('contact_1', $firstName);
543 $this->click("contact_1");
544 $this->waitForElementPresent("css=div.ac_results-inner li");
545 $this->click("css=div.ac_results-inner li");
546 $this->assertContains($firstName, $this->getValue('contact_1'), "autocomplete expected $firstName but didn’t find it in " . $this->getValue('contact_1'));
549 $this->click("is_permission_a_b");
550 $this->click("is_permission_b_a");
553 $this->waitForElementPresent("details-save");
554 $this->click("details-save");
555 $this->waitForElementPresent("Relationships");
557 $pageTitle = substr(sha1(rand()), 0, 7);
559 $hash = substr(sha1(rand()), 0, 7);
560 $amountSection = TRUE;
566 $memPriceSetId = NULL;
568 $profilePreId = NULL;
569 $profilePostId = NULL;
573 $honoreeSection = FALSE;
574 $isAddPaymentProcessor = FALSE;
575 $isPcpApprovalNeeded = FALSE;
576 $isSeparatePayment = FALSE;
578 // create a new online contribution page
579 // create contribution page with randomized title and default params
580 $pageId = $this->webtestAddContributionPage($hash,
597 $isAddPaymentProcessor,
598 $isPcpApprovalNeeded,
603 $this->_testOrganization($pageId, $cid, $pageTitle);
607 function _testOrganization($pageId, $cid, $pageTitle) {
608 //Open Live Contribution Page
609 $this->open($this->sboxPath
. "civicrm/contribute/transact?reset=1&id=" . $pageId);
611 $this->waitForElementPresent("_qf_Main_upload-bottom");
613 $this->waitForElementPresent("onbehalf_state_province-3");
615 $this->waitForElementPresent("onbehalf_phone-3-1");
616 $this->type("onbehalf_phone-3-1", 9999999999);
617 $this->waitForElementPresent("onbehalf_email-3");
618 $this->type("onbehalf_email-3", "org@example.com");
619 $this->type("onbehalf_street_address-3", "Test Street Address");
620 $this->type("onbehalf_city-3", "Test City");
621 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
622 $this->click("onbehalf_country-3");
623 $this->select("onbehalf_country-3", "label=United States");
624 $this->click("onbehalf_state_province-3");
625 $this->select("onbehalf_state_province-3", "label=Alabama");
627 $this->waitForElementPresent("_qf_Main_upload-bottom");
628 $this->click("_qf_Main_upload-bottom");
630 $this->waitForPageToLoad($this->getTimeoutMsec());
632 $this->waitForElementPresent("_qf_Confirm_next-bottom");
634 $this->click("_qf_Confirm_next-bottom");
635 $this->waitForPageToLoad($this->getTimeoutMsec());
639 function _testAnomoyousOganization($pageId, $cid, $pageTitle) {
640 //Open Live Contribution Page
641 $this->open($this->sboxPath
. "civicrm/contribute/transact?reset=1&id=" . $pageId);
643 $this->waitForElementPresent("_qf_Main_upload-bottom");
645 $this->click('CIVICRM_QFID_0_8');
646 $this->type('css=div.other_amount-section input', 60);
648 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
649 $lastName = 'An' . substr(sha1(rand()), 0, 7);
650 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
651 $this->type("email-5", $firstName . "@example.com");
653 // enable onbehalforganization block
654 $this->click("is_for_organization");
655 $this->waitForElementPresent("onbehalf_state_province-3");
657 // onbehalforganization info
658 $this->type("onbehalf_organization_name", $orgName);
659 $this->type("onbehalf_phone-3-1", 9999999999);
660 $this->type("onbehalf_email-3", "{$orgName}@example.com");
661 $this->type("onbehalf_street_address-3", "Test Street Address");
662 $this->type("onbehalf_city-3", "Test City");
663 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
664 $this->click("onbehalf_country-3");
665 $this->select("onbehalf_country-3", "label=United States");
666 $this->click("onbehalf_state_province-3");
667 $this->select("onbehalf_state_province-3", "label=Alabama");
671 $this->select("credit_card_type", "value=Visa");
672 $this->type("credit_card_number", "4111111111111111");
673 $this->type("cvv2", "000");
674 $this->select("credit_card_exp_date[M]", "value=1");
675 $this->select("credit_card_exp_date[Y]", "value=2020");
678 $this->type("billing_first_name", $firstName . 'billing');
679 $this->type("billing_last_name", $lastName . 'billing');
680 $this->type("billing_street_address-5", "0121 Mount Highschool.");
681 $this->type(" billing_city-5", "Shangai");
682 $this->select("billing_country_id-5", "value=1228");
683 $this->select("billing_state_province_id-5", "value=1004");
684 $this->type("billing_postal_code-5", "94129");
685 $this->click("_qf_Main_upload-bottom");
687 $this->waitForPageToLoad($this->getTimeoutMsec());
688 $this->waitForElementPresent("_qf_Confirm_next-bottom");
690 $this->click("_qf_Confirm_next-bottom");
691 $this->waitForPageToLoad($this->getTimeoutMsec());
693 //login to check contribution
694 $this->open($this->sboxPath
);
696 // Log in using webtestLogin() method
697 $this->webtestLogin();
700 $this->open($this->sboxPath
. "civicrm/contribute/search?reset=1");
701 $this->type("sort_name", $orgName);
702 $this->click("_qf_Search_refresh");
704 $this->waitForPageToLoad($this->getTimeoutMsec());
706 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
707 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
708 $this->waitForPageToLoad($this->getTimeoutMsec());
709 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
711 // verify contrb created
717 foreach ($expected as $value => $label) {
718 $this->verifyText("xpath=id( 'ContributionView' )/div[2]/table[1]/tbody/tr[$value]/td[2]", preg_quote($label));
722 function _testUserWithOneRelationship($pageId, $cid, $pageTitle) {
723 // Logging in. Remember to wait for page to load. In most cases,
724 // you can rely on 30000 as the value that allows your test to pass, however,
725 // sometimes your test might fail because of this. In such cases, it's better to pick one element
726 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
727 // page contents loaded and you can continue your test execution.
728 $this->webtestLogin();
729 $this->waitForPageToLoad($this->getTimeoutMsec());
732 $groupName = $this->WebtestAddGroup();
733 $this->open($this->sboxPath
. "civicrm/group?reset=1");
734 $this->waitForPageToLoad($this->getTimeoutMsec());
735 $this->waitForElementPresent("_qf_Search_refresh");
736 $groupId = $this->getText("xpath=//table[@id='crm-group-selector']/tbody//tr/td[text()='{$groupName}']/../td[2]");
738 $this->open($this->sboxPath
. "civicrm/contact/view?reset=1&cid={$cid}");
739 $this->waitForPageToLoad($this->getTimeoutMsec());
741 $this->click('link=Edit');
742 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
743 $this->click('addressBlock');
744 $this->waitForElementPresent('link=Another Address');
747 $this->select('address_1_location_type_id', 'label=Billing');
748 $this->type('address_1_street_address', '0121 Mount Highschool.');
749 $this->type('address_1_city', "Shangai");
750 $this->type('address_1_postal_code', "94129");
751 $this->select('address_1_country_id', "value=1228");
752 $this->select('address_1_state_province_id', "value=1004");
753 $this->click('_qf_Contact_upload_view-bottom');
754 $this->waitForPageToLoad($this->getTimeoutMsec());
756 // add contact to group
758 $this->click("css=li#tab_group a");
759 $this->waitForElementPresent("group_id");
762 $this->select("group_id", "label={$groupName}");
763 $this->click("_qf_GroupContact_next");
764 $this->waitForPageToLoad($this->getTimeoutMsec());
766 $this->open($this->sboxPath
. "civicrm/admin/custom/group?action=add&reset=1");
767 $this->waitForElementPresent("_qf_Group_next-bottom");
769 // fill in a unique title for the custom group
770 $groupTitle = "Custom Group" . substr(sha1(rand()), 0, 7);
771 $this->type("title", $groupTitle);
773 // select the group this custom data set extends
774 $this->select("extends[0]", "value=Contribution");
775 $this->waitForElementPresent("extends[1]");
777 // save the custom group
778 $this->click("_qf_Group_next-bottom");
779 $this->waitForElementPresent("_qf_Field_next_new-bottom");
780 $this->assertTrue($this->isTextPresent("Your custom field set '$groupTitle' has been added. You can add custom fields now."));
782 // add a custom field to the custom group
783 $fieldTitle = "Custom Field " . substr(sha1(rand()), 0, 7);
784 $this->type("label", $fieldTitle);
786 $this->select("data_type[1]", "value=Text");
787 $this->click('_qf_Field_next-bottom');
789 $this->waitForPageToLoad($this->getTimeoutMsec());
790 $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
791 $url = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']/div[2]/table/tbody//tr/td[1][text()='$fieldTitle']/../td[8]/span/a@href"));
794 // Enable CiviCampaign module if necessary
795 $this->enableComponents("CiviCampaign");
797 // add the required Drupal permission
798 $permission = array('edit-2-administer-civicampaign');
799 $this->changePermissions($permission);
801 // Go directly to the URL of the screen that you will be add campaign
802 $this->open($this->sboxPath
. "civicrm/campaign/add?reset=1");
804 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
805 // button at the end of this page to show up, to make sure it's fully loaded.
806 $this->waitForElementPresent("_qf_Campaign_upload-bottom");
808 // Let's start filling the form with values.
809 $title = 'Campaign ' . substr(sha1(rand()), 0, 7);
810 $this->type("title", $title);
812 // select the campaign type
813 $this->select("campaign_type_id", "value=2");
815 // fill in the description
816 $this->type("description", "This is a test campaign");
818 // include groups for the campaign
819 $this->addSelection("includeGroups-f", "label={$groupName}");
820 $this->click("//option[@value={$groupId}]");
823 // fill the end date for campaign
824 $this->webtestFillDate("end_date", "+1 year");
826 // select campaign status
827 $this->select("status_id", "value=2");
830 $this->click("_qf_Campaign_upload-bottom");
831 $this->waitForElementPresent("xpath=//div[@id='campaigns_wrapper']//table[@id='campaigns']/tbody//tr/td[3][text()='{$title}']");
832 $this->assertTrue($this->isTextPresent("Campaign {$title} has been saved."), "Status message didn't show up after saving!");
834 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
835 $this->waitForPageToLoad($this->getTimeoutMsec());
836 $this->click("link=Reserved Profiles");
838 $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']");
839 $this->waitForPageToLoad($this->getTimeoutMsec());
841 $this->click("link=Add Field");
842 $this->waitForElementPresent('_qf_Field_next-bottom');
843 $this->select('field_name[0]', 'value=Contribution');
844 $this->select('field_name[1]', 'label=Campaign');
845 $this->click('field_name[1]');
846 $this->click('_qf_Field_next_new-bottom');
847 $this->waitForPageToLoad($this->getTimeoutMsec());
849 $this->select('field_name[0]', 'value=Contribution');
850 $this->select('field_name[1]', "label=$fieldTitle :: $groupTitle");
851 $this->click('field_name[1]');
852 $this->click('_qf_Field_next-bottom');
853 $this->waitForPageToLoad($this->getTimeoutMsec());
854 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$fieldTitle}' has been saved to 'On Behalf Of Organization'."));
856 // Open Page to create Organization
857 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Organization");
858 $this->waitForElementPresent("_qf_Contact_upload_view-bottom");
859 $orgName1 = 'org1_' . substr(sha1(rand()), 0, 7);
861 // Type Organization name
862 $this->type("organization_name", $orgName1);
864 // Type Organizatio email for main
865 $this->type("email_1_email", "{$orgName1}@example.com");
866 $this->select("email_1_location_type_id", "value=3");
868 // type phone no for main
869 $this->type("phone_1_phone", 9999999999);
870 $this->select("phone_1_location_type_id", "value=3");
873 $this->click("addressBlock");
874 $this->waitForElementPresent("address_1_street_address");
876 //fill in address 1 for main
877 $this->select("address_1_location_type_id", "value=3");
878 $this->type("address_1_street_address", "{$orgName1} street address");
879 $this->type("address_1_city", "{$orgName1} city");
880 $this->type("address_1_postal_code", substr(sha1(rand()), 0, 4));
881 $this->assertTrue($this->isTextPresent("- select - United States"));
882 $this->select("address_1_state_province_id", "value=1019");
883 $this->type("address_1_geo_code_1", "1234");
884 $this->type("address_1_geo_code_2", "5678");
886 // Save the Organization
887 $this->click("_qf_Contact_upload_view-bottom");
888 $this->waitForPageToLoad($this->getTimeoutMsec());
891 $this->open($this->sboxPath
. "civicrm/contact/view/rel?cid={$cid}&action=add&reset=1");
892 $this->waitForPageToLoad($this->getTimeoutMsec());
894 // select relationship type
895 $this->click("relationship_type_id");
896 $this->select("relationship_type_id", "value=4_a_b");
898 // search organization
899 $this->type('contact_1', $orgName1);
900 $this->click("contact_1");
901 $this->waitForElementPresent("css=div.ac_results-inner li");
902 $this->click("css=div.ac_results-inner li");
903 $this->assertContains($orgName1, $this->getValue('contact_1'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('contact_1'));
905 $this->waitForElementPresent("add_current_employer");
906 $this->click("add_current_employer");
909 $this->click("is_permission_a_b");
910 $this->click("is_permission_b_a");
913 $this->waitForElementPresent("details-save");
914 $this->click("details-save");
916 //Open Live Contribution Page
917 $this->open($this->sboxPath
. "civicrm/contribute/transact?reset=1&id=" . $pageId . "&cid=" . $cid);
918 $this->waitForElementPresent("onbehalf_state_province-3");
919 $this->click('CIVICRM_QFID_amount_other_radio_4');
920 $this->type('amount_other', 60);
921 $this->click('onbehalf_contribution_campaign_id');
922 $this->select('onbehalf_contribution_campaign_id', "label={$title}");
923 $this->type("onbehalf_custom_{$fieldId}", 'Test Subject');
926 $this->select("credit_card_type", "value=Visa");
927 $this->type("credit_card_number", "4111111111111111");
928 $this->type("cvv2", "000");
929 $this->select("credit_card_exp_date[M]", "value=1");
930 $this->select("credit_card_exp_date[Y]", "value=2020");
933 $this->type("billing_street_address-5", "0121 Mount Highschool.");
934 $this->type(" billing_city-5", "Shangai");
935 $this->select("billing_country_id-5", "value=1228");
936 $this->select("billing_state_province_id-5", "value=1004");
937 $this->type("billing_postal_code-5", "94129");
939 $this->click("_qf_Main_upload-bottom");
940 $this->waitForPageToLoad($this->getTimeoutMsec());
941 $this->waitForElementPresent("_qf_Confirm_next-bottom");
942 $this->click("_qf_Confirm_next-bottom");
943 $this->waitForPageToLoad($this->getTimeoutMsec());
946 $this->open($this->sboxPath
. "civicrm/contribute/search?reset=1");
947 $this->type("sort_name", $orgName1);
948 $this->click("_qf_Search_refresh");
949 $this->waitForPageToLoad($this->getTimeoutMsec());
950 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
951 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
952 $this->waitForPageToLoad($this->getTimeoutMsec());
953 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
955 // verify contrb created
962 foreach ($expected as $value => $label) {
963 $this->verifyText("xpath=id( 'ContributionView' )/div[2]/table[1]/tbody/tr[$value]/td[2]", preg_quote($label));
967 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
968 $this->waitForPageToLoad($this->getTimeoutMsec());
969 $this->click("link=Reserved Profiles");
971 $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']");
972 $this->waitForPageToLoad($this->getTimeoutMsec());
974 $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']");
975 $this->waitForElementPresent('_qf_Field_next-bottom');
977 $this->click('_qf_Field_next-bottom');
978 $this->waitForPageToLoad($this->getTimeoutMsec());
979 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'), "Status message didn't show up after saving!");
981 $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']");
982 $this->waitForElementPresent('_qf_Field_next-bottom');
984 $this->click('_qf_Field_next-bottom');
985 $this->waitForPageToLoad($this->getTimeoutMsec());
986 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'), "Status message didn't show up after saving!");
989 function _testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle) {
990 // Logging in. Remember to wait for page to load. In most cases,
991 // you can rely on 30000 as the value that allows your test to pass, however,
992 // sometimes your test might fail because of this. In such cases, it's better to pick one element
993 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
994 // page contents loaded and you can continue your test execution.
995 $this->webtestLogin();
996 $this->waitForPageToLoad($this->getTimeoutMsec());
999 $groupName = $this->WebtestAddGroup();
1000 $this->open($this->sboxPath
. "civicrm/group?reset=1");
1001 $this->waitForElementPresent('_qf_Search_refresh');
1002 $this->click('_qf_Search_refresh');
1003 $this->waitForElementPresent("xpath=//div[@id='group']/div[3]/table/tbody//tr/td[text()='{$groupName}']/../td[2]");
1004 $groupId = $this->getText("xpath=//div[@id='group']/div[3]/table/tbody//tr/td[text()='{$groupName}']/../td[2]");
1006 $this->open($this->sboxPath
. "civicrm/contact/view?reset=1&cid={$cid}");
1007 $this->waitForPageToLoad($this->getTimeoutMsec());
1009 $this->click('link=Edit');
1010 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
1011 $this->click('addressBlock');
1012 $this->waitForElementPresent('link=Another Address');
1015 $this->select('address_1_location_type_id', 'label=Billing');
1016 $this->type('address_1_street_address', '0121 Mount Highschool.');
1017 $this->type('address_1_city', "Shangai");
1018 $this->type('address_1_postal_code', "94129");
1019 $this->select('address_1_country_id', "value=1228");
1020 $this->select('address_1_state_province_id', "value=1004");
1021 $this->click('_qf_Contact_upload_view-bottom');
1022 $this->waitForPageToLoad($this->getTimeoutMsec());
1024 // add contact to group
1026 $this->click("css=li#tab_group a");
1027 $this->waitForElementPresent("group_id");
1030 $this->select("group_id", "label=$groupName");
1031 $this->click("_qf_GroupContact_next");
1032 $this->waitForPageToLoad($this->getTimeoutMsec());
1034 $this->open($this->sboxPath
. "civicrm/admin/custom/group?action=add&reset=1");
1035 $this->waitForElementPresent("_qf_Group_next-bottom");
1037 // fill in a unique title for the c$groupIdustom group
1038 $groupTitle = "Members Custom Group" . substr(sha1(rand()), 0, 7);
1039 $this->type("title", $groupTitle);
1041 // select the group this custom data set extends
1042 $this->select("extends[0]", "value=Membership");
1043 $this->waitForElementPresent("extends[1]");
1045 // save the custom group
1046 $this->click("_qf_Group_next-bottom");
1048 $this->waitForElementPresent("_qf_Field_next_new-bottom");
1049 $this->assertTrue($this->isTextPresent("Your custom field set '$groupTitle' has been added. You can add custom fields now."));
1051 // add a custom field to the custom group
1052 $fieldTitle = "Member Custom Field " . substr(sha1(rand()), 0, 7);
1053 $this->type("label", $fieldTitle);
1055 $this->select("data_type[1]", "value=Text");
1056 $this->click('_qf_Field_next-bottom');
1058 $this->waitForPageToLoad($this->getTimeoutMsec());
1059 $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
1060 $url = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']/div[2]/table/tbody//tr/td[1]/span[text()='$fieldTitle']/../td[8]/span/a@href"));
1063 // Enable CiviCampaign module if necessary
1064 $this->enableComponents("CiviCampaign");
1066 // add the required Drupal permission
1067 $permission = array('edit-2-administer-civicampaign');
1068 $this->changePermissions($permission);
1070 // Go directly to the URL of the screen that you will be add campaign
1071 $this->open($this->sboxPath
. "civicrm/campaign/add?reset=1");
1073 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
1074 // button at the end of this page to show up, to make sure it's fully loaded.
1075 $this->waitForElementPresent("_qf_Campaign_upload-bottom");
1077 // Let's start filling the form with values.
1078 $title = 'Campaign ' . substr(sha1(rand()), 0, 7);
1079 $this->type("title", $title);
1081 // select the campaign type
1082 $this->select("campaign_type_id", "value=2");
1084 // fill in the description
1085 $this->type("description", "This is a test campaign");
1087 // include groups for the campaign
1088 $this->addSelection("includeGroups-f", "label={$groupName}");
1089 $this->click("//option[@value={$groupId}]");
1090 $this->click("add");
1092 // fill the end date for campaign
1093 $this->webtestFillDate("end_date", "+1 year");
1095 // select campaign status
1096 $this->select("status_id", "value=2");
1099 $this->click("_qf_Campaign_upload-bottom");
1100 $this->waitForPageToLoad($this->getTimeoutMsec());
1102 $this->assertTrue($this->isTextPresent("Campaign {$title} has been saved."), "Status message didn't show up after saving!");
1104 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
1105 $this->waitForPageToLoad($this->getTimeoutMsec());
1106 $this->click("link=Reserved Profiles");
1107 $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']");
1108 $this->waitForPageToLoad($this->getTimeoutMsec());
1110 $this->click("link=Add Field");
1111 $this->waitForElementPresent('_qf_Field_next-bottom');
1112 $this->select('field_name[0]', 'value=Membership');
1113 $this->select('field_name[1]', 'label=Campaign');
1114 $this->click('field_name[1]');
1115 $this->click('_qf_Field_next_new-bottom');
1116 $this->waitForPageToLoad($this->getTimeoutMsec());
1117 $this->waitForElementPresent('_qf_Field_cancel-bottom');
1119 $this->select('field_name[0]', 'value=Membership');
1120 $this->select('field_name[1]', "label=$fieldTitle :: $groupTitle");
1121 $this->click('field_name[1]');
1122 $this->click('_qf_Field_next-bottom');
1123 $this->waitForPageToLoad($this->getTimeoutMsec());
1124 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$fieldTitle}' has been saved to 'On Behalf Of Organization'."),
1125 "Status message didn't show up after saving!"
1128 // Open Page to create Organization 1
1129 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Organization");
1130 $this->waitForElementPresent("_qf_Contact_upload_view-bottom");
1131 $orgName1 = 'org1_' . substr(sha1(rand()), 0, 7);
1133 // Type Organization name
1134 $this->type("organization_name", $orgName1);
1136 // Type Organizatio email for main
1137 $this->type("email_1_email", "{$orgName1}@example.com");
1138 $this->select("email_1_location_type_id", "value=3");
1140 // type phone no for main
1141 $this->type("phone_1_phone", substr(sha1(rand()), 0, 4));
1142 $this->select("phone_1_location_type_id", "value=3");
1145 $this->click("addressBlock");
1146 $this->waitForElementPresent("address_1_street_address");
1148 //fill in address 1 for main
1149 $this->select("address_1_location_type_id", "value=3");
1150 $this->type("address_1_street_address", "{$orgName1} street address");
1151 $this->type("address_1_city", "{$orgName1} city");
1152 $this->type("address_1_postal_code", "9999999999");
1153 $this->assertTrue($this->isTextPresent("- select - United States"));
1154 $this->select("address_1_state_province_id", "value=1019");
1155 $this->type("address_1_geo_code_1", "1234");
1156 $this->type("address_1_geo_code_2", "5678");
1158 // Save the Organization
1159 $this->click("_qf_Contact_upload_view-bottom");
1160 $this->waitForPageToLoad($this->getTimeoutMsec());
1162 // create second orzanization
1163 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Organization");
1164 $this->waitForElementPresent("_qf_Contact_upload_view-bottom");
1165 $orgName2 = 'org2_' . substr(sha1(rand()), 0, 7);
1167 // Type Organization name
1168 $this->type("organization_name", $orgName2);
1170 // Type Organizatio email for main
1171 $this->type("email_1_email", "{$orgName2}@example.com");
1172 $this->select("email_1_location_type_id", "value=3");
1174 // type phone no for main
1175 $this->type("phone_1_phone", substr(sha1(rand()), 0, 4));
1176 $this->select("phone_1_location_type_id", "value=3");
1179 $this->click("addressBlock");
1180 $this->waitForElementPresent("address_1_street_address");
1182 //fill in address 1 for main
1183 $this->select("address_1_location_type_id", "value=3");
1184 $this->type("address_1_street_address", "{$orgName2} street address");
1185 $this->type("address_1_city", "{$orgName2} city");
1186 $this->type("address_1_postal_code", "7777777777");
1187 $this->assertTrue($this->isTextPresent("- select - United States"));
1188 $this->select("address_1_state_province_id", "value=1019");
1189 $this->type("address_1_geo_code_1", "1224");
1190 $this->type("address_1_geo_code_2", "5628");
1192 // Save the Organization
1193 $this->click("_qf_Contact_upload_view-bottom");
1194 $this->waitForPageToLoad($this->getTimeoutMsec());
1197 // create Membership type
1198 $title1 = "Membership Type" . substr(sha1(rand()), 0, 7);
1199 $this->open($this->sboxPath
. "civicrm/admin/member/membershipType?reset=1&action=browse");
1200 $this->waitForPageToLoad($this->getTimeoutMsec());
1202 $this->click("link=Add Membership Type");
1203 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
1205 $this->type('name', $title1);
1206 $this->type('member_org', $orgName1);
1207 $this->click('_qf_MembershipType_refresh');
1208 $this->waitForElementPresent("xpath=//div[@id='membership_type_form']/fieldset/table[2]/tbody/tr[2]/td[2]");
1210 $this->type('minimum_fee', '50');
1212 $this->select( 'financial_type_id', 'value=2' );
1214 $this->type('duration_interval', 1);
1215 $this->select('duration_unit', "label=year");
1217 $this->select('period_type', "label=fixed");
1218 $this->waitForElementPresent('fixed_period_rollover_day[d]');
1220 $this->select('fixed_period_start_day[M]', 'value=4');
1221 $this->select('fixed_period_rollover_day[M]', 'value=1');
1223 $this->select('relationship_type_id', 'value=4_b_a');
1225 $this->click('_qf_MembershipType_upload-bottom');
1226 $this->waitForElementPresent('link=Add Membership Type');
1227 $this->assertTrue($this->isTextPresent("The membership type '$title1' has been saved."));
1228 $typeUrl = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[1][text()='{$title1}']/../td[10]/span/a[3]@href"));
1229 $typeId = $typeUrl[1];
1232 $this->open($this->sboxPath
. "civicrm/contact/view/rel?cid={$cid}&action=add&reset=1");
1233 $this->waitForPageToLoad($this->getTimeoutMsec());
1235 // select relationship type
1236 $this->click("relationship_type_id");
1237 $this->select("relationship_type_id", "value=4_a_b");
1239 // search organization
1240 $this->type('contact_1', $orgName1);
1241 $this->click("contact_1");
1242 $this->waitForElementPresent("css=div.ac_results-inner li");
1243 $this->click("css=div.ac_results-inner li");
1244 $this->assertContains($orgName1, $this->getValue('contact_1'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('contact_1'));
1247 $this->click("is_permission_a_b");
1248 $this->click("is_permission_b_a");
1250 // save relationship
1251 $this->click("details-save");
1254 $this->open($this->sboxPath
. "civicrm/contact/view/rel?cid={$cid}&action=add&reset=1");
1255 $this->waitForPageToLoad($this->getTimeoutMsec());
1257 // select relationship type
1258 $this->click("relationship_type_id");
1259 $this->select("relationship_type_id", "value=4_a_b");
1261 // search organization
1262 $this->type('contact_1', $orgName2);
1263 $this->click("contact_1");
1264 $this->waitForElementPresent("css=div.ac_results-inner li");
1265 $this->click("css=div.ac_results-inner li");
1266 $this->assertContains($orgName2, $this->getValue('contact_1'), "autocomplete expected $orgName2 but didn’t find it in " . $this->getValue('contact_1'));
1269 $this->click("is_permission_a_b");
1270 $this->click("is_permission_b_a");
1272 // save relationship
1273 $this->click("details-save");
1275 // set membership type
1276 $this->open($this->sboxPath
. "civicrm/admin/contribute/membership?reset=1&action=update&id=" . $pageId);
1277 $this->waitForElementPresent("_qf_MembershipBlock_upload_done-bottom");
1278 $this->click("member_is_active");
1279 $this->click("membership_type[{$typeId}]");
1280 $this->click("xpath=//div[@id='memberFields']//table[@class='report']/tbody//tr/td[1]/label[text()='{$title1}']/../../td[2]/input");
1281 $this->click('_qf_MembershipBlock_upload_done-bottom');
1282 $this->waitForPageToLoad($this->getTimeoutMsec());
1284 //Open Live Membership Page
1285 $this->open($this->sboxPath
. "civicrm/contribute/transact?reset=1&id=" . $pageId . "&cid=" . $cid);
1286 $this->waitForElementPresent("_qf_Main_upload-bottom");
1287 $this->click('CIVICRM_QFID_amount_other_radio_4');
1288 $this->type('amount_other', 60);
1289 $this->click('onbehalf_organization_name');
1290 $this->type('onbehalf_organization_name', $orgName1);
1291 $this->typeKeys('onbehalf_organization_name', $orgName1);
1292 $this->click("onbehalf_organization_name");
1293 $this->waitForElementPresent("css=div.ac_results-inner li");
1294 $this->click("css=div.ac_results-inner li");
1296 $this->click('onbehalf_member_campaign_id');
1297 $this->select('onbehalf_member_campaign_id', "label={$title}");
1298 $this->type("onbehalf_custom_{$fieldId}", 'Test Subject');
1300 $this->assertContains($orgName1, $this->getValue('onbehalf_organization_name'), "autocomplete expected $orgName1 but didn’t find it in " . $this->getValue('onbehalf_organization_name'));
1303 $this->select("credit_card_type", "value=Visa");
1304 $this->type("credit_card_number", "4111111111111111");
1305 $this->type("cvv2", "000");
1306 $this->select("credit_card_exp_date[M]", "value=1");
1307 $this->select("credit_card_exp_date[Y]", "value=2020");
1309 $this->click("_qf_Main_upload-bottom");
1310 $this->waitForPageToLoad($this->getTimeoutMsec());
1311 $this->waitForElementPresent("_qf_Confirm_next-bottom");
1312 $this->click("_qf_Confirm_next-bottom");
1313 $this->waitForPageToLoad($this->getTimeoutMsec());
1315 //Find Membership for organization
1316 $this->open($this->sboxPath
. "civicrm/member/search?reset=1");
1317 $this->type("sort_name", $orgName1);
1318 $this->click("_qf_Search_refresh");
1319 $this->waitForPageToLoad($this->getTimeoutMsec());
1320 $this->waitForElementPresent("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
1321 $this->click("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
1322 $this->waitForPageToLoad($this->getTimeoutMsec());
1323 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
1325 //verify contrb created
1331 foreach ($expected as $value => $label) {
1332 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1335 // find membership for contact in relationship
1336 $this->open($this->sboxPath
. "civicrm/contact/view?reset=1&force=1&cid={$cid}");
1337 $this->waitForPageToLoad($this->getTimeoutMsec());
1338 $this->click("css=li#tab_member a");
1339 $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']");
1340 $this->click("xpath=//div[@id='memberships']/div/table//tbody//tr/td[1][text()='{$title1}']/../td[7]/span/a[text()='View']");
1341 $this->waitForPageToLoad($this->getTimeoutMsec());
1343 //verify contrb created
1348 foreach ($expected as $value => $label) {
1349 $this->verifyText("xpath=//form[@id='MembershipView']/div[2]/div/table/tbody/tr[$value]/td[2]", preg_quote($label));
1352 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
1353 $this->waitForPageToLoad($this->getTimeoutMsec());
1354 $this->click("link=Reserved Profiles");
1355 $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']");
1356 $this->waitForPageToLoad($this->getTimeoutMsec());
1358 $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']");
1359 $this->waitForElementPresent('_qf_Field_next-bottom');
1361 $this->click('_qf_Field_next-bottom');
1362 $this->waitForPageToLoad($this->getTimeoutMsec());
1363 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1364 "Status message didn't show up after saving!"
1367 $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']");
1368 $this->waitForElementPresent('_qf_Field_next-bottom');
1370 $this->click('_qf_Field_next-bottom');
1371 $this->waitForPageToLoad($this->getTimeoutMsec());
1372 $this->assertTrue($this->isTextPresent('Selected Profile Field has been deleted.'),
1373 "Status message didn't show up after saving!"
1376 $this->open($this->sboxPath
. "civicrm/contact/view?reset=1&cid={$cid}");
1377 $this->waitForPageToLoad($this->getTimeoutMsec());
1378 $this->click("css=li#tab_rel a");
1380 $this->waitForElementPresent("xpath=//div[@id='current-relationships']/div/table/tbody//tr/td[2]/a[text()='{$orgName1}']");
1381 $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']");
1383 // Check confirmation alert.
1384 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this relationship?/",
1385 $this->getConfirmation()
1387 $this->chooseOkOnNextConfirmation();
1388 $this->waitForPageToLoad($this->getTimeoutMsec());
1389 $this->assertTrue($this->isTextPresent('Selected relationship has been deleted successfully.'),
1390 "Status message didn't show up after saving!"
1395 function testOnBehalfOfOrganizationWithImage() {
1396 // This is the path where our testing install resides.
1397 // The rest of URL is defined in CiviSeleniumTestCase base class, in
1398 // class attributes.
1399 $this->open($this->sboxPath
);
1401 // Logging in. Remember to wait for page to load. In most cases,
1402 // you can rely on 30000 as the value that allows your test to pass, however,
1403 // sometimes your test might fail because of this. In such cases, it's better to pick one element
1404 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
1405 // page contents loaded and you can continue your test execution.
1406 $this->webtestLogin();
1408 $this->open($this->sboxPath
. "civicrm/profile/edit?reset=1&gid=4");
1409 $firstName = 'John_x_' . substr(sha1(rand()), 0, 7);
1410 $lastName = 'Anderson_c_' . substr(sha1(rand()), 0, 7);
1412 $this->waitForPageToLoad($this->getTimeoutMsec());
1413 $this->waitForElementPresent("_qf_Edit_next");
1414 $this->type("first_name", $firstName);
1415 $this->type("last_name", $lastName);
1416 $this->click("_qf_Edit_next");
1417 $this->waitForPageToLoad($this->getTimeoutMsec());
1418 $this->waitForElementPresent("profilewrap4");
1420 $urlElements = $this->parseURL();
1421 $cid = $urlElements['queryString']['id'];
1422 $this->assertType('numeric', $cid);
1423 // Is status message correct?
1424 $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
1426 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
1427 $this->waitForPageToLoad($this->getTimeoutMsec());
1428 $this->click("link=Reserved Profiles");
1430 $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']");
1431 $this->waitForPageToLoad($this->getTimeoutMsec());
1433 $this->click("link=Add Field");
1434 $this->waitForElementPresent('_qf_Field_next-bottom');
1436 $this->select('field_name[0]', 'value=Contact');
1437 $this->select('field_name[1]', 'label=Image Url');
1438 $this->click('field_name[1]');
1439 $this->click('_qf_Field_next-bottom');
1440 $this->waitForPageToLoad($this->getTimeoutMsec());
1442 // We need a payment processor
1443 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
1444 $processorType = 'Dummy';
1445 $pageTitle = substr(sha1(rand()), 0, 7);
1447 $hash = substr(sha1(rand()), 0, 7);
1448 $amountSection = TRUE;
1453 $memberships = FALSE;
1454 $memPriceSetId = NULL;
1456 $profilePreId = NULL;
1457 $profilePostId = NULL;
1461 $honoreeSection = FALSE;
1462 $isAddPaymentProcessor = TRUE;
1463 $isPcpApprovalNeeded = FALSE;
1464 $isSeparatePayment = FALSE;
1466 // create a new online contribution page
1467 // create contribution page with randomized title and default params
1468 $pageId = $this->webtestAddContributionPage($hash,
1471 array($processorName => $processorType),
1485 $isAddPaymentProcessor,
1486 $isPcpApprovalNeeded,
1491 $this->_testOrganizationWithImageUpload($pageId, $cid, $pageTitle);
1493 $this->open($this->sboxPath
. "civicrm/admin/uf/group?reset=1");
1494 $this->waitForPageToLoad($this->getTimeoutMsec());
1495 $this->click("link=Reserved Profiles");
1497 $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']");
1498 $this->waitForPageToLoad($this->getTimeoutMsec());
1499 $this->click("xpath=//table[@id='option11']/tbody//tr/td/span[text()='Image Url']/../following-sibling::td[8]/span[2]/ul/li[2]/a");
1500 $this->waitForPageToLoad($this->getTimeoutMsec());
1501 $this->click('_qf_Field_next-bottom');
1502 $this->waitForPageToLoad($this->getTimeoutMsec());
1503 $this->assertElementContainsText('crm-notification-container', "Selected Profile Field has been deleted.");
1506 function _testOrganizationWithImageUpload($pageId, $cid, $pageTitle) {
1507 //Open Live Contribution Page
1508 $this->open($this->sboxPath
. "civicrm/contribute/transact?reset=1&id=" . $pageId);
1510 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
1511 $lastName = 'An' . substr(sha1(rand()), 0, 7);
1512 $orgName = 'org_11_' . substr(sha1(rand()), 0, 7);
1513 $this->type("email-5", $firstName . "@example.com");
1515 // onbehalforganization info
1516 $this->type("onbehalf_organization_name", $orgName);
1517 $this->type("onbehalf_phone-3-1", 9999999999);
1518 $this->type("onbehalf_email-3", "{$orgName}@example.com");
1519 $this->type("onbehalf_street_address-3", "Test Street Address");
1520 $this->type("onbehalf_city-3", "Test City");
1521 $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
1522 $this->click("onbehalf_country-3");
1523 $this->select("onbehalf_country-3", "label=United States");
1524 $this->click("onbehalf_state_province-3");
1525 $this->select("onbehalf_state_province-3", "label=Alabama");
1527 // check for upload field.
1528 $this->waitForElementPresent("onbehalf_image_URL");
1530 //header("Content-Type: image/png");
1531 $im = imagecreate(110, 20)
1532 or die("Cannot Initialize new GD image stream");
1533 $background_color = imagecolorallocate($im, 0, 0, 0);
1534 $text_color = imagecolorallocate($im, 233, 14, 91);
1535 imagestring($im, 1, 5, 5, "On Behalf-Org Logo", $text_color);
1536 imagepng($im,"/tmp/file.png");
1538 $imagePath = "/tmp/file.png";
1539 $this->webtestAttachFile('onbehalf_image_URL', $imagePath);
1543 $this->select("credit_card_type", "value=Visa");
1544 $this->type("credit_card_number", "4111111111111111");
1545 $this->type("cvv2", "000");
1546 $this->select("credit_card_exp_date[M]", "value=1");
1547 $this->select("credit_card_exp_date[Y]", "value=2020");
1550 $this->type("billing_first_name", $firstName . 'billing');
1551 $this->type("billing_last_name", $lastName . 'billing');
1552 $this->type("billing_street_address-5", "0121 Mount Highschool.");
1553 $this->type(" billing_city-5", "Shangai");
1554 $this->select("billing_country_id-5", "value=1228");
1555 $this->select("billing_state_province_id-5", "value=1004");
1556 $this->type("billing_postal_code-5", "94129");
1557 $this->click("_qf_Main_upload-bottom");
1559 $this->waitForPageToLoad($this->getTimeoutMsec());
1560 $this->waitForElementPresent("_qf_Confirm_next-bottom");
1562 $this->click("_qf_Confirm_next-bottom");
1563 $this->waitForPageToLoad($this->getTimeoutMsec());
1565 // Type search name in autocomplete.
1566 $this->click('sort_name_navigation');
1567 $this->type('css=input#sort_name_navigation', $orgName);
1568 $this->typeKeys('css=input#sort_name_navigation', $orgName);
1570 // Wait for result list.
1571 $this->waitForElementPresent("css=div.ac_results-inner li");
1573 // Visit organization page.
1574 $this->click("css=div.ac_results-inner li");
1575 $this->waitForPageToLoad($this->getTimeoutMsec());
1577 //check whether the image is present
1578 $this->assertTrue($this->isElementPresent("xpath=//div[@id='crm-contact-thumbnail']/div/a/img"));