order_id = $order->get_id(); wp_set_current_user(1); } /** * @covers Wiass_REST_Delivery_Process_API::get_next_actions_for_user */ function test_get_next_actions_for_user() { wp_set_current_user(1); $response = Wiass_REST_Delivery_Process_API::get_next_actions_for_user(); $this->assertNotNull($response); $this->assertInstanceOf('WP_REST_Response', $response); $next_steps = $response->get_data(); $this->assertNotNull($next_steps); $this->assertTrue(is_array($next_steps)); $pending_step = $next_steps[0]; $this->assertTrue(is_array($pending_step)); $this->assertArrayHasKey('order_id', $pending_step); $this->assertArrayHasKey('order_number', $pending_step); $this->assertArrayHasKey('status', $pending_step); $this->assertArrayHasKey('step_action', $pending_step); $this->assertEquals($pending_step['order_id'], $this->order_id); $this->assertEquals($pending_step['order_number'], $this->order_id); $this->assertEquals($pending_step['status'], 'pending'); $this->assertNotEmpty($pending_step['step_action']); } /** * @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance */ function test_get_customer_acceptance_as_guest() { wp_set_current_user(0); $response = Wiass_REST_Delivery_Process_API::get_customer_acceptance(NULL); $this->assertNotNull($response); $this->assertInstanceOf('WP_REST_Response',$response); $this->assertTrue($response->is_error()); $this->assertEquals($response->get_status(), 401); $error_data = $response->as_error(); $this->assertEquals($error_data->get_error_message(), 'You don\'t have permission to read this entry'); } /** * @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance */ function test_get_nonexisting_customer_acceptance() { wp_set_current_user(1); $data['entry_id'] = 101; $response = Wiass_REST_Delivery_Process_API::get_customer_acceptance($data); $this->assertNotNull($response); $this->assertInstanceOf('WP_REST_Response',$response); $this->assertTrue($response->is_error()); $this->assertEquals($response->get_status(), 404); $error_data = $response->as_error(); $this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found'); } /** * @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance */ function test_get_valid_customer_acceptance() { wp_set_current_user(1); // create customer acceptance entry $customer_acceptance_form_id = 1; $customer_id_field_id = 2; $actual_date_field_id = 6; $acceptance_status_field_id = 8; $expiration_date_field_id = 9; $decline_reason_field_id = 10; $files_uploaded_field_id = 12; $input_values['input_' . $acceptance_status_field_id] = 'accept'; $input_values['input_' . $expiration_date_field_id] = "2020-01-01"; //$input_values['input_' . $files_uploaded_field_id] = json_encode(['http://path/to/file1.docx']); GFAPI::submit_form($customer_acceptance_form_id, $input_values); //this part is needed since form submit does not store files for some reason, probably files should be sent some other way $entry = GFAPI::get_entries($customer_acceptance_form_id)[0]; $data['entry_id'] = $entry['id']; $entry[$files_uploaded_field_id] = json_encode(['http://path/to/file1.docx']); $update = GFAPI::update_entry($entry); $response = Wiass_REST_Delivery_Process_API::get_customer_acceptance($data); $this->assertNotNull($response); $this->assertInstanceOf('WP_REST_Response',$response); $this->assertFalse($response->is_error()); $this->assertEquals($response->get_status(), 200); $response_data = $response->get_data(); $this->assertTrue(is_array($response_data)); $this->assertArrayHasKey('documents', $response_data); $this->assertArrayHasKey('expiration', $response_data); $this->assertArrayHasKey('status', $response_data); $this->assertArrayHasKey('decline_reason', $response_data); $this->assertTrue(is_array($response_data['documents'])); $uploaded_file = $response_data['documents'][0]; $this->assertTrue(is_array($uploaded_file)); $this->assertArrayHasKey('name', $uploaded_file); $this->assertArrayHasKey('extension', $uploaded_file); $this->assertArrayHasKey('url', $uploaded_file); $this->assertEquals($uploaded_file['name'], 'file1'); $this->assertEquals($uploaded_file['extension'], 'docx'); $this->assertEquals($uploaded_file['url'], 'http://path/to/file1.docx'); $this->assertEquals($response_data['status'], 1); //1 means accept $this->assertEquals($response_data['expiration'], "2020-01-01"); } /** * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance */ function test_submit_customer_acceptance_as_guest() { wp_set_current_user(0); $response = Wiass_REST_Delivery_Process_API::submit_customer_acceptance(NULL); $this->assertNotNull($response); $this->assertInstanceOf('WP_REST_Response',$response); $this->assertTrue($response->is_error()); $this->assertEquals($response->get_status(), 401); $error_data = $response->as_error(); $this->assertEquals($error_data->get_error_message(), 'You don\'t have permission to update this entry'); } /** * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance */ function test_submit_nonexisting_customer_acceptance() { wp_set_current_user(1); $data['entry_id'] = 101; $response = Wiass_REST_Delivery_Process_API::submit_customer_acceptance($data); $this->assertNotNull($response); $this->assertInstanceOf('WP_REST_Response',$response); $this->assertTrue($response->is_error()); $this->assertEquals($response->get_status(), 404); $error_data = $response->as_error(); $this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found'); } /** * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance */ function test_submit_customer_acceptance_with_accept_status() { wp_set_current_user(1); $data['entry_id'] = 101; $response = Wiass_REST_Delivery_Process_API::submit_customer_acceptance($data); $this->assertNotNull($response); $this->assertInstanceOf('WP_REST_Response',$response); $this->assertTrue($response->is_error()); $this->assertEquals($response->get_status(), 404); $error_data = $response->as_error(); $this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found'); } private function create_customer_acceptance_entry(){ $customer_acceptance_form_id = 1; $customer_id_field_id = 2; $actual_date_field_id = 6; $acceptance_status_field_id = 8; $expiration_date_field_id = 9; $decline_reason_field_id = 10; $files_uploaded_field_id = 12; $input_values['input_' . $acceptance_status_field_id] = 'accept'; $input_values['input_' . $expiration_date_field_id] = "2020-01-01"; //$input_values['input_' . $files_uploaded_field_id] = json_encode(['http://path/to/file1.docx']); GFAPI::submit_form($customer_acceptance_form_id, $input_values); //this part is needed since form submit does not store files for some reason, probably files should be sent some other way $entry = GFAPI::get_entries($customer_acceptance_form_id)[0]; $data['entry_id'] = $entry['id']; $entry[$files_uploaded_field_id] = json_encode(['http://path/to/file1.docx']); $update = GFAPI::update_entry($entry); $response = Wiass_REST_Delivery_Process_API::get_customer_acceptance($data); } }