Add general testing for payment module.

  • Paying during checkout
  • Validating payment information
  • Check if payment transaction is created
  • Adding payments through admin
  • Create a new payment method with some rule condition

Also we need to check if it's feasible to test offsite payment processing. This would require writing a small payment module that sets 'offsite' to TRUE in hook_commerce_payment_method_info() and also add a page for faking an offsite payment processing.

CommentFileSizeAuthor
#10 1069896.patch7.97 KBrecidive

Comments

recidive’s picture

Status: Active » Needs review

I added tests for paying during checkout, validating payment information, and adding payments through admin UI.

https://github.com/recidive/drupalcommerce/tree/1069896

I'm moving to needs review, but actually it can be improved to testing adding new payment method and offsite payments.

recidive’s picture

I added tests for payment method rules.

Can we commit those tests and work on offsite payment tests in another issue?

rszrama’s picture

Status: Needs review » Fixed

Sounds like a plan. In fact, you can spawn two child issues. One for adding and testing an example payment method for a redirected service. Another for adding and testing an example CC payment method.

Committed this.

pcambra’s picture

Status: Fixed » Needs work

A couple of things after reviewing this:

  • User site_admin is not really needed for the tests, we could remove it from setUp
  • The comment at the beginning refers to checkout tests.
  • Do we need to do assertions in auxiliar functions as createOrderAndGoToPayment? I think that those assertions belong to checkout tests
  • In testCommercePaymentCheckout you're asserting the validation for 2 or more chars long, so we are doing part of the validation of the pane in checkout tests and other part in the payment tests, we could do a test for both validations in payment test and take it out from checkout.
  • We would want to test if the normal user is able to access the administration interface for payments, check last product ui tests.
  • I think testCommercePaymentAdministration test should also do a test for a complete payment, not only partial
  • $this->assertFieldByXPath("//input[starts-with(@id, 'edit-amount')]".. (and similar) could be just $this->assertFieldById('edit-amount' ...
recidive’s picture

Status: Needs work » Needs review

I did the following improvements to payments tests, but was not able to post an update here due to Git migration.

From the commit message:

  • Test adding remaining payment needed to complete the order amount.
  • Moving payment method validation tests from checkout module.
  • Removing Site Admin user.

https://github.com/recidive/drupalcommerce/commit/22daa8bbff26a86d78c2be...

@pcambra, I think we can leave the assertions there in createOrderAndGoToPayment(), since they are basically checking if we are on the correct pages. Will the $this->assertFieldById() work for ajax posts too?

I'll add the access check tests.

recidive’s picture

pcambra’s picture

Status: Needs review » Needs work

Do we really need to keep assertions in each process?

I'm working in customer tests now and I'm going to include the generic "create order" with customer information filled in the commerce_base so we don't have to include it all over again (payment tests and tax tests include it and probably checkout tests can get benefit of this function as well), so there will be a commerce base test that ensures that the piece of code is correct, I'll update this issue as soon as we can include it.

With the new payment method access to administration test, we can get rid of the assertion in testCommercePaymentAdministration for 200 response (line 178)
and in testCommercePaymentMethodsAdministration (line 239)

I think we need to complete a payment, currently testCommercePaymentAdministration only "pays" half of the order total

Also we should create a helper module for offsite payments and test that the payment redirect happens, that the offsite button is present and so on.

I tested the replacement of assertFieldByXPath by assertFieldById and it seems safe even after the postAjax.

recidive’s picture

"I think we need to complete a payment, currently testCommercePaymentAdministration only "pays" half of the order total"

This was done in #5.

It's not clear in your comment what needs work.

pcambra’s picture

I pulled from your github repo for this branch (1069896) and I can see changes in #6 but not changes in #5, maybe you could take a look to this and put together the changes in a patch?

recidive’s picture

Status: Needs work » Needs review
StatusFileSize
new7.97 KB
pcambra’s picture

Status: Needs review » Needs work

I've merged all the on-going tests in this issue #908302: Complete "version 1.0" of the CommerceBaseTestCase

Setting this to needs work as we need to create a helper module for offsite payments and test that the payment redirect happens, that the offsite button is present and so on.

pcambra’s picture

Status: Needs work » Needs review

Added new testing for offsite payment methods

Repo: git.drupal.org:sandbox/pcambra/1081200.git
Branch: 1069896
Diff: http://drupalcode.org/sandbox/pcambra/1081200.git/commitdiff/52033605dd5...

rszrama’s picture

Status: Needs review » Needs work

Does this need to stay in needs work mode? I've pulled those changes in, but we can further extend the tests by defining "remote" URLs in that module - i.e. page callbacks that redirect right back to the success or failure page to ensure the checkout workflow is correct. It doesn't really matter that we aren't actually redirecting to a URL on a separate domain, just that there's some sort of redirect and that we test a return that either simulates a customer cancellation, a failed payment, or a successful payment.

bojanz’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)