Commit e1b78a19 authored by colemanw's avatar colemanw

Merge pull request #7959 from JMAConsulting/CRM-18163

CRM-18163 Unsupervised Organization Rule for On Behalf Of Contributions
parents e70cec10 7028a38f
......@@ -223,9 +223,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
}
// if onbehalf-of-organization
if (!empty($this->_values['onbehalf_profile_id']) && !empty($this->_params['onbehalf']['organization_name'])) {
// CRM-15182
$this->_params['organization_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_params['onbehalf']['organization_name'], 'id', 'display_name');
$this->_params['organization_id'] = CRM_Utils_Array::value('onbehalfof_id', $this->_params);
$this->_params['organization_name'] = $this->_params['onbehalf']['organization_name'];
$addressBlocks = array(
'street_address',
......
......@@ -1223,7 +1223,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
if ($memPriceSetId || (($membershipTypes === TRUE) || (is_array($membershipTypes) && !empty($membershipTypes)))) {
// go to step 3 (memberships)
$this->click('link=Memberships');
$this->waitForElementPresent('_qf_MembershipBlock_next-bottom');
$this->waitForElementPresent('_qf_MembershipBlock_submit_savenext');
// fill in step 3 (Memberships)
$this->click('member_is_active');
......
......@@ -199,7 +199,7 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
* @param bool $amountSection
* @param bool $freeMembership
*/
public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE, $freeMembership = FALSE) {
public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE, $freeMembership = FALSE, $onBehalf = FALSE, $onBehalfParams = array()) {
//Open Live Contribution Page
$this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
// Select membership type 1
......@@ -207,10 +207,8 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
if ($memTypeId != 'No thank you') {
$this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//div/span/label/span[1][contains(text(),'$memTypeId')]");
}
else {
$this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
}
if (!$otherAmount && $amountSection) {
$this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
......@@ -225,6 +223,19 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
$this->waitForAjaxContent();
$this->click("xpath=//label[text()='Pay later label {$hash}']");
}
if ($onBehalf && $onBehalfParams) {
if ($onBehalfParams['mode'] == 'optional') {
$this->click("is_for_organization");
}
$this->type("onbehalf[organization_name]", $onBehalfParams['org_name']);
$this->type("onbehalf[phone-3-1]", $onBehalfParams['org_phone']);
$this->type("onbehalf[email-3]", $onBehalfParams['org_email']);
$this->type("onbehalf[street_address-3]", "100 Main Street");
$this->type("onbehalf[city-3]", "San Francisco");
$this->type("onbehalf[postal_code-3]", $onBehalfParams['org_postal_code']);
$this->select("onbehalf[country-3]", "value=1228");
$this->select("onbehalf[state_province-3]", "value=1001");
}
$this->type("email-5", $firstName . "@example.com");
$this->waitForElementPresent("first_name");
$this->type("first_name", $firstName);
......@@ -382,10 +393,11 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
$hash = substr(sha1(rand()), 0, 7);
$rand = 2 * rand(2, 50);
$amountSection = $payLater = $allowOtherAmount = $onBehalf = $pledges = $recurring = FALSE;
$amountSection = $payLater = $allowOtherAmount = $pledges = $recurring = FALSE;
$premiums = $widget = $pcp = $isSeparatePayment = $membershipsRequired = $fixedAmount = $friend = FALSE;
$memberships = TRUE;
$memPriceSetId = NULL;
$onBehalf = TRUE;
$profilePreId = 1;
$profilePostId = NULL;
$contributionTitle = "Title $hash";
......@@ -512,4 +524,106 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
}
}
/**
* CRM-18163 - To check whether multiple organizations with same name
* are created based on dedupe rule other than org name.
*/
public function testOnlineMembershipCreateOnBehalfWithOrgDedupe() {
// Add unsupervised dedupe rule.
$this->webtestLogin();
$this->openCiviPage("contact/deduperules", "reset=1");
$this->waitForElementPresent("xpath=//div[@id='option13_wrapper']/table/tbody/tr[2]/td[3]/span/a[2][text()='Edit Rule']");
$this->click("xpath=//div[@id='option13_wrapper']/table/tbody/tr[2]/td[3]/span/a[2][text()='Edit Rule']");
$this->waitForElementPresent('_qf_DedupeRules_next');
$this->type('title', "Postal Code unsupervised dedupe rule");
$this->click('CIVICRM_QFID_Unsupervised_used');
$this->select('where_0', "Organization Name");
$this->type('weight_0', 10);
$this->select('where_1', "Postal Code");
$this->type('length_1', 3);
$this->type('weight_1', 10);
$this->type('threshold', 20);
$this->click('_qf_DedupeRules_next');
$this->webtestLogout();
//login with admin credentials & make sure we do have required permissions.
$permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
$this->changePermissions($permissions);
$hash = substr(sha1(rand()), 0, 7);
$rand = 2 * rand(2, 50);
$amountSection = $payLater = $allowOtherAmount = $pledges = $recurring = $membershipsRequired = FALSE;
$premiums = $widget = $pcp = $isSeparatePayment = $fixedAmount = $friend = FALSE;
$memberships = FALSE;
$memPriceSetId = NULL;
$profilePreId = 1;
$profilePostId = NULL;
$onBehalf = 'optional';
$contributionTitle = "Title $hash";
$pageId = $this->webtestAddContributionPage(
$hash,
$rand,
$contributionTitle,
NULL,
$amountSection,
$payLater,
$onBehalf,
$pledges,
$recurring,
$memberships,
$memPriceSetId,
$friend,
$profilePreId,
$profilePostId,
$premiums,
$widget,
$pcp,
FALSE,
FALSE,
$isSeparatePayment,
FALSE,
$allowOtherAmount,
TRUE,
'Member Dues',
$fixedAmount,
$membershipsRequired
);
$memTypeParams = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 0);
$memTypeTitle = $memTypeParams['membership_type'];
$memTypeId = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle}']/../../td[12]/span/a[3]@href"));
$memTypeId = $memTypeId[1];
$this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_submit_savenext');
$this->click('member_is_active');
$this->waitForElementPresent('displayFee');
$this->type('new_title', "Title - New Membership $hash");
$this->type('renewal_title', "Title - Renewals $hash");
$this->click("membership_type_$memTypeId");
$this->clickLink('_qf_MembershipBlock_submit_savenext');
$firstName = 'Ma' . substr(sha1(rand()), 0, 4);
$lastName = 'An' . substr(sha1(rand()), 0, 7);
$onBehalfParams = array(
'org_name' => 'Test Org Dedupe', // Same Org Name.
'org_phone' => '123-456-789',
'org_email' => 'testorgdedupe@test.com', // Same Email address.
'org_postal_code' => 'ABC 123',
'mode' => 'optional',
);
$this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE, TRUE, $onBehalfParams);
$onBehalfParams['org_postal_code'] = 'XYZ 123';
$this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE, TRUE, $onBehalfParams);
$this->webtestLogin();
$this->openCiviPage("contact/search", "reset=1");
$this->waitForElementPresent("_qf_Basic_refresh");
$this->type('sort_name', $onBehalfParams['org_email']);
$this->click("_qf_Basic_refresh");
$this->waitForElementPresent("xpath=//div[@class='crm-search-results']");
$this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[2]/td[2]/label[1]", "All 2 records");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment