2017-04-24 18:33:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WC_Object_Query tests
|
|
|
|
* @package WooCommerce\Tests\CRUD
|
2017-04-26 17:49:19 +00:00
|
|
|
* @since 3.1.0
|
2017-04-24 18:33:17 +00:00
|
|
|
*/
|
|
|
|
class WC_Tests_WC_Object_Query extends WC_Unit_Test_Case {
|
|
|
|
|
2017-04-26 17:49:19 +00:00
|
|
|
/**
|
|
|
|
* Test the default query var values.
|
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*/
|
2017-04-24 18:33:17 +00:00
|
|
|
function test_default_query() {
|
|
|
|
$query = new WC_Mock_WC_Object_Query();
|
|
|
|
|
|
|
|
$this->assertNotEmpty( $query->query_vars );
|
2017-04-24 23:28:13 +00:00
|
|
|
$this->assertEquals( '', $query->get( 'parent' ) );
|
2017-04-24 18:33:17 +00:00
|
|
|
$this->assertEquals( 'date', $query->get( 'orderby' ) );
|
|
|
|
}
|
|
|
|
|
2017-04-26 17:49:19 +00:00
|
|
|
/**
|
|
|
|
* Test setting/getting query vars.
|
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*/
|
2017-04-24 18:33:17 +00:00
|
|
|
function test_query_with_args() {
|
|
|
|
$args = array(
|
2017-04-24 23:28:13 +00:00
|
|
|
'per_page' => 15,
|
2017-04-24 18:33:17 +00:00
|
|
|
'year' => 2017
|
|
|
|
);
|
|
|
|
$query = new WC_Mock_WC_Object_Query( $args );
|
|
|
|
|
2017-04-24 23:28:13 +00:00
|
|
|
$this->assertEquals( 15, $query->get( 'per_page' ) );
|
2017-04-24 18:33:17 +00:00
|
|
|
$this->assertEquals( 2017, $query->get( 'year' ) );
|
|
|
|
|
|
|
|
$query->set( 'year', 2016 );
|
|
|
|
$this->assertEquals( 2016, $query->get( 'year' ) );
|
|
|
|
}
|
|
|
|
}
|