5

I have followed the instructions here on how to link Magento up to PHPUnit and THAT works.

I have created some custom shipping methods that, based on the order weight, order total, and a couple of custom attributes, will dictate which shipping method is available.

How do I add products to the cart and go through the checkout process using PHPUnit so that I can see which shipping method(s) is(are) available?

The idea being I would change the combination of products in the cart as needed without having to do it manually.

My function so far is:

public function testFirstMethod()
{
        $this->_model = new Company_CustomShippingMethod_Model_Carrier;
        $request = new Mage_Shipping_Model_Rate_Request();
        $response = $this->_model->collectRates($request);

        $this->assertEquals(FALSE, $response);
}

which passes as at this point there is no order and the model returns false.

So, how do I add products to the cart and go through the checkout process using PHPUnit?

[Edit]

Using the answer from programmatically adding product to cart returns empty price, I can add products using:

$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->addProduct($product, $qty);

$quote->collectTotals()->save();

How do I programmatically perform a checkout to get the shipping methods being returned by Magento?

1

You could use EcomDev Framework to simulate those situations. http://www.ecomdev.org/ .

Just extend from a Ecomdev Test Case instead of PHPUnit and you are able to create Fixtures to fill your Database with your needs like getting a quote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.