public function test_insert_cart() { $data = array('customer_id' => 1, 'item_id' => 2); $_POST = $data; $expected = TRUE; $Cart_model = new Cart_model(); $list = $Cart_model->insert_cart(); $actual = $list['status']; $this->assertEquals($expected, $actual); }
public function save() { header("Access-Control-Allow-Origin: *"); header("Content-Type: application/json; charset=UTF-8"); $Cart_model = new Cart_model(); if ($this->_detect_method() == 'post') { $result = $Cart_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')); } }
public function add_put() { $Cart_model = new Cart_model(); if ($this->_detect_method() == 'put') { $result = $Cart_model->insert_cart(); if ($result['status'] === FALSE) { $this->response(['status' => FALSE, 'message' => 'Could not save the item into cart'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code } else { $this->response(['status' => TRUE, 'id' => $result['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 } }
function __construct() { Cart_model::__construct(); }