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

@@ -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();