Fix assigment order issues
This commit is contained in:
@@ -16,10 +16,10 @@ class Wiaas_Package_Addon_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_Package_Addon::get_package_addons()
|
||||
*/
|
||||
function test_adding_package_addons() {
|
||||
$package = $this->create_new_package();
|
||||
$package = $this->factory->product->create_product_bundle();
|
||||
|
||||
$addon1 = $this->create_new_package();
|
||||
$addon2 = $this->create_new_package();
|
||||
$addon1 = $this->factory->product->create_product_bundle();
|
||||
$addon2 = $this->factory->product->create_product_bundle();
|
||||
$addons_ids = array(
|
||||
$addon1->get_id(),
|
||||
$addon2->get_id()
|
||||
|
||||
@@ -16,12 +16,12 @@ class Wiaas_Package_Option_Groups_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_Package_Option_Groups::get_package_option_groups()
|
||||
*/
|
||||
function test_adding_package_option_group() {
|
||||
$package = $this->create_new_package();
|
||||
$package = $this->factory->product->create_product_bundle();
|
||||
|
||||
$option_package1 = $this->create_new_package();
|
||||
$option_package1 = $this->factory->product->create_product_bundle();
|
||||
Wiaas_Package_Type::set_package_type($option_package1->get_id(), 'option');
|
||||
|
||||
$option_package2 = $this->create_new_package();
|
||||
$option_package2 = $this->factory->product->create_product_bundle();
|
||||
Wiaas_Package_Type::set_package_type($option_package2->get_id(), 'option');
|
||||
|
||||
$option_group1 = array(
|
||||
@@ -79,9 +79,9 @@ class Wiaas_Package_Option_Groups_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_Package_Option_Groups::get_group_name_for_package_option()
|
||||
*/
|
||||
function test_get_group_name_for_package_option() {
|
||||
$package = $this->create_new_package();
|
||||
$package = $this->factory->product->create_product_bundle();
|
||||
|
||||
$option_package = $this->create_new_package();
|
||||
$option_package = $this->factory->product->create_product_bundle();
|
||||
Wiaas_Package_Type::set_package_type($option_package->get_id(), 'option');
|
||||
|
||||
$option_group = array(
|
||||
|
||||
@@ -16,6 +16,7 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
||||
$this->assertNotEmpty($package_statuses);
|
||||
|
||||
$this->assertContains(Wiaas_Package_Status::AVAILABLE, $package_statuses);
|
||||
$this->assertContains(Wiaas_Package_Status::INVALID_MARGIN, $package_statuses);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_Package_Type::get_package_status()
|
||||
*/
|
||||
function test_adding_package_status() {
|
||||
$package = $this->create_new_package();
|
||||
$package = $this->factory->product->create_product_bundle();
|
||||
|
||||
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::AVAILABLE);
|
||||
|
||||
@@ -37,15 +38,15 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
||||
* Test package status update on simple product price update
|
||||
*/
|
||||
function test_package_status_update_on_simple_product_price_update() {
|
||||
$product1 = $this->create_new_product(20);
|
||||
$this->add_product_category($product1, 'hardware');
|
||||
|
||||
$product2 = $this->create_new_product(20);
|
||||
$this->add_product_category($product2, 'software');
|
||||
$product1 = $this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' ));
|
||||
|
||||
$package = $this->create_new_package();
|
||||
|
||||
$this->add_products_to_package($package, array( $product1, $product2));
|
||||
$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(
|
||||
@@ -68,10 +69,13 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
||||
$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->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::AVAILABLE);
|
||||
|
||||
$product1->set_price(1000);
|
||||
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::MARGIN_EXCEEDED);
|
||||
$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);
|
||||
|
||||
}
|
||||
|
||||
@@ -79,15 +83,12 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
||||
* Test package status update on cost margin update
|
||||
*/
|
||||
function test_package_status_update_on_margin_cost_update() {
|
||||
$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' ))
|
||||
)
|
||||
));
|
||||
|
||||
$pricing_rules = array(
|
||||
'purchase' => array(
|
||||
@@ -108,13 +109,14 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
||||
);
|
||||
$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);
|
||||
$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::MARGIN_EXCEEDED);
|
||||
|
||||
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::INVALID_MARGIN);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class Wiaas__Package_Type_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_Package_Type::get_package_type()
|
||||
*/
|
||||
function test_adding_package_type() {
|
||||
$package = $this->create_new_package();
|
||||
$package = $this->factory->product->create_product_bundle();
|
||||
|
||||
Wiaas_Package_Type::set_package_type($package->get_id(), 'standard');
|
||||
|
||||
|
||||
@@ -6,17 +6,17 @@ class Wiaas_Package_CL_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->shop_owner_id = wp_insert_term(
|
||||
'Shop owner organization',
|
||||
Wiaas_User_Organization::TAXONOMY_NAME)['term_id'];
|
||||
$this->shop_owner_id = $this->factory->organization->create_new_organization(
|
||||
array( 'name' => 'Shop owner organization' )
|
||||
);
|
||||
|
||||
$this->customer_id = wp_insert_term(
|
||||
'Customer Organization',
|
||||
Wiaas_User_Organization::TAXONOMY_NAME)['term_id'];
|
||||
$this->customer_id = $this->factory->organization->create_new_organization(
|
||||
array( 'name' => 'Customer Organization' )
|
||||
);
|
||||
|
||||
$package = $this->create_new_package();
|
||||
|
||||
$this->add_products_to_package($package, array( $this->create_new_product()));
|
||||
$package = $this->factory->product->create_product_bundle(array(
|
||||
'products' => array( $this->factory->product->create_simple_product() )
|
||||
));
|
||||
|
||||
$this->package_id = $package->get_id();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class Wiaas_Package_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
*/
|
||||
function test_set_and_get_package_prices() {
|
||||
|
||||
$package = $this->create_new_package();
|
||||
$package = $this->factory->product->create_product_bundle();
|
||||
|
||||
$pricing_rules = array(
|
||||
'purchase' => array(
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Access_Management_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @var WC_Order
|
||||
*/
|
||||
var $order;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
var $organization_id;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
var $customer_user_id;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
wp_set_current_user(1);
|
||||
|
||||
$this->customer_user_id = wp_insert_user(array(
|
||||
'user_login' => 'test_customer',
|
||||
'user_pass' => 'test',
|
||||
'user_email' => 'test_customer@mail.com',
|
||||
'role' => 'customer',
|
||||
));
|
||||
|
||||
$this->organization_id = $this->factory->organization->create_new_organization();
|
||||
|
||||
$this->factory->organization->assign_user_to_organization($this->customer_user_id, $this->organization_id);
|
||||
|
||||
$this->order = $this->factory->order->create_new_order();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
parent::tearDown();
|
||||
|
||||
wp_set_current_user(1);
|
||||
|
||||
wp_delete_user($this->customer_user_id);
|
||||
|
||||
$this->factory->organization->delete_organizations();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Access_Management::maybe_handle_product_access()
|
||||
*/
|
||||
function test_simple_product_has_admin_access() {
|
||||
|
||||
$simple_product = $this->factory->product->create_simple_product();
|
||||
|
||||
Wiaas_Access_Management::maybe_handle_product_access($simple_product->get_id(), get_post($simple_product->get_id()));
|
||||
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $simple_product->get_id() );
|
||||
$this->assertEquals(1, count($access_group_ids));
|
||||
$admin_access_group = Groups_Group::read_by_name('admin');
|
||||
$this->assertEquals($admin_access_group->group_id, $access_group_ids[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Access_Management::maybe_handle_product_access()
|
||||
*/
|
||||
function test_bundle_with_no_price_has_admin_access() {
|
||||
|
||||
$bundle_product = $this->factory->product->create_product_bundle();
|
||||
|
||||
Wiaas_Access_Management::maybe_handle_product_access($bundle_product->get_id(), get_post($bundle_product->get_id()));
|
||||
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $bundle_product->get_id() );
|
||||
$this->assertEquals(1, count($access_group_ids));
|
||||
$admin_access_group = Groups_Group::read_by_name('admin');
|
||||
$this->assertEquals($admin_access_group->group_id, $access_group_ids[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Access_Management::maybe_handle_product_access()
|
||||
*/
|
||||
function test_bundle_with_prices_has_registered_access() {
|
||||
|
||||
$bundle_product = $this->factory->product->create_product_bundle();
|
||||
$this->factory->product->set_product_bundle_prices($bundle_product);
|
||||
|
||||
Wiaas_Access_Management::maybe_handle_product_access($bundle_product->get_id(), get_post($bundle_product->get_id()));
|
||||
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $bundle_product->get_id() );
|
||||
$this->assertEquals(1, count($access_group_ids));
|
||||
$registered_access_group = Groups_Group::read_by_name('Registered');
|
||||
$this->assertEquals($registered_access_group->group_id, $access_group_ids[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Access_Management::assign_order_to_customer_organization()
|
||||
*/
|
||||
function test_order_assigned_to_customer_organization() {
|
||||
|
||||
wp_set_current_user($this->customer_user_id);
|
||||
|
||||
Wiaas_Access_Management::assign_order_to_customer_organization($this->order->get_id());
|
||||
|
||||
$organization_access_group = Groups_Group::read_by_name('organization');
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
|
||||
|
||||
$this->assertEquals(1, count($access_group_ids));
|
||||
$this->assertNotNull($access_group_ids[0]);
|
||||
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Access_Management::assign_order_to_commercial_lead_organization()
|
||||
*/
|
||||
function test_order_assigned_to_commercial_lead_organization() {
|
||||
|
||||
$this->order->update_meta_data('_wiaas_commercial_lead_id', $this->organization_id);
|
||||
$this->order->save_meta_data();
|
||||
|
||||
Wiaas_Access_Management::assign_order_to_commercial_lead_organization($this->order->get_id());
|
||||
|
||||
$organization_access_group = Groups_Group::read_by_name('organization');
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
|
||||
|
||||
$this->assertEquals(1, count($access_group_ids));
|
||||
$this->assertNotNull($access_group_ids[0]);
|
||||
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Access_Management::assign_order_to_supplier_organizations()
|
||||
*/
|
||||
function test_order_assigned_to_supplier_organizations() {
|
||||
|
||||
$items = array();
|
||||
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
|
||||
'category' => 'hardware',
|
||||
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'hardware supplier'))
|
||||
));
|
||||
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
|
||||
'category' => 'software',
|
||||
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'software supplier'))
|
||||
));
|
||||
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
|
||||
'category' => 'service',
|
||||
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'service supplier'))
|
||||
));
|
||||
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
|
||||
'category' => 'installation',
|
||||
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'installation supplier'))
|
||||
));
|
||||
|
||||
$this->factory->order->add_order_items($this->order, $items);
|
||||
|
||||
Wiaas_Access_Management::assign_order_to_supplier_organizations($this->order->get_id());
|
||||
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
|
||||
$this->assertEquals(3, count($access_group_ids));
|
||||
|
||||
$organization_access_group = Groups_Group::read_by_name('hardware supplier');
|
||||
$this->assertContains($organization_access_group->group_id, $access_group_ids);
|
||||
|
||||
$organization_access_group = Groups_Group::read_by_name('software supplier');
|
||||
$this->assertContains($organization_access_group->group_id, $access_group_ids);
|
||||
|
||||
$organization_access_group = Groups_Group::read_by_name('service supplier');
|
||||
$this->assertContains($organization_access_group->group_id, $access_group_ids);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Access_Management::assign_order_to_installation_organization()
|
||||
*/
|
||||
function test_order_assigned_to_installation_organization() {
|
||||
|
||||
$bundle_item = $this->factory->order->create_new_bundle_order_item();
|
||||
|
||||
$installation_item = $this->factory->order->create_new_simple_product_order_item(array(
|
||||
'category' => 'installation',
|
||||
'supplier_organization_id' => $this->organization_id
|
||||
));
|
||||
|
||||
$this->order->add_item($bundle_item);
|
||||
$this->order->add_item($installation_item);
|
||||
|
||||
Wiaas_Access_Management::assign_order_to_installation_organization($this->order, $bundle_item, $installation_item);
|
||||
|
||||
$organization_access_group = Groups_Group::read_by_name('organization');
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
|
||||
|
||||
$this->assertEquals(1, count($access_group_ids));
|
||||
$this->assertNotNull($access_group_ids[0]);
|
||||
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
var $product, $package, $current_country = 'Sweden';
|
||||
var $product, $package, $current_country = 'se';
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
@@ -13,14 +13,10 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
|
||||
# set admin as current user
|
||||
wp_set_current_user(1);
|
||||
|
||||
$this->product = $this->create_new_product();
|
||||
wp_set_object_terms($this->product->get_id(), $this->current_country, 'product_country', false);
|
||||
clean_object_term_cache( $this->product->get_id(), 'product_country' );
|
||||
$this->product = $this->factory->product->create_simple_product(array( 'country' => $this->current_country ));
|
||||
|
||||
|
||||
$this->package = $this->create_new_package();
|
||||
wp_set_object_terms($this->package->get_id(), $this->current_country, 'product_country', false);
|
||||
clean_object_term_cache( $this->package->get_id(), 'product_country' );
|
||||
$this->package = $this->factory->product->create_product_bundle(array( 'country' => $this->current_country ));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,15 +29,20 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
||||
|
||||
$country_names = array_map(function($term) {
|
||||
return $term->name;
|
||||
}, get_terms(array( 'taxonomy' => 'product_country', 'hide_empty' => false )));
|
||||
$countries = get_terms(
|
||||
array(
|
||||
'taxonomy' => 'product_country',
|
||||
'hide_empty' => false,
|
||||
'fields' => 'id=>slug'
|
||||
)
|
||||
);
|
||||
$country_codes = array_values($countries);
|
||||
|
||||
$this->assertNotEmpty($country_names);
|
||||
$this->assertNotEmpty($country_codes);
|
||||
|
||||
$this->assertContains('Sweden', $country_names);
|
||||
$this->assertContains('Denmark', $country_names);
|
||||
$this->assertContains('Finland', $country_names);
|
||||
$this->assertContains('se', $country_codes);
|
||||
$this->assertContains('fi', $country_codes);
|
||||
$this->assertContains('dk', $country_codes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +54,7 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
$this->assertNotNull($retrieved_country, 'Product has not country!');
|
||||
|
||||
$this->assertEquals($retrieved_country['name'], $this->current_country, 'Retrieved product country is incorrect!');
|
||||
$this->assertEquals($retrieved_country['code'], $this->current_country, 'Retrieved product country is incorrect!');
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +66,7 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
$this->assertNotNull($retrieved_country, 'Package has not country!');
|
||||
|
||||
$this->assertEquals($retrieved_country['name'], $this->current_country, 'Retrieved package country is incorrect!');
|
||||
$this->assertEquals($retrieved_country['code'], $this->current_country, 'Retrieved package country is incorrect!');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
var $customer_id, $customer_organization_id, $customer_organization_name, $order_id;
|
||||
var $customer_id, $customer_organization_id, $customer_organization_name, $order;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
@@ -23,26 +23,15 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
||||
$this->customer_organization_name = 'test-customer-organization';
|
||||
|
||||
# create customer organization
|
||||
$this->customer_organization_id = wp_insert_term(
|
||||
$this->customer_organization_name,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME
|
||||
)['term_id'];
|
||||
$this->customer_organization_id = $this->factory->organization->create_new_organization(
|
||||
array( 'name' => $this->customer_organization_name )
|
||||
);
|
||||
|
||||
update_user_meta($this->customer_id, '_wiaas_organization_id', $this->customer_organization_id);
|
||||
|
||||
# add customer to organization
|
||||
wp_set_terms_for_user(
|
||||
$this->customer_id,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||
[$this->customer_organization_name]);
|
||||
$this->factory->organization->assign_user_to_organization($this->customer_id, $this->customer_organization_id);
|
||||
|
||||
wp_set_current_user($this->customer_id);
|
||||
|
||||
$order = wc_create_order(array(
|
||||
'customer_id' => $this->customer_id
|
||||
));
|
||||
|
||||
$this->order_id = $order->get_id();
|
||||
$this->order = $this->factory->order->create_new_order();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
@@ -57,46 +46,6 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
||||
Wiaas_User_Organization::TAXONOMY_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Order::assign_order_to_organization()
|
||||
*/
|
||||
function test_order_assigned_to_customer_organization() {
|
||||
|
||||
$organization_access_group = Groups_Group::read_by_name($this->customer_organization_name);
|
||||
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order_id );
|
||||
|
||||
$this->assertEquals(1, count($access_group_ids));
|
||||
$this->assertNotNull($access_group_ids[0]);
|
||||
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Order::check_order_access()
|
||||
*/
|
||||
function test_order_customer_can_access_order() {
|
||||
|
||||
$has_access = Wiaas_Order::check_order_access(true, 'view', $this->order_id, 'shop_order');
|
||||
|
||||
$this->assertTrue($has_access);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Order::check_order_access()
|
||||
*/
|
||||
function test_customer_cannot_access_order_when_not_in_organization() {
|
||||
$customer_id = wc_create_new_customer(
|
||||
'test_customer1@mail.com',
|
||||
'test_customer1',
|
||||
'test1');
|
||||
wp_set_current_user($customer_id);
|
||||
|
||||
$this->assertTrue(Groups_Post_Access::handles_post_type('shop_order'));
|
||||
|
||||
$has_access = Wiaas_Order::check_order_access(true, 'view', $this->order_id, 'shop_order');
|
||||
|
||||
$this->assertFalse($has_access);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Order::wiaas_prepare_rest_orders_query()
|
||||
*/
|
||||
@@ -139,10 +88,12 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
||||
'line_items' => array()
|
||||
);
|
||||
|
||||
$this->factory->order->add_customer_organization_info($this->order, $this->customer_organization_id);
|
||||
|
||||
$order_rest_response = Wiaas_Order::transform_rest_order(
|
||||
new WP_REST_Response($order_response),
|
||||
wc_get_order($this->order_id),
|
||||
array( 'id' => $this->order_id));
|
||||
$this->order,
|
||||
array( 'id' => $this->order->get_id() ));
|
||||
|
||||
$transformed_order_response = $order_rest_response->get_data();
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -19,11 +19,10 @@ class Wiaas_Templates_Test extends Wiaas_Unit_Test_Case {
|
||||
);
|
||||
|
||||
$this->template = $this->create_new_wiaas_template();
|
||||
$this->product = $this->create_new_product();
|
||||
$this->package = $this->create_new_package();
|
||||
$this->add_products_to_package($this->package, $this->product);
|
||||
|
||||
|
||||
$this->product = $this->factory->product->create_simple_product();
|
||||
$this->package = $this->factory->product->create_product_bundle(array(
|
||||
'products' => $this->product
|
||||
));
|
||||
}
|
||||
|
||||
public function test_template_category_taxonomy_created() {
|
||||
|
||||
@@ -22,28 +22,18 @@ class Wiaas_User_Organization_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
$this->user_department_name = 'test_department';
|
||||
|
||||
# create organization
|
||||
$this->user_organization_id = wp_insert_term(
|
||||
$this->user_organization_name,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME
|
||||
)['term_id'];
|
||||
// create organization
|
||||
$this->user_organization_id = $this->factory->organization->create_new_organization(
|
||||
array( 'name' => $this->user_organization_name )
|
||||
);
|
||||
|
||||
update_user_meta($this->user_id, '_wiaas_organization_id', $this->user_organization_id);
|
||||
// create department
|
||||
$this->user_department_id = $this->factory->organization->create_new_organization(
|
||||
array( 'name' => $this->user_department_name, 'parent_id' => $this->user_organization_id )
|
||||
);
|
||||
|
||||
# create department
|
||||
$this->user_department_id = wp_insert_term(
|
||||
$this->user_department_name,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||
array(
|
||||
'parent' => $this->user_organization_id
|
||||
)
|
||||
)['term_id'];
|
||||
|
||||
# assign user to organization
|
||||
wp_set_terms_for_user(
|
||||
$this->user_id,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||
[$this->user_organization_name]);
|
||||
// assign user to organization
|
||||
$this->factory->organization->assign_user_to_organization($this->user_id, $this->user_organization_id);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
@@ -53,12 +43,7 @@ class Wiaas_User_Organization_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
wp_delete_user($this->user_id);
|
||||
|
||||
wp_delete_term(
|
||||
$this->user_organization_id,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME);
|
||||
wp_delete_term(
|
||||
$this->user_department_id,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME);
|
||||
$this->factory->organization->delete_organizations();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user