create_new_product(20); $this->add_product_category($product1, 'hardware'); $product2 = $this->create_new_product(20, true, 2); $this->add_product_category($product2, 'installation'); $package = $this->create_new_package(); $this->add_products_to_package($package, array( $product1, $product2)); $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; Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision); $expected_prices = array( 'purchase' => array( 'fixed_extra' => 100, 'recurrent_extra' => 0, 'services_extra' => 0 ), 'purchase_24' => array( 'fixed_extra' => 100, 'recurrent_extra' => 0, 'services_extra' => 100 ), 'managed_36' => array( 'fixed_extra' => 100, 'recurrent_extra' => 3, 'services_extra' => 100 ) ); return array( $package, $expected_prices ); } /** * @covers Wiaas_Pricing::get_product_total_cost() */ function test_get_fixed_product_total_cost() { $product = $this->create_new_product(); $total_cost = Wiaas_Pricing::get_product_total_cost($product); $this->assertEquals($total_cost, $product->get_price()); } /** * @covers Wiaas_Pricing::get_product_total_cost() */ function test_get_recurring_product_total_cost() { $product = $this->create_new_product(10, true, 2); $total_cost = Wiaas_Pricing::get_product_total_cost($product); $this->assertEquals($total_cost, 20); } /** * @covers Wiaas_Pricing::get_package_total_cost() */ function test_get_package_with_fixed_products_total_cost() { $product1 = $this->create_new_product(20); $this->add_product_category($product1, 'hardware'); $product2 = $this->create_new_product(20); $this->add_product_category($product2, 'software'); $package = $this->create_new_package(); $this->add_products_to_package($package, array( $product1, $product2)); $expected_total_price = 40; $total_price = Wiaas_Pricing::get_package_total_cost($package); $this->assertEquals($expected_total_price, $total_price); } /** * @covers Wiaas_Pricing::get_package_total_cost() */ function test_get_package_with_recurring_products_total_cost() { $product1 = $this->create_new_product(20); $this->add_product_category($product1, 'hardware'); $product2 = $this->create_new_product(20, true, 2); $this->add_product_category($product2, 'software'); $package = $this->create_new_package(); $this->add_products_to_package($package, array( $product1, $product2)); $expected_total_price = 60; $total_price = Wiaas_Pricing::get_package_total_cost($package); $this->assertEquals($expected_total_price, $total_price); } /** * @covers Wiaas_Pricing::get_package_total_cost() */ function test_package_with_single_installation_product_total_cost() { $product1 = $this->create_new_product(20); $this->add_product_category($product1, 'hardware'); $product2 = $this->create_new_product(20, true, 2); $this->add_product_category($product2, 'installation'); $package = $this->create_new_package(); $this->add_products_to_package($package, array( $product1, $product2)); $expected_total_price = 60; $total_price = Wiaas_Pricing::get_package_total_cost($package); $this->assertEquals($expected_total_price, $total_price); } /** * @covers Wiaas_Pricing::get_package_total_cost() */ function test_package_with_multiple_installation_products_total_cost() { $product1 = $this->create_new_product(20); $this->add_product_category($product1, 'hardware'); $product2 = $this->create_new_product(10, true, 2); $this->add_product_category($product2, 'installation'); $this->assertTrue(Wiaas_Product_Category::is_installation($product2)); $product3 = $this->create_new_product(20, true, 2); $this->add_product_category($product3, 'installation'); $package = $this->create_new_package(); $this->add_products_to_package($package, array( $product1, $product2, $product3)); // price will be 20 + 20*2 , more expensive installation will be applied $expected_total_price = 60; $total_price = Wiaas_Pricing::get_package_total_cost($package); $this->assertEquals($expected_total_price, $total_price); } /** * @covers Wiaas_Pricing::get_standard_package_customer_prices() */ function test_get_standard_package_customer_price() { list( $package, $expected_prices ) = $this->_create_package_to_sell(); $customer_prices = Wiaas_Pricing::get_standard_package_customer_prices($package); $this->assertCount(3, $customer_prices); foreach ($customer_prices as $customer_price) { $this->assertArrayHasKey('id', $customer_price); $this->assertArrayHasKey('payment_type', $customer_price); $this->assertArrayHasKey('max_contract_period', $customer_price); $this->assertArrayHasKey('package_pay_period', $customer_price); $this->assertArrayHasKey('period_unit', $customer_price); $this->assertArrayHasKey('services_contract_period', $customer_price); $this->assertArrayHasKey('fixed_extra', $customer_price); $this->assertArrayHasKey('recurrent_extra', $customer_price); $this->assertArrayHasKey('services_extra', $customer_price); $id = $customer_price['id']; $this->assertEquals($customer_price['fixed_extra'], $expected_prices[$id]['fixed_extra']); $this->assertEquals($customer_price['recurrent_extra'], $expected_prices[$id]['recurrent_extra']); $this->assertEquals($customer_price['services_extra'], $expected_prices[$id]['services_extra']); } } /** * @covers Wiaas_Pricing::get_addon_package_customer_price() */ function test_get_addon_package_customer_price() { list( $package ) = $this->_create_package_to_sell(); $addon_product = $this->create_new_product(20); $this->add_product_category($addon_product, 'hardware'); $addon_package = $this->create_new_package(); $this->add_products_to_package($addon_package, array($addon_product)); $pricing_rules = array( 'purchase' => array( 'minimal_fixed_price' => 500, 'principal_amount' => 0, 'minimal_services_price' => 0 ), 'purchase_24' => array( 'minimal_fixed_price' => 500, 'principal_amount' => 0, 'minimal_services_price' => 500 ), 'managed_36' => array( 'minimal_fixed_price' => 500, 'principal_amount' => 500, 'minimal_services_price' => 500 ) ); $commision = 50; Wiaas_Package_Pricing::set_package_prices($addon_package, $pricing_rules, $commision); Wiaas_Package_Addon::set_package_addons($package, array($addon_package->get_id())); $expected_prices = array( 'purchase' => array( 'fixed_extra' => 500, 'recurrent_extra' => 0, 'services_extra' => 0 ), 'purchase_24' => array( 'fixed_extra' => 500, 'recurrent_extra' => 0, 'services_extra' => 500 ), 'managed_36' => array( 'fixed_extra' => 500, 'recurrent_extra' => 14, 'services_extra' => 500 ) ); $customer_prices = Wiaas_Pricing::get_addon_package_customer_price($addon_package, $package); $this->assertCount(3, $customer_prices); foreach ($customer_prices as $customer_price) { $this->assertArrayHasKey('id', $customer_price); $this->assertArrayHasKey('payment_type', $customer_price); $this->assertArrayHasKey('max_contract_period', $customer_price); $this->assertArrayHasKey('package_pay_period', $customer_price); $this->assertArrayHasKey('period_unit', $customer_price); $this->assertArrayHasKey('services_contract_period', $customer_price); $this->assertArrayHasKey('fixed_extra', $customer_price); $this->assertArrayHasKey('recurrent_extra', $customer_price); $this->assertArrayHasKey('services_extra', $customer_price); $id = $customer_price['id']; $this->assertEquals($customer_price['fixed_extra'], $expected_prices[$id]['fixed_extra']); $this->assertEquals($customer_price['recurrent_extra'], $expected_prices[$id]['recurrent_extra']); $this->assertEquals($customer_price['services_extra'], $expected_prices[$id]['services_extra']); } } /** * @covers Wiaas_Pricing::get_option_package_customer_price() */ function test_get_option_package_customer_price() { list( $package ) = $this->_create_package_to_sell(); $option_product = $this->create_new_product(20); $this->add_product_category($option_product, 'hardware'); $option_package = $this->create_new_package(); $this->add_products_to_package($option_package, array($option_product)); $pricing_rules = array( 'purchase' => array( 'minimal_fixed_price' => 500, 'principal_amount' => 0, 'minimal_services_price' => 0 ), 'purchase_24' => array( 'minimal_fixed_price' => 500, 'principal_amount' => 0, 'minimal_services_price' => 500 ), 'managed_36' => array( 'minimal_fixed_price' => 500, 'principal_amount' => 500, 'minimal_services_price' => 500 ) ); $commision = 50; Wiaas_Package_Pricing::set_package_prices($option_package, $pricing_rules, $commision); Wiaas_Package_Option_Groups::set_package_option_groups($package, array( 'id' => 'option', 'name' => 'Option', 'default' => $option_package->get_id(), 'options' => array( $option_package->get_id() ) )); $expected_prices = array( 'purchase' => array( 'fixed_extra' => 500, 'recurrent_extra' => 0, 'services_extra' => 0 ), 'purchase_24' => array( 'fixed_extra' => 500, 'recurrent_extra' => 0, 'services_extra' => 500 ), 'managed_36' => array( 'fixed_extra' => 500, 'recurrent_extra' => 14, 'services_extra' => 500 ) ); $customer_prices = Wiaas_Pricing::get_option_package_customer_price($option_package, $package); $this->assertCount(3, $customer_prices); foreach ($customer_prices as $customer_price) { $this->assertArrayHasKey('id', $customer_price); $this->assertArrayHasKey('payment_type', $customer_price); $this->assertArrayHasKey('max_contract_period', $customer_price); $this->assertArrayHasKey('package_pay_period', $customer_price); $this->assertArrayHasKey('period_unit', $customer_price); $this->assertArrayHasKey('services_contract_period', $customer_price); $this->assertArrayHasKey('fixed_extra', $customer_price); $this->assertArrayHasKey('recurrent_extra', $customer_price); $this->assertArrayHasKey('services_extra', $customer_price); $id = $customer_price['id']; $this->assertEquals($customer_price['fixed_extra'], $expected_prices[$id]['fixed_extra']); $this->assertEquals($customer_price['recurrent_extra'], $expected_prices[$id]['recurrent_extra']); $this->assertEquals($customer_price['services_extra'], $expected_prices[$id]['services_extra']); } } }