2016-01-08 13:56:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Shipping_Zones.
|
|
|
|
* @package WooCommerce\Tests\Shipping_Zones
|
|
|
|
*/
|
2016-03-23 12:14:13 +00:00
|
|
|
class WC_Tests_Shipping_Zones extends WC_Unit_Test_Case {
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shipping_Zones::get_zones
|
|
|
|
*/
|
|
|
|
public function test_get_zones() {
|
|
|
|
// Setup
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::create_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Test
|
2016-03-23 12:14:13 +00:00
|
|
|
$zones = WC_Shipping_Zones::get_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Assert
|
2016-03-23 14:28:45 +00:00
|
|
|
$this->assertTrue( is_array( $zones ) );
|
|
|
|
$this->assertTrue( 4 === sizeof( $zones ) );
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Clean
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::remove_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shipping_Zones::get_zone
|
|
|
|
*/
|
|
|
|
public function test_get_zone() {
|
|
|
|
// Setup
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::create_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Test
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone = WC_Shipping_Zones::get_zone( 1 );
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Assert that the first zone is our local zone
|
|
|
|
$this->assertInstanceOf( 'WC_Shipping_Zone', $zone );
|
|
|
|
$this->assertEquals( $zone->get_zone_name(), 'Local' );
|
|
|
|
|
|
|
|
// Clean
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::remove_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shipping_Zones::get_zone_by
|
|
|
|
*/
|
|
|
|
public function test_get_zone_by() {
|
|
|
|
// Setup
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::create_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Test
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone = WC_Shipping_Zones::get_zone_by( 'zone_id', 2 );
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
$this->assertInstanceOf( 'WC_Shipping_Zone', $zone );
|
|
|
|
$this->assertEquals( $zone->get_zone_name(), 'Europe' );
|
|
|
|
|
|
|
|
// Test instance_id
|
|
|
|
$instance_id = $zone->add_shipping_method( 'flat_rate' );
|
|
|
|
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $instance_id );
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
$this->assertInstanceOf( 'WC_Shipping_Zone', $zone );
|
|
|
|
$this->assertEquals( $zone->get_zone_name(), 'Europe' );
|
|
|
|
|
|
|
|
// Clean
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::remove_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shipping_Zones::get_shipping_method
|
|
|
|
*/
|
|
|
|
public function test_get_shipping_method() {
|
|
|
|
// Setup
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::create_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Test
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone = WC_Shipping_Zones::get_zone_by( 'zone_id', 1 );
|
2016-01-08 13:56:01 +00:00
|
|
|
$instance_id = $zone->add_shipping_method( 'flat_rate' );
|
2016-03-23 12:14:13 +00:00
|
|
|
$shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id );
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
$this->assertInstanceOf( 'WC_Shipping_Flat_Rate', $shipping_method );
|
|
|
|
|
|
|
|
// Clean
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::remove_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shipping_Zones::delete_zone
|
|
|
|
*/
|
|
|
|
public function test_delete_zone() {
|
|
|
|
// Setup
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::create_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Test
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Shipping_Zones::delete_zone( 1 );
|
|
|
|
$zones = WC_Shipping_Zones::get_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Assert
|
2016-03-23 14:28:45 +00:00
|
|
|
$this->assertTrue( 3 === sizeof( $zones ) );
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Clean
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::remove_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shipping_Zones::get_zone_matching_package
|
|
|
|
*/
|
|
|
|
public function test_get_zone_matching_package() {
|
|
|
|
// Setup
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::create_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Test
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone1 = WC_Shipping_Zones::get_zone_matching_package( array(
|
2016-01-08 13:56:01 +00:00
|
|
|
'destination' => array(
|
|
|
|
'country' => 'GB',
|
|
|
|
'state' => 'Cambs',
|
|
|
|
'postcode' => 'CB23 1GG',
|
|
|
|
)
|
|
|
|
) );
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone2 = WC_Shipping_Zones::get_zone_matching_package( array(
|
2016-01-08 13:56:01 +00:00
|
|
|
'destination' => array(
|
|
|
|
'country' => 'GB',
|
|
|
|
'state' => 'Cambs',
|
|
|
|
'postcode' => 'PE12 1BG',
|
|
|
|
)
|
|
|
|
) );
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone3 = WC_Shipping_Zones::get_zone_matching_package( array(
|
2016-01-08 13:56:01 +00:00
|
|
|
'destination' => array(
|
|
|
|
'country' => 'US',
|
|
|
|
'state' => 'CA',
|
|
|
|
'postcode' => '90210',
|
|
|
|
)
|
|
|
|
) );
|
2016-03-23 12:14:13 +00:00
|
|
|
$zone4 = WC_Shipping_Zones::get_zone_matching_package( array(
|
2016-01-08 13:56:01 +00:00
|
|
|
'destination' => array(
|
|
|
|
'country' => 'US',
|
|
|
|
'state' => 'AL',
|
|
|
|
'postcode' => '12345',
|
|
|
|
)
|
|
|
|
) );
|
|
|
|
|
|
|
|
// Assert
|
2016-02-10 13:21:16 +00:00
|
|
|
$this->assertEquals( 'Local', $zone1->get_zone_name() );
|
|
|
|
$this->assertEquals( 'Europe', $zone2->get_zone_name() );
|
|
|
|
$this->assertEquals( 'California', $zone3->get_zone_name() );
|
|
|
|
$this->assertEquals( 'US', $zone4->get_zone_name() );
|
2016-01-08 13:56:01 +00:00
|
|
|
|
|
|
|
// Clean
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping_Zones::remove_mock_zones();
|
2016-01-08 13:56:01 +00:00
|
|
|
}
|
|
|
|
}
|