Fix assigment order issues

This commit is contained in:
Almira Krdzic
2018-12-02 22:18:09 +01:00
parent 3dbdb657c9
commit e87d1521dd
23 changed files with 873 additions and 256 deletions

View File

@@ -3,15 +3,16 @@
class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
private function _create_package_to_sell() {
$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));
$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,
'is_recurring' => true,
'pay_period' => 2,
'category' => 'installation' ))
)
));
$pricing_rules = array(
'purchase' => array(
@@ -32,17 +33,16 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
);
$commision = 50;
$cost_margin = 0;
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
$customer_id = wp_create_term(
'Customer',
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
$this->factory->product->set_product_bundle_prices($package, $pricing_rules, $commision, $cost_margin);
$commercial_lead_id = wp_create_term(
'Commercial Lead',
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
$customer_id = $this->factory->organization->create_new_organization(
array( 'name' => 'Customer' )
);
$commercial_lead_id = $this->factory->organization->create_new_organization(
array( 'name' => 'Commercial Lead' )
);
self::_set_package_default_extras($commercial_lead_id, $package->get_id());
@@ -97,7 +97,7 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_product_total_cost()
*/
function test_get_fixed_product_total_cost() {
$product = $this->create_new_product();
$product = $this->factory->product->create_simple_product();
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
@@ -108,7 +108,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_product_total_cost()
*/
function test_get_recurring_product_total_cost() {
$product = $this->create_new_product(10, true, 2);
$product = $this->factory->product->create_simple_product(array(
'price' => 10,
'is_recurring' => true,
'pay_period' => 2
));
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
@@ -119,15 +123,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @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));
$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' ))
)
));
$expected_total_price = 40;
@@ -140,15 +141,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @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));
$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, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'software' ))
)
));
$expected_total_price = 60;
@@ -161,15 +159,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @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));
$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, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'installation' ))
)
));
$expected_total_price = 60;
@@ -182,20 +177,13 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @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));
$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, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'installation' )),
$this->factory->product->create_simple_product(array( 'price' => 20, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'installation' ))
)
));
// price will be 20 + 20*2 , more expensive installation will be applied
$expected_total_price = 60;
@@ -246,12 +234,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
function test_get_addon_package_customer_price() {
list( $package, $expected_prices, $customer_id, $commercial_lead_id ) = $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));
$addon_package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
)
));
$pricing_rules = array(
'purchase' => array(
@@ -330,12 +317,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
function test_get_option_package_customer_price() {
list( $package, $customer_id, $commercial_lead_id ) = $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));
$option_package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
)
));
$pricing_rules = array(
'purchase' => array(