Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21436: Fix exception on pay later contribution page. #11317

Merged

Conversation

jitendrapurohit
Copy link
Contributor

@jitendrapurohit jitendrapurohit commented Nov 24, 2017

Overview

This is an extension of #11286 and fixes exception on a pay later contribution page.

Before

If no payment processor is selected, contribution page displays the following exception.

A payment processor configured for this page might be disabled (contact the site administrator for assistance).

After

Contribution page loads fine with pay later processor.

Technical Details

Assignment of pay_later was done after checking if there are any processors enabled on the contribution page. This PR assigns paylater processor just before the check so that it gets assigned correctly even if none of the payment processor is configured.

Comments

Added unit test.


@eileenmcnaughton
Copy link
Contributor

this looks good to me - code makes sense

@seamuslee001
Copy link
Contributor

Jenkins re test this please

try {
$form->preProcess();
}
catch (CRM_Core_Exception $e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the expectation is that an extension is thrown here, this will still pass if one is not. You can add a return in the catch box & a $this->markFail('exception was expected'); to deal with that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Thanks, seems I was extra optimistic here ;-)

@eileenmcnaughton
Copy link
Contributor

@jitendrapurohit the failing test is related

@eileenmcnaughton
Copy link
Contributor

(it might be a thing where the test works in isolation but in the test suite perhaps some data from another test interferes)

@jitendrapurohit
Copy link
Contributor Author

Not sure whats wrong, the test passes on my local individually and also if I run the whole file. Jenkin seems to be failing because the contribution page which is in process is disabled. But is_active param on my test should make sure that it is active.

Only thing I can see is that the contribution_page table might be having some extra rows in it. I've added this table in the teardown() function. Any more pointers?

@seamuslee001
Copy link
Contributor

@jitendrapurohit i have been doing some looking into this on the jenkins test box

So what I have found is that when you run ./tools/scripts/phpunit 'CRM_AllTests' which is essentially what Jenkins does, the test fails because even though $page1['id'] outputs correct id (in this case 1 as shown below) $this->_id in the contribution base is going to 4 and therefor nothing from the contribution_page table gets loaded and therefor no values are loaded and you get the exception, I replicated this on my local as well

Installing core113171_knvo7 database
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.

.............................................................   61 / 1759 (  3%)
.............................................................  122 / 1759 (  6%)
.............................................................  183 / 1759 ( 10%)
.............................................................  244 / 1759 ( 13%)
.............................................................  305 / 1759 ( 17%)
.............................................................  366 / 1759 ( 20%)
..............EArray
(
    [is_error] => 0
    [undefined_fields] => Array
        (
            [0] => is_active
            [1] => title
            [2] => financial_type_id
            [3] => currency
            [4] => goal_amount
            [5] => is_pay_later
            [6] => is_monetary
            [7] => is_email_receipt
            [8] => receipt_from_email
            [9] => receipt_from_name
        )

    [version] => 3
    [count] => 1
    [id] => 1
    [values] => Array
        (
            [1] => Array
                (
                    [id] => 1
                    [title] => Test Contribution Page
                    [intro_text] =>
                    [financial_type_id] => 1
                    [payment_processor] =>
                    [is_credit_card_only] =>
                    [is_monetary] => 1
                    [is_recur] =>
                    [is_confirm_enabled] =>
                    [recur_frequency_unit] =>
                    [is_recur_interval] =>
                    [is_recur_installments] =>
                    [adjust_recur_start_date] =>
                    [is_pay_later] => 1
                    [pay_later_text] =>
                    [pay_later_receipt] =>
                    [is_partial_payment] =>
                    [initial_amount_label] =>
                    [initial_amount_help_text] =>
                    [min_initial_amount] =>
                    [is_allow_other_amount] =>
                    [default_amount_id] =>
                    [min_amount] =>
                    [max_amount] =>
                    [goal_amount] => 100
                    [thankyou_title] =>
                    [thankyou_text] =>
                    [thankyou_footer] =>
                    [is_email_receipt] => 1
                    [receipt_from_name] => Ego Freud
                    [receipt_from_email] => yourconscience@donate.com
                    [cc_receipt] =>
                    [bcc_receipt] =>
                    [receipt_text] =>
                    [is_active] => 1
                    [footer_text] =>
                    [amount_block_is_active] =>
                    [start_date] =>
                    [end_date] =>
                    [created_id] =>
                    [created_date] =>
                    [currency] => NZD
                    [campaign_id] =>
                    [is_share] =>
                    [is_billing_required] =>
                )

        )

)
14Array
(
    [custom_post_id] =>
    [custom_pre_id] =>
)
..```


//Execute CRM_Contribute_Form_ContributionBase preProcess
//and check the assignment of payment processors
$form = new CRM_Contribute_Form_ContributionBase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would help to load the form 'Main' rather than it's parent? There is a helper 'getForm' which might set things that matter

@mlutfy
Copy link
Member

mlutfy commented Nov 27, 2017

I deployed the patch to our production testers, and so far so good.

@eileenmcnaughton
Copy link
Contributor

@jitendrapurohit if you are still struggling with the test after looking again today let's split this into 2 prs - a fix that I will merge against the rc and the unit test against master. We are getting tight on the rc timeframe now & I agree this is an essential patch to be in there. (not that I don't want the test finished - just creating an option if you think it might take longer than we really want this to be pending merging)

@@ -129,7 +129,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
*
* @var int
*/
protected $_is_pay_later_enabled;
protected $isPayLaterEnabled;
Copy link
Member

@mlutfy mlutfy Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that this variable is not used in this class. Is it used anywhere else? i.e. any risk of breaking something else?

Also I notice that most protected variables start with _, but there are exceptions. Are there coding guidelines on this?

(this is mostly out of curiosity, I would not block merging)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to move any changes that are more clean up to a pr against master

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ie. this one could be used by any class that inherits from CRM_Core_Form so it might be better on master - the one below is fine as is as it is easy by reading it to feel confident about renaming that var

@jitendrapurohit
Copy link
Contributor Author

Thanks @seamuslee001 that is much helpful, and I'm still thinking why teardown() function wasn't able to handle that. Anyway, I've separated the unit test as mentioned by @eileenmcnaughton and have submitted it against master #11334. I can take a look later this week, as now we've steps for replicating it on my local :-).

Will also consider @mlutfy comment about the variable on the master PR.

@eileenmcnaughton
Copy link
Contributor

@jitendra - if you want to pull out that very first change (the one to the name of the form property) I'll give this merge-on-pass & we can look at that line on master

@jitendrapurohit
Copy link
Contributor Author

I thought I included that in my previous commit - done now.

@eileenmcnaughton eileenmcnaughton merged commit 682c12c into civicrm:4.7.28-rc Nov 28, 2017
@jitendrapurohit jitendrapurohit deleted the CRM-21436-minor-fix branch November 28, 2017 03:06
@eileenmcnaughton
Copy link
Contributor

I just merged it - we've seen the test results enough times to know it's only the new test failing. Will up-merge to master now. Thanks @jitendrapurohit - I think this & the one you did earlier are solid fixes that improve the robustness & logic of the code

@eileenmcnaughton eileenmcnaughton mentioned this pull request Nov 28, 2017
sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
* CRM-21436: Fix exception on pay later contribution page.

* minor fix

* move test against master

* variable fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants