122 lines
4.0 KiB
PHP
122 lines
4.0 KiB
PHP
<?php
|
|
|
|
class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
|
|
|
/**
|
|
* @covers Wiaas_Package_Status::register_package_status_taxonomy()
|
|
* @covers Wiaas_Package_Status::get_available_package_statuses()
|
|
*/
|
|
function test_register_package_status_taxonomy() {
|
|
$taxonomy = get_taxonomy('package_status');
|
|
|
|
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
|
|
|
$package_statuses = Wiaas_Package_Status::get_available_package_statuses();
|
|
|
|
$this->assertNotEmpty($package_statuses);
|
|
|
|
$this->assertContains(Wiaas_Package_Status::AVAILABLE, $package_statuses);
|
|
$this->assertContains(Wiaas_Package_Status::INVALID_MARGIN, $package_statuses);
|
|
}
|
|
|
|
/**
|
|
* @covers Wiaas_Package_Type::set_package_status()
|
|
* @covers Wiaas_Package_Type::get_package_status()
|
|
*/
|
|
function test_adding_package_status() {
|
|
$package = $this->factory->product->create_product_bundle();
|
|
|
|
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::AVAILABLE);
|
|
|
|
$package_status = Wiaas_Package_Status::get_package_status($package->get_id());
|
|
|
|
$this->assertNotNull($package_status);
|
|
$this->assertEquals($package_status, Wiaas_Package_Status::AVAILABLE);
|
|
}
|
|
|
|
/**
|
|
* Test package status update on simple product price update
|
|
*/
|
|
function test_package_status_update_on_simple_product_price_update() {
|
|
|
|
$product1 = $this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' ));
|
|
|
|
$package = $this->factory->product->create_product_bundle(array(
|
|
'products' => array(
|
|
$product1,
|
|
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'software' ))
|
|
)
|
|
));
|
|
|
|
$pricing_rules = array(
|
|
'purchase' => array(
|
|
'minimal_fixed_price' => 100,
|
|
'principal_amount' => 0,
|
|
'minimal_services_price' => 0
|
|
),
|
|
'purchase_24' => array(
|
|
'minimal_fixed_price' => 100,
|
|
'principal_amount' => 0,
|
|
'minimal_services_price' => 100
|
|
),
|
|
'managed_36' => array(
|
|
'minimal_fixed_price' => 100,
|
|
'principal_amount' => 100,
|
|
'minimal_services_price' => 100
|
|
)
|
|
);
|
|
$commision = 50;
|
|
$cost_margin = 100;
|
|
|
|
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
|
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::AVAILABLE);
|
|
|
|
$this->factory->product->set_product_price($product1, 1000);
|
|
|
|
Wiaas_Package_Pricing::on_product_update($product1->get_id());
|
|
|
|
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::INVALID_MARGIN);
|
|
|
|
}
|
|
|
|
/**
|
|
* Test package status update on cost margin update
|
|
*/
|
|
function test_package_status_update_on_margin_cost_update() {
|
|
$package = $this->factory->product->create_product_bundle(array(
|
|
'products' => array(
|
|
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
|
|
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'software' ))
|
|
)
|
|
));
|
|
|
|
$pricing_rules = array(
|
|
'purchase' => array(
|
|
'minimal_fixed_price' => 100,
|
|
'principal_amount' => 0,
|
|
'minimal_services_price' => 0
|
|
),
|
|
'purchase_24' => array(
|
|
'minimal_fixed_price' => 100,
|
|
'principal_amount' => 0,
|
|
'minimal_services_price' => 100
|
|
),
|
|
'managed_36' => array(
|
|
'minimal_fixed_price' => 100,
|
|
'principal_amount' => 100,
|
|
'minimal_services_price' => 100
|
|
)
|
|
);
|
|
$commision = 50;
|
|
$cost_margin = 0;
|
|
|
|
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
|
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::AVAILABLE);
|
|
|
|
$cost_margin = 1;
|
|
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
|
|
|
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::INVALID_MARGIN);
|
|
|
|
}
|
|
} |