*/
public function buildQuickForm() {
$attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Premium');
- $this->addElement('checkbox', 'premiums_active', ts('Premiums Section Enabled?'), NULL, array('onclick' => "premiumBlock(this);"));
+ $this->addElement('checkbox', 'premiums_active', ts('Premiums Section Enabled?'), NULL);
$this->addElement('text', 'premiums_intro_title', ts('Title'), $attributes['premiums_intro_title']);
$this->addElement('checkbox', 'premiums_display_min_contribution', ts('Display Minimum Contribution Amount?'));
// CRM-10999 Control label and position for No Thank-you radio button
- $this->add('text', 'premiums_nothankyou_label', ts('No Thank-you Label'), $attributes['premiums_nothankyou_label'], TRUE);
+ $this->add('text', 'premiums_nothankyou_label', ts('No Thank-you Label'), $attributes['premiums_nothankyou_label']);
$positions = array(1 => ts('Before Premiums'), 2 => ts('After Premiums'));
$this->add('select','premiums_nothankyou_position', ts('No Thank-you Option'), $positions);
$showForm = TRUE;
$this->assign('showForm', $showForm);
parent::buildQuickForm();
+ $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Premium', 'formRule'), $this);
$premiumPage = new CRM_Contribute_Page_Premium();
$premiumPage->browse();
}
+ /**
+ * Function for validation
+ *
+ * @param array $params (ref.) an assoc array of name/value pairs
+ *
+ * @return mixed true or array of errors
+ * @access public
+ * @static
+ */
+ public static function formRule($params) {
+ $errors = array();
+ if (CRM_Utils_Array::value('premiums_active', $params)) {
+ if (!CRM_Utils_Array::value('premiums_nothankyou_label', $params)) {
+ $errors['premiums_nothankyou_label'] = ts('No Thank-you Label is a required field.');
+ }
+ }
+ return empty($errors) ? TRUE : $errors;
+ }
+
/**
* Process the form
*
</tr>
</table>
- <div class="crm-accordion-wrapper crm-plain_text_email-accordion collapsed">
+ <div id="premiumSettings" class="crm-accordion-wrapper crm-plain_text_email-accordion collapsed">
<div class="crm-accordion-header">
{ts}Premiums Settings{/ts}
</div>
</td>
</tr>
<tr class="crm-contribution-contributionpage-premium-form-block-premiums_nothankyou_label">
- <td class="label">{$form.premiums_nothankyou_label.label}
+ <td class="label">{$form.premiums_nothankyou_label.label}<span class="marker"> *</span>
</td>
<td class="html-adjust">{$form.premiums_nothankyou_label.html}<br />
<span class="description">{ts}You can change the text for the 'No thank-you' radio button.{/ts}</span>
</tr>
</table>
</div><!-- /.crm-accordion-body -->
+ {* Call Premiums tpl inside premiumSettings div to hide it on unchecking premiums_active checkbox*}
+ {include file="CRM/Contribute/Page/Premium.tpl"}
</div><!-- /.crm-accordion-wrapper -->
- {include file="CRM/Contribute/Page/Premium.tpl"}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
{literal}
cj(function() {
cj().crmAccordions();
+
+ // bind click event to premiums_active checkbox
+ cj('#premiums_active').click(function() {
+ // call function to show/hide Premium Settings div
+ premiumBlock(cj(this).prop('checked'));
+ });
+
+ // show/hide Premium Settings div on page load
+ // depending on "Premiums Section Enabled?" checkbox's value
+ if (!cj('#premiums_active').is(':checked')) {
+ cj("#premiumSettings:not(.collapsed)").crmAccordionToggle();
+ cj('#premiumSettings').hide();
+ }
+ else {
+ cj("#premiumSettings").crmAccordionToggle();
+ cj('#premiumSettings').show();
+ }
+
+ // function to show/hide Premium Settings
+ function premiumBlock(checked) {
+ if (checked) {
+ cj("#premiumSettings").crmAccordionToggle();
+ cj('#premiumSettings').show();
+ return;
+ }
+ else {
+ cj("#premiumSettings:not(.collapsed)").crmAccordionToggle();
+ cj('#premiumSettings').hide();
+ return;
+ }
+ }
});
{/literal}
</script>
$this->webtestVerifyTabularData($expected);
$this->click('_qf_MembershipView_cancel-bottom');
}
+
+ /**
+ * CRM-12994
+ */
+ function testContributionPageAddPremiumRequiredField() {
+ // open browser, login
+ $this->webtestLogin();
+
+ // a random 7-char string and an even number to make this pass unique
+ $hash = substr(sha1(rand()), 0, 7);
+ $rand = 2 * rand(2, 50);
+ $pageTitle = 'Donate Online ' . $hash;
+ $processor = array("Webtest Dummy" . substr(sha1(rand()), 0, 7) => 'Dummy');
+
+ // Create a new payment processor
+ while (list($processorName, $processorType) = each($processor)) {
+ $this->webtestAddPaymentProcessor($processorName, $processorType);
+ }
+
+ // go to the New Contribution Page page
+ $this->openCiviPage('admin/contribute', 'action=add&reset=1');
+
+ // fill in Title and Settings
+ $this->type('title', $pageTitle);
+
+ // to select financial type
+ $this->select('financial_type_id', "label=Donation");
+
+ $this->click('is_organization');
+ $this->select('onbehalf_profile_id', 'label=On Behalf Of Organization');
+ $this->type('for_organization', "On behalf $hash");
+ // make onBehalf optional
+ $this->click('CIVICRM_QFID_1_2');
+
+ $this->fillRichTextField('intro_text', 'This is introductory message for ' . $pageTitle, 'CKEditor');
+ $this->fillRichTextField('footer_text', 'This is footer message for ' . $pageTitle, 'CKEditor');
+
+ $this->type('goal_amount', 10 * $rand);
+
+ // Submit form
+ $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
+
+ // Get contribution page id
+ $pageId = $this->urlArg('id');
+
+ // fill in Processor, Amounts
+ if (!empty($processor)) {
+ reset($processor);
+ while (list($processorName) = each($processor)) {
+ // select newly created processor
+ $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
+ $this->assertTrue($this->isTextPresent($processorName));
+ $this->check($xpath);
+ }
+ }
+
+ // fill in labels & values in Fixed Contribution Options
+ $this->type('label_1', 'Fixed Amount 1');
+ $this->type('value_1', 1);
+ $this->type('label_2', 'Fixed Amount 2');
+ $this->type('value_2', 2);
+ $this->type('label_3', 'Fixed Amount 3');
+ $this->type('value_3', 3);
+ $this->click('CIVICRM_QFID_1_2');
+ $this->click('_qf_Amount_submit_savenext-bottom');
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+
+ // click through to the membership view screen
+ $this->click("css=li#tab_thankyou a");
+ $this->waitForElementPresent('_qf_ThankYou_next-bottom');
+
+ // fill in Receipt details
+ $this->type('thankyou_title', "Thank-you Page Title $hash");
+ $this->fillRichTextField('thankyou_text', 'This is thankyou message for ' . $pageTitle, 'CKEditor');
+ $this->fillRichTextField('thankyou_footer', 'This is thankyou footer message for ' . $pageTitle, 'CKEditor');
+ $this->click('is_email_receipt');
+ $this->waitForElementPresent('bcc_receipt');
+ $this->type('receipt_from_name', "Receipt From Name $hash");
+ $this->type('receipt_from_email', "$hash@example.org");
+ $this->type('receipt_text', "Receipt Message $hash");
+ $this->type('cc_receipt', "$hash@example.net");
+ $this->type('bcc_receipt', "$hash@example.com");
+
+ $this->click('_qf_ThankYou_next');
+ $this->waitForElementPresent('_qf_ThankYou_next-bottom');
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+ $receiptText = "'ThankYou' information has been saved.";
+ $this->assertTrue($this->isTextPresent($receiptText), 'Missing text: ' . $receiptText);
+
+ $this->click('link=Premiums');
+ $this->waitForElementPresent('_qf_Premium_submit_savenext-bottom');
+ $assertPremiumsCheck = FALSE;
+ if (!$this->isChecked('premiums_active')) {
+ $assertPremiumsCheck = TRUE;
+ }
+ $this->assertTrue($assertPremiumsCheck, 'Premiums Section is not unchecked by default.');
+ $this->click('_qf_Premium_submit_savenext-bottom');
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+ $premiumText = "'Premium' information has been saved.";
+ // check if clicking Save & Next button
+ // Premium is saved rather than required validation error
+ // for No Thank-you Label textfield
+ $this->assertTrue($this->isTextPresent($premiumText));
+
+ $this->openCiviPage("admin/contribute", "reset=1");
+
+ // search for the new contrib page and go to its test version
+ $this->type('title', $pageTitle);
+ $this->click('_qf_SearchContribution_refresh');
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+ $this->isElementPresent("xpath=//table[@id='option11_wrapper']/tbody/tr/td/strong[text()='$pageTitle']");
+ $this->waitForElementPresent("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
+ $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
+ $this->waitForElementPresent("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']/ul[@class='panel']/li[8]/a[@title='Premiums']");
+ $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']/ul[@class='panel']/li[8]/a[@title='Premiums']");
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+ $this->waitForElementPresent('premiums_active');
+ $this->waitForElementPresent('_qf_Premium_cancel-bottom');
+
+ // click on Premiums Section Enabled? checkbox
+ $this->click('premiums_active');
+ $this->waitForElementPresent("xpath=//div[@id='premiumSettings']");
+ $this->waitForElementPresent('premiums_nothankyou_position');
+ $this->type('premiums_intro_title', 'Premiums Intro Title');
+ $this->type('premiums_intro_text', 'Premiums Into Text');
+ $this->type('premiums_contact_email', "$hash@example.net");
+
+ // let No Thank-you Label text be blank
+ // so that validation error appears
+ // $this->type('premiums_nothankyou_label', );
+ $this->select('premiums_nothankyou_position', 'value=2');
+
+ // click on save & next button
+ $this->click('_qf_Premium_submit_savenext-bottom');
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+ $premiumRequiredText = "No Thank-you Label is a required field.";
+ // check if clicking Save & Next button
+ // required validation error appears
+ // for No Thank-you Label textfield
+ $this->waitForElementPresent("xpath=//ul[@id='errorList']");
+ $this->assertTrue($this->isTextPresent($premiumRequiredText));
+
+ // fill in value for Premiums No Thank-you Label textfield
+ $this->type('premiums_nothankyou_label', 'Premiums No Thank-you Label');
+ $this->waitForElementPresent('_qf_Premium_upload_done-bottom');
+
+ // click save & done button
+ $this->click('_qf_Premium_upload_done-bottom');
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+ $premiumSavedText = "'Premium' information has been saved.";
+ // check if clicking Save & Done button
+ // contribution page is saved.
+ $this->assertTrue($this->isTextPresent($premiumSavedText));
+ }
}