Unit Tests: add mock session handler

This commit is contained in:
Max Rice 2014-09-05 02:35:53 -04:00
parent bf4ca33150
commit 02adbfa110
4 changed files with 26 additions and 1 deletions

View File

@ -85,6 +85,7 @@ class WC_Unit_Tests_Bootstrap {
public function includes() {
require_once( $this->tests_dir . '/framework/wc-unit-test-factory.php' );
require_once( $this->tests_dir . '/framework/class-wc-mock-session-handler.php' );
require_once( $this->tests_dir . '/framework/class-wc-unit-test-case.php' );
require_once( $this->tests_dir . '/framework/class-wc-api-unit-test-case.php' );
}

View File

@ -0,0 +1,7 @@
<?php
/**
* WooCommerce Mock Session Handler
*
* @since 2.2
*/
class WC_Mock_Session_Handler extends WC_Session { }

View File

@ -23,6 +23,23 @@ class WC_Unit_Test_Case extends WP_UnitTestCase {
// add custom factories
$this->factory = new WC_Unit_Test_Factory();
// setup mock WC session handler
add_filter( 'woocommerce_session_handler', array( $this, 'set_mock_session_handler' ) );
$this->setOutputCallback( array( $this, 'filter_output' ) );
}
/**
* Mock the WC session using the abstract class as cookies are not available
* during tests
*
* @since 2.2
* @return string
*/
public function set_mock_session_handler() {
return 'WC_Mock_Session_Handler';
}
}
/**

View File

@ -64,7 +64,7 @@ class WC_Tests_WooCommerce extends WC_Unit_Test_Case {
$this->assertInstanceOf( 'WC_Product_Factory', $this->wc->product_factory );
$this->assertInstanceOf( 'WC_Order_Factory', $this->wc->order_factory );
$this->assertInstanceOf( 'WC_Countries', $this->wc->countries );
$this->assertInstanceOf( 'WC_Session_Handler', $this->wc->session );
$this->assertInstanceOf( 'WC_Mock_Session_Handler', $this->wc->session );
$this->assertInstanceOf( 'WC_Cart', $this->wc->cart );
$this->assertInstanceOf( 'WC_Customer', $this->wc->customer );
}