Tests
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Package_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Package_Pricing::set_package_prices()
|
||||
* @covers Wiaas_Package_Pricing::get_package_prices()
|
||||
*/
|
||||
function test_set_and_get_package_prices() {
|
||||
|
||||
$package = $this->create_new_package();
|
||||
|
||||
$pricing_rules = array(
|
||||
'purchase' => array(
|
||||
'minimal_fixed_price' => 10,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 0
|
||||
),
|
||||
'purchase_24' => array(
|
||||
'minimal_fixed_price' => 10,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 10
|
||||
),
|
||||
'managed_36' => array(
|
||||
'minimal_fixed_price' => 10,
|
||||
'principal_amount' => 10,
|
||||
'minimal_services_price' => 10
|
||||
)
|
||||
);
|
||||
|
||||
$commision = 60;
|
||||
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision);
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
$this->assertCount(3, $configured_prices);
|
||||
|
||||
$this->assertArrayHasKey('purchase', $configured_prices);
|
||||
$this->assertArrayHasKey('purchase_24', $configured_prices);
|
||||
$this->assertArrayHasKey('managed_36', $configured_prices);
|
||||
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
|
||||
$this->assertArrayHasKey('id', $configured_price);
|
||||
$this->assertArrayHasKey('payment_type', $configured_price);
|
||||
$this->assertArrayHasKey('max_contract_period', $configured_price);
|
||||
$this->assertArrayHasKey('package_pay_period', $configured_price);
|
||||
$this->assertArrayHasKey('period_unit', $configured_price);
|
||||
$this->assertArrayHasKey('services_contract_period', $configured_price);
|
||||
$this->assertArrayHasKey('commision_split', $configured_price);
|
||||
$this->assertArrayHasKey('minimal_fixed_price', $configured_price);
|
||||
$this->assertArrayHasKey('principal_amount', $configured_price);
|
||||
$this->assertArrayHasKey('minimal_services_price', $configured_price);
|
||||
|
||||
$this->assertEquals($configured_price['id'], $type);
|
||||
$this->assertEquals($configured_price['commision_split'], $commision / 100);
|
||||
|
||||
$this->assertEquals($configured_price['minimal_fixed_price'], $pricing_rules[$type]['minimal_fixed_price']);
|
||||
$this->assertEquals($configured_price['principal_amount'], $pricing_rules[$type]['principal_amount']);
|
||||
$this->assertEquals($configured_price['minimal_services_price'], $pricing_rules[$type]['minimal_services_price']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Product_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Product_Pricing::set_product_price()
|
||||
* @covers Wiaas_Product_Pricing::get_product_price()
|
||||
*/
|
||||
function test_adding_product_price() {
|
||||
$product = $this->create_new_product(10, true, 2);
|
||||
|
||||
$configured_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
$this->assertNotNull($configured_price);
|
||||
|
||||
$this->assertArrayHasKey('price', $configured_price);
|
||||
$this->assertArrayHasKey('is_recurring', $configured_price);
|
||||
$this->assertArrayHasKey('pay_period', $configured_price);
|
||||
|
||||
$this->assertEquals($configured_price['price'], 10);
|
||||
$this->assertEquals($configured_price['is_recurring'], true);
|
||||
$this->assertEquals($configured_price['pay_period'], 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Product_Pricing::get_product_price_html()
|
||||
*/
|
||||
function test_get_product_fixed_price_html() {
|
||||
$product = $this->create_new_product();
|
||||
|
||||
$original_price_html = $product->get_price_html();
|
||||
|
||||
$price_html = Wiaas_Product_Pricing::get_product_price_html($original_price_html, $product);
|
||||
|
||||
$this->assertEquals($price_html, $original_price_html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Product_Pricing::get_product_price_html()
|
||||
*/
|
||||
function test_get_product_recurrent_price_html() {
|
||||
$product = $this->create_new_product(10, true, 1);
|
||||
|
||||
$original_price_html = $product->get_price_html();
|
||||
|
||||
$price_html = Wiaas_Product_Pricing::get_product_price_html($original_price_html, $product);
|
||||
|
||||
$this->assertEquals($price_html, $original_price_html . ' / month');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Product_Pricing::get_product_fixed_price()
|
||||
*/
|
||||
function test_get_fixed_price_for_fixed_product() {
|
||||
$product = $this->create_new_product();
|
||||
|
||||
$original_price = $product->get_price();
|
||||
|
||||
$fixed_price = Wiaas_Product_Pricing::get_product_fixed_price($original_price, $product);
|
||||
|
||||
$this->assertEquals($fixed_price, $original_price);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Product_Pricing::get_product_fixed_price()
|
||||
*/
|
||||
function test_get_fixed_price_for_recurring_product() {
|
||||
$product = $this->create_new_product(10, true, 1);
|
||||
|
||||
$fixed_price = Wiaas_Product_Pricing::get_product_fixed_price($product->get_price(), $product);
|
||||
|
||||
$this->assertEquals($fixed_price, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user