public function test_update_item() { $data = array('id' => 3, 'name' => "Iphone", 'description' => "This is test data from Unit test update", 'price' => 3); $_POST = $data; $expected = TRUE; $Item_model = new Item_model(); $list = $Item_model->update_item(); $actual = $list['status']; $this->assertEquals($expected, $actual); }
public function save() { header("Access-Control-Allow-Origin: *"); header("Content-Type: application/json; charset=UTF-8"); $Item_model = new Item_model(); if ($this->_detect_method() == 'post') { if (isset($_POST['id'])) { $result = $Item_model->update_item(); } else { $result = $Item_model->insert_item(); } if ($result['status'] === FALSE) { print json_encode(array('status' => 'failed', 'error' => 'data error')); } else { print json_encode(array('id' => $result['status'], 'status' => 'success')); } } else { print json_encode(array('status' => 'failed', 'error' => 'Nothing Post')); } }
/** * Insert a item record into the database * * @access public * @return void */ public function lists_post() { $Item_model = new Item_model(); if ($this->_detect_method() == 'post') { if (isset($_POST['id'])) { $lists = $Item_model->update_item(); } else { $lists = $Item_model->insert_item(); } if ($lists['status'] === FALSE) { $this->response(['status' => FALSE, 'message' => 'Could not save the item'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code } else { $this->response(['status' => TRUE, 'id' => $lists['id']], REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code } } else { $this->response(['status' => FALSE, 'message' => 'Nothing Post'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code } }