Unit Tests: add mock session handler
This commit is contained in:
parent
bf4ca33150
commit
02adbfa110
|
@ -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' );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Mock Session Handler
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
class WC_Mock_Session_Handler extends WC_Session { }
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue