From a13b51e02cc56650d41f060fcf14308aa13aee30 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 13 Apr 2016 08:41:09 +0200 Subject: [PATCH] Tests --- application/config/autoload.php | 6 +- application/controllers/api/v1/Person.php | 287 +++++++++++---------- application/models/person/Person_model.php | 11 +- tests/codeception/api/LoginCept.php | 4 +- 4 files changed, 158 insertions(+), 150 deletions(-) diff --git a/application/config/autoload.php b/application/config/autoload.php index 2ddafebad..dd66c13b6 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -60,11 +60,7 @@ $autoload['packages'] = array(); */ //$autoload['libraries'] = array(); -$autoload['libraries'] = array('session', 'Fhcauth'); - -//$autoload['libraries'] = array(); -$autoload['libraries'] = array('session'); - +$autoload['libraries'] = array('Session', 'FHC_Auth'); /* | ------------------------------------------------------------------- diff --git a/application/controllers/api/v1/Person.php b/application/controllers/api/v1/Person.php index 0ac0ba638..b74bbce59 100644 --- a/application/controllers/api/v1/Person.php +++ b/application/controllers/api/v1/Person.php @@ -15,7 +15,7 @@ defined('BASEPATH') || exit('No direct script access allowed'); -class Person extends REST_Controller +class Person extends APIv1_Controller { //public $session; @@ -24,181 +24,184 @@ class Person extends REST_Controller */ public function __construct() { - parent::__construct(); + parent::__construct(); - $this->load->model('person/person_model'); + $this->load->model('person/person_model'); } public function person_get() { - //if (!$this->session_model->validate($this->get('session_id'), $this->get('device_id'))) - // $this->response(array(['success' => false, 'message' => 'access denied']), REST_Controller::HTTP_UNAUTHORIZED); + //if (!$this->session_model->validate($this->get('session_id'), $this->get('device_id'))) + // $this->response(array(['success' => false, 'message' => 'access denied']), REST_Controller::HTTP_UNAUTHORIZED); - $code = $this->get('code'); - $email = $this->get('email'); - $person_id = $this->get('person_id'); + $code = $this->get('code'); + $email = $this->get('email'); + $person_id = $this->get('person_id'); - if ((!is_null($code)) && (!is_null($email))) - { - $result = $this->person_model->getPersonByCodeAndEmail($code, $email); - } - elseif (!is_null($person_id)) - { - $result = $this->person_model->getPerson($person_id); - } - else - { - $result = $this->person_model->getPerson(); - } + if ((!is_null($code)) && (!is_null($email))) + { + $result = $this->person_model->getPersonByCodeAndEmail($code, $email); + } + elseif (! is_null($code)) + { + $result = $this->person_model->getPersonByCode($code, $email); + } + elseif (!is_null($person_id)) + { + $result = $this->person_model->getPerson($person_id); + } + else + { + $result = $this->person_model->getPerson(); + } - if (empty($result)) - { - $payload = [ - 'success' => false, - 'message' => 'Person not found' - ]; - $httpstatus = REST_Controller::HTTP_OK; - } - else - { - // return all available persons - $payload = [ - 'success' => true, - 'message' => 'Persons found' - ]; - $payload['data'] = $result; - $httpstatus = REST_Controller::HTTP_OK; - } + if (empty($result)) + { + $payload = [ + 'success' => false, + 'message' => 'Person not found' + ]; + $httpstatus = REST_Controller::HTTP_OK; + } + else + { + // return all available persons + $payload = [ + 'success' => true, + 'message' => 'Persons found' + ]; + $payload['data'] = $result; + $httpstatus = REST_Controller::HTTP_OK; + } - // Set the response and exit - $this->response($payload, $httpstatus); + // Set the response and exit + $this->response($payload, $httpstatus); } public function personFromCode_post() { - $code = $this->post('code'); - $email = $this->post('email'); - $person_id = $this->post('person_id'); + $code = $this->post('code'); + $email = $this->post('email'); + $person_id = $this->post('person_id'); - if ((!is_null($code)) && (!is_null($email))) - { - $result = $this->person_model->getPersonByCodeAndEmail($code, $email); - } - elseif (!is_null($person_id)) - { - $result = $this->person_model->getPerson($person_id); - } - else - { - $result = $this->person_model->getPerson(); - } + if ((!is_null($code)) && (!is_null($email))) + { + $result = $this->person_model->getPersonByCodeAndEmail($code, $email); + } + elseif (!is_null($person_id)) + { + $result = $this->person_model->getPerson($person_id); + } + else + { + $result = $this->person_model->getPerson(); + } - if (empty($result)) - { - $payload = [ - 'success' => false, - 'message' => 'Person not found' - ]; - $httpstatus = REST_Controller::HTTP_OK; - } - else - { - // return all available persons - $payload = [ - 'success' => true, - 'message' => 'Persons found' - ]; - $payload['data'] = $result; - $httpstatus = REST_Controller::HTTP_OK; - } + if (empty($result)) + { + $payload = [ + 'success' => false, + 'message' => 'Person not found' + ]; + $httpstatus = REST_Controller::HTTP_OK; + } + else + { + // return all available persons + $payload = [ + 'success' => true, + 'message' => 'Persons found' + ]; + $payload['data'] = $result; + $httpstatus = REST_Controller::HTTP_OK; + } - // Set the response and exit - $this->response($payload, $httpstatus); + // Set the response and exit + $this->response($payload, $httpstatus); } public function person_post() { - $result = $this->person_model->savePerson($this->post()); - if($result != FALSE) - { - $httpstatus = REST_Controller::HTTP_OK; - $payload = [ - 'success' => true, - 'message' => 'Person saved.' - ]; - $payload['data'] = $result; - } - else - { - $payload = [ - 'success' => false, - 'message' => 'Could not save person.' - ]; - $httpstatus = REST_Controller::HTTP_OK; - } + $result = $this->person_model->savePerson($this->post()); + if($result != FALSE) + { + $httpstatus = REST_Controller::HTTP_OK; + $payload = [ + 'success' => true, + 'message' => 'Person saved.' + ]; + $payload['data'] = $result; + } + else + { + $payload = [ + 'success' => false, + 'message' => 'Could not save person.' + ]; + $httpstatus = REST_Controller::HTTP_OK; + } - $this->response($payload, $httpstatus); + $this->response($payload, $httpstatus); } public function personUpdate_post() { - $result = $this->person_model->updatePerson($this->post()); - if($result != FALSE) - { - $httpstatus = REST_Controller::HTTP_OK; - $payload = [ - 'success' => true, - 'message' => 'Person updated.' - ]; - $payload['data'] = $result; - } - else - { - $payload = [ - 'success' => false, - 'message' => 'Could not update person.' - ]; - $httpstatus = REST_Controller::HTTP_OK; - } -// - $this->response($payload, $httpstatus); + $result = $this->person_model->updatePerson($this->post()); + if($result != FALSE) + { + $httpstatus = REST_Controller::HTTP_OK; + $payload = [ + 'success' => true, + 'message' => 'Person updated.' + ]; + $payload['data'] = $result; + } + else + { + $payload = [ + 'success' => false, + 'message' => 'Could not update person.' + ]; + $httpstatus = REST_Controller::HTTP_OK; + } + // + $this->response($payload, $httpstatus); } public function checkBewerbung_get() { - $result = $this->person_model->checkBewerbung($this->get("email"),$this->get("studiensemester_kurzbz")); - $httpstatus = REST_Controller::HTTP_OK; - $payload = [ - 'success' => true, - 'message' => 'Bewerbung exists.' - ]; - $payload['data'] = $result; + $result = $this->person_model->checkBewerbung($this->get("email"),$this->get("studiensemester_kurzbz")); + $httpstatus = REST_Controller::HTTP_OK; + $payload = [ + 'success' => true, + 'message' => 'Bewerbung exists.' + ]; + $payload['data'] = $result; - $this->response($payload, $httpstatus); + $this->response($payload, $httpstatus); } public function checkZugangscodePerson_get() { - $result = $this->person_model->checkZugangscodePerson($this->get("code")); - $httpstatus = REST_Controller::HTTP_OK; - if(!empty($result)) - { - $payload = [ - 'success' => true, - 'message' => 'Zugangscode exists.' - ]; - $payload['data'] = $result; - } - else - { - $payload = [ - 'success' => false, - 'message' => 'Zugangscode does not exist.' - ]; - $httpstatus = REST_Controller::HTTP_OK; - } + $result = $this->person_model->checkZugangscodePerson($this->get("code")); + $httpstatus = REST_Controller::HTTP_OK; + if(!empty($result)) + { + $payload = [ + 'success' => true, + 'message' => 'Zugangscode exists.' + ]; + $payload['data'] = $result; + } + else + { + $payload = [ + 'success' => false, + 'message' => 'Zugangscode does not exist.' + ]; + $httpstatus = REST_Controller::HTTP_OK; + } - $this->response($payload, $httpstatus); + $this->response($payload, $httpstatus); } - } diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 827f48c84..1cfe356a9 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -30,8 +30,15 @@ class Person_model extends DB_Model ->where("k.kontakt", $email); return $this->db->get()->result_object(); -// $query = $this->db->get_where('public.tbl_person p ', array('zugangscode' => $code)); -// return $query->result_object(); +// } + } + + public function getPersonByCode($code) + { +// if ($this->fhc_db_acl->bb->isBerechtigt('person', 'suid')) +// { + $query = $this->db->get_where('public.tbl_person', array('zugangscode' => $code)); + return $query->result_object(); // } } diff --git a/tests/codeception/api/LoginCept.php b/tests/codeception/api/LoginCept.php index bd04cda0c..4cce862cf 100644 --- a/tests/codeception/api/LoginCept.php +++ b/tests/codeception/api/LoginCept.php @@ -3,7 +3,9 @@ $I = new ApiTester($scenario); $I->wantTo('test the Login API'); $I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); -$I->sendGET('AuthAPI/login?username=pam&password=1q2w3&FHC-API-KEY=testapikey@fhcomplete.org'); +//$I->haveHttpHeader('username', 'testapikey@fhcomplete.org'); +//$I->haveHttpHeader('password', 'testapikey@fhcomplete.org'); +$I->sendPOST('AuthAPI/login?username=admin&password=1q2w3'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson([