Implement Commerce cart tests.
Something similar with what's done for Commerce 1 : http://cgit.drupalcode.org/commerce/tree/modules/cart/tests/commerce_car...

Based on work from #2617638: Create a CommerceTestBase (if not commited already).

Comments

vasike created an issue. See original summary.

vasike’s picture

Status: Active » Needs work
StatusFileSize
new3.45 KB

Here is the first work on Cart tests.
- (only) Tests for product Add to cart form

About this patch and this issue
- I used OrderTestBase as it seems it covers some setup aspects.
- Add to Setup - Create an cart order and a second variation/product (first is in the OrderTestBase) to be used for these tests
- testProductAddToCartForm - get the second product page, press add to cart button and check if the product is added in the cart.

Todo:
- testCartPage - some checks on cart page
- testCartOrder - some checks on the order and the products in the cart.
- testCartChangeQuantity - update quantities on cart page
- testCartRemove - remove products from cart.
- other tests?

About the Cart page it seems there are some requirements:
- Product variations need Prices - as the OrderTestBase is used, maybe the first product variation there needs to have price
- Cart it seems requires 'access content' permission, which is a Node module permission, is this correct?
This means the cart module should have node dependency?

vasike’s picture

Status: Needs work » Needs review
StatusFileSize
new6.18 KB

Updated the patch:
- testCartOrder - some checks on the order and the products in the cart.
- testCartPage - some checks on cart page
- testCartChangeQuantity - update quantities on cart page
- testCartRemove - remove products from cart.
- move the product variation and product creation to testProductAddToCartForm, instead of having in the setUp.
- Add price data for the order line item and product varation, as they are requested in the cart.
- add node module dependency and 'access content' for the permissions - requested by cart page.

Are there other tests needed here?

vasike’s picture

StatusFileSize
new6.08 KB

"rebased" the previous patch (#3).
It seems there were some changes: for Remove button in cart and permissions implementation (commit) for the CommerceTestBase

bojanz’s picture

Title: Commerce cart tests » Add a test for the cart page
Status: Needs review » Needs work

1) We can remove commerce, block from the modules list cause they're enabled by the parent class. We can also remove inline_entity_form and commerce_price cause they're dependencies, should be enabled automatically.

2) testProductAddToCartForm is out of scope, needs to be removed. We're only testing the cart page.

3) setUp() should use the cart provider to create a cart, and assign it to $this->cart. It should also assign $this->cartManager for later tests.

4) We don't need testCartOrder, we should assume that the cart provider and manager are functional (they need their own tests).

5) The other test methods should be merged together (test the presence of the quantity and remove elements, use them) to avoid unnecessary Drupal reinstalls between them.

vasike’s picture

Status: Needs work » Needs review
StatusFileSize
new3.61 KB

There is an updated patch following @bojanz directions:
1) keep only commerce_cart and node as dependencies
2) testProductAddToCartForm - removed, create new issue #2652768: AddToCartForm tests
3) cart and cartManager in setUp using Cart module API
4) testCartOrder removed
5) merge all tests left into testCartPage method.
extra
6) Move the test "setup" to a base class CartTestBase for other uses, for example for AddToCartForm tests.

bojanz’s picture

StatusFileSize
new3.04 KB

Attaching what was supposed to be the final version.

However, I can't get it to pass on Travis, even though it passes for both mglaman and me locally (run-tests.sh and Simpletest UI).
Test output is here: https://travis-ci.org/drupalcommerce/commerce/jobs/103381205
The view is rendered, as is the row, but there is no views form. The handlers don't seem to be invoked at all, I placed a die() in the Quantity handler's viewsForm() method, and got no change.

https://github.com/drupalcommerce/commerce/commit/7252aac7b9ed2c4dabcfc0... shows some other changes I tried to introduce, but which had no effect.

  • bojanz committed 288f686 on 8.x-2.x authored by vasike
    Issue #2650838 by vasike, bojanz: Add a test for the cart page
    
bojanz’s picture

Status: Needs review » Fixed

Committed, the test fail was due to a case sensitivity issue, fixed in https://github.com/drupalcommerce/commerce/commit/f3da642f301d4ff3d2b764...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.