/**
  * Toggles whether the user is checked in or not.
  *
  * @param \WP_REST_Request $request
  * @return \WP_Error|\WP_REST_Response
  */
 protected function _create_checkin_checkout_object(\WP_REST_Request $request)
 {
     $reg_id = $request->get_param('REG_ID');
     $dtt_id = $request->get_param('DTT_ID');
     $force = $request->get_param('force');
     if ($force == 'true') {
         $force = true;
     } else {
         $force = false;
     }
     $reg = \EEM_Registration::instance()->get_one_by_ID($reg_id);
     if (!$reg instanceof \EE_Registration) {
         return $this->send_response(new \WP_Error('rest_registration_toggle_checkin_invalid_id', sprintf(__('You cannot checkin registration with ID %1$s because it doesn\'t exist.', 'event_espresso'), $reg_id), array('status' => 422)));
     }
     if (!\EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
         return $this->send_response(new \WP_Error('rest_user_cannot_toggle_checkin', sprintf(__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), $reg_id), array('status' => 403)));
     }
     $success = $reg->toggle_checkin_status($dtt_id, !$force);
     if ($success === false) {
         //rely on EE_Error::add_error messages to have been added to give more data about hwy it failed
         return $this->send_response(new \WP_Error('rest_toggle_checkin_failed', __('Registration checkin failed. Please see additional error data.', 'event_espresso')));
     }
     $checkin = \EEM_Checkin::instance()->get_one(array(array('REG_ID' => $reg_id, 'DTT_ID' => $dtt_id), 'order_by' => array('CHK_timestamp' => 'DESC')));
     if (!$checkin instanceof \EE_Checkin) {
         return $this->send_response(new \WP_Error('rest_toggle_checkin_error', sprintf(__('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', 'event_espresso'), $reg_id, $dtt_id)));
     }
     $requested_version = $this->get_requested_version($request->get_route());
     $get_request = new \WP_REST_Request('GET', \EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID());
     $get_request->set_url_params(array('id' => $checkin->ID()));
     return Read::handle_request_get_one($get_request);
 }
 /**
  * Test getting published items.
  */
 function test_get_collection_published()
 {
     wp_set_current_user($this->factory()->user->create(array('role' => 'administrator')));
     $request = new \WP_REST_Request('GET', '/wp/v2/customize_snapshots');
     $request->set_param('context', 'edit');
     $response = $this->server->dispatch($request);
     $this->assertEquals(200, $response->get_status());
     $items = $response->get_data();
     $this->assertCount(1, $items);
     $this->assertEquals('publish', $items[0]['status']);
     $this->assertArrayHasKey('content', $items[0]);
     $this->assertArrayHasKey('blogname', $items[0]['content']);
     $this->assertArrayHasKey('value', $items[0]['content']['blogname']);
     $request = new \WP_REST_Request('GET', '/wp/v2/customize_snapshots');
     $request->set_param('context', 'edit');
     $request->set_url_params(array('status' => 'publish'));
     $response = $this->server->dispatch($request);
     $this->assertEquals($items, $response->get_data());
 }
 public function test_handle_request_get_one__cannot_access()
 {
     $e = $this->new_model_obj_with_dependencies('Event', array('status' => 'draft'));
     $req = new \WP_REST_Request('GET', \EED_Core_Rest_Api::ee_api_namespace . '4.8.29/events/' . $e->ID());
     $req->set_url_params(array('id' => $e->ID()));
     $response = Read::handle_request_get_one($req);
     $this->assertInstanceOf('WP_REST_Response', $response);
     $this->assertEquals(403, $response->get_status());
 }