Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Magento Checkout Integration Test
scope:
website:
- website_id: 1
code: default
name: Default Website
default_group_id: 1
is_default: 1
group:
- group_id: 1
website_id: 1
name: Default Store Group
default_store_id: 1
root_category_id: 2 #default
store:
- store_id: 1
website_id: 1
group_id: 1
code: default
name: Default Store
is_active: 1
config:
stores/default/checkout/options/enable_agreements: 0
default/general/country/allow: DE,GB
stores/default/dev/log/active: 1
stores/default/dev/log/file: tests-system.log
stores/default/dev/log/exception_file: tests-exception.log
eav:
catalog_product:
-
entity_id: 1
stock:
qty: 100
is_in_stock: 1
website_ids:
- default
sku: test
name: Test
status: 1 # enabled
type_id: simple
price: 1.00
<?php
/**
* Integration test for OnePageCheckout
*
* @author Fabian Schmengler <fschmengler@sgh-it.eu>
* @copyright SGH informationstechnologie UGmbH 2012
* @package SGH\Common
* @subpackage Test
*
*/
class SGH_Common_Test_Controller_Checkout_OnepageController
extends EcomDev_PHPUnit_Test_Case_Controller
{
protected function setUp()
{
parent::setUp();
/*
* uncomment if test system has no mail capability
*/
//$this->_replaceMailerModels();
}
protected function _replaceMailerModels()
{
$this->replaceByMock(
'model', 'core/email_template',
$this->_mockMailer('core/email_template')
);
$this->replaceByMock(
'model', 'core/email', $this->_mockMailer('core/email')
);
}
/**
* Returns mock for given mailer model
*
* @param string $model class alias
* @return PHPUnit_Framework_MockObject_MockObject
*/
protected function _mockMailer($model)
{
return $this->getModelMock(
$model, array('send', 'sendTransactional')
);
}
protected function tearDown()
{
$this->_deleteOrders();
parent::tearDown();
}
/**
* Deletes any created order
*
* @return void
*/
protected function _deleteOrders()
{
Mage::register('isSecureArea', true);
/* @var $orders Mage_Sales_Model_Mysql4_Order_Collection */
$orders = Mage::getModel('sales/order')->getCollection()->load();
$orders->walk('delete');
}
/**
* @author Alistair Stead
* @author Fabian Schmengler (rewritten for EcomDev PHPUnit)
* @test
* @loadFixture
*/
public function magentoCheckoutIntegrationTest()
{
$this->setCurrentStore('default');
// Add the product to the basket
$this->getRequest()->setMethod('POST')
->setPost(
array(
'product' => '1',
'related_product' => '',
'qty' => '1'
)
);
// Set an initial cookie so that the Magento cookie validation passes
$this->getRequest()->setCookie('mage-test', true);
$this->dispatch('checkout/cart/add');
$this->assertResponseHttpCode('302', '/checkout/cart/add/ has not redirected to the cart');
$this->assertRedirectToUrlRegExp("/^.*checkout.*$/", 'We are not directed to the checkout as expected');
$this->reset();
$this->_fixCheckout();
$this->_debugCheckout();
// Set the checkout as guest
$this->getRequest()->setMethod('POST')
->setPost(
array(
'method' => 'guest'
)
);
$this->dispatch('checkout/onepage/saveMethod');
$this->assertResponseHttpCode('200', '/checkout/onepage/saveMethod/ has not responded as expected');
$this->reset();
// Save billing address
$this->getRequest()->setMethod('POST')
->setPost(
array(
'billing' => array(
'address_id' => '',
'firstname' => 'Authorize',
'lastname' => 'Capture',
'company' => '',
'email' => 'user@mage-test.co.uk',
'street' => array('Flat 14b', 'Baker Street'),
'city' => 'London',
'region_id' => '',
'postcode' => 'W1B OW3',
'country_id' => 'GB',
'telephone' => '+44 1234 123456',
'fax' => '+44 1234 123456',
'customer_password' => '',
'confirm_password' => '',
'save_in_address_book' => '1',
'use_for_shipping' => '1'
)
)
);
$this->dispatch('checkout/onepage/saveBilling');
$this->assertResponseHttpCode('200', '/checkout/onepage/saveBilling/ has not responded as expected');
$this->reset();
// Set shipping method
$this->getRequest()->setMethod('POST')
->setPost(
array(
'shipping_method' => 'flatrate_flatrate'
)
);
$this->dispatch('checkout/onepage/saveShippingMethod');
$this->assertResponseHttpCode('200', '/checkout/onepage/saveShippingMethod/ has not responded as expected');
$this->reset();
// Save payment
$this->getRequest()->setMethod('POST')
->setPost(
array(
'payment' => array(
'method' => 'checkmo'
)
)
);
$this->dispatch('checkout/onepage/savePayment');
$this->assertResponseHttpCode('200', '/checkout/onepage/savePayment/ has not responded as expected');
$this->reset();
// Save order
$this->getRequest()->setMethod('POST')
->setPost(
array(
'payment' => array(
'method' => 'checkmo'
)
)
);
$this->dispatch('checkout/onepage/saveOrder');
$this->assertResponseHttpCode('200', '/checkout/onepage/saveOrder/ has not responded as expected');
// Decode the JSON response so that we can evaluate the success
$data = json_decode($this->getResponse()->getOutputBody(), true);
$this->assertTrue(
$data['success'],
'Unexpected status expected result: ' .
array_key_exists('error_messages', $data)
? $data['error_messages'] : ' - '
);
}
/*
* 403 Session Expired: Root Cause Analysis
*/
protected function _debugCheckout()
{
/* @var $opc Mage_Checkout_Model_Type_Onepage */
$opc = Mage::getSingleton('checkout/type_onepage');
$this->assertTrue(
$opc->getQuote()->hasItems(),
'DEBUG: hasItems()'
);
$this->assertEquals(
false, $opc->getQuote()->getHasError(),
'DEBUG: hasError'
);
$this->assertEquals(
false, $opc->getQuote()->getIsMultiShipping(),
'DEBUG: isMultiShipping'
);
$this->assertEquals(
false, Mage::getSingleton('checkout/session')->getCartWasUpdated(),
'DEBUG: cartWasUpdated'
);
/*
* payment method
*/
$check = (string) $this->app()->getConfig()->getNode(
'payment/checkmo/active', 'store', 'default'
);
$this->assertEquals('1', $check, 'DEBUG: Check / Money Order is active');
}
/*
* solved :-)
*/
protected function _fixCheckout()
{
Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.