diff --git a/tests/unit-tests/account/permissions.php b/tests/unit-tests/account/permissions.php new file mode 100644 index 00000000000..8b2285dd916 --- /dev/null +++ b/tests/unit-tests/account/permissions.php @@ -0,0 +1,69 @@ +get_id() ); + $this->assertEquals( true, current_user_can( 'pay_for_order', $order->get_id() ) ); + } + + /** + * Test that guest orders can be paid when not logged in. + */ + public function test_wc_guest_pay_guest_order() { + $order = WC_Helper_Order::create_order( 0 ); + $this->assertEquals( true, current_user_can( 'pay_for_order', $order->get_id() ) ); + } + + /** + * Test that a customer cannot pay another customer's order. + */ + public function test_wc_customer_cannot_pay_another_customer_order() { + $customer1 = WC_Helper_Customer::create_customer(); + $order = WC_Helper_Order::create_order( $customer1->get_id() ); + $customer2 = WC_Helper_Customer::create_customer( 'testcustomer2', 'woo', 'test2@local.woo' ); + wp_set_current_user( $customer2->get_id() ); + $this->assertEquals( false, current_user_can( 'pay_for_order', $order->get_id() ) ); + } + + /** + * Test that customer can pay their own order. + */ + public function test_wc_customer_can_pay_their_order() { + $customer = WC_Helper_Customer::create_customer(); + wp_set_current_user( $customer->get_id() ); + $order = WC_Helper_Order::create_order( $customer->get_id() ); + $this->assertEquals( true, current_user_can( 'pay_for_order', $order->get_id() ) ); + } + +}