diff --git a/application/controllers/api/v1/person/Person.php b/application/controllers/api/v1/person/Person.php index a75981a32..7c095301d 100644 --- a/application/controllers/api/v1/person/Person.php +++ b/application/controllers/api/v1/person/Person.php @@ -39,11 +39,11 @@ class Person extends REST_Controller $result = $this->PersonModel->getPerson($personID, $code, $email); - if(is_object($result)) + if(is_object($result) && $result->num_rows() > 0) { $payload = [ 'success' => TRUE, - 'message' => 'People found', + 'message' => 'Person found', 'data' => $result->result() ]; $httpstatus = REST_Controller::HTTP_OK; diff --git a/application/controllers/api/v1/studies/Course.php b/application/controllers/api/v1/studies/Course.php index 36b911a8a..e69a40887 100644 --- a/application/controllers/api/v1/studies/Course.php +++ b/application/controllers/api/v1/studies/Course.php @@ -32,7 +32,7 @@ class Course extends REST_Controller { $result = $this->CourseModel->getEnabledCourses(); - if(is_object($result)) + if(is_object($result) && $result->num_rows() > 0) { $payload = [ 'success' => TRUE, diff --git a/application/controllers/api/v1/studies/Plan.php b/application/controllers/api/v1/studies/Plan.php index b25d502cf..25a4b9fe5 100644 --- a/application/controllers/api/v1/studies/Plan.php +++ b/application/controllers/api/v1/studies/Plan.php @@ -28,17 +28,17 @@ class Plan extends REST_Controller $this->PlanModel->setAddonID($this->_getAddonID()); } - public function getCurricula() + public function getPlan() { $courseOfStudiesID = $this->get('studiengang_kz'); - $result = $this->PlanModel->getCurricula($courseOfStudiesID); + $result = $this->PlanModel->getPlan($courseOfStudiesID); - if(is_object($result)) + if(is_object($result) && $result->num_rows() > 0) { $payload = [ 'success' => TRUE, - 'message' => 'Curricula found', + 'message' => 'Plan found', 'data' => $result->result() ]; $httpstatus = REST_Controller::HTTP_OK; @@ -47,7 +47,7 @@ class Plan extends REST_Controller { $payload = [ 'success' => FALSE, - 'message' => 'Curricula not found' + 'message' => 'Plan not found' ]; $httpstatus = REST_Controller::HTTP_OK; } diff --git a/application/models/studies/Plan_model.php b/application/models/studies/Plan_model.php index e1519a8e0..a824fdeb9 100644 --- a/application/models/studies/Plan_model.php +++ b/application/models/studies/Plan_model.php @@ -3,7 +3,7 @@ class Plan_model extends DB_Model { // - protected $_curriculaQuery = "SELECT DISTINCT tbl_studienplan.* + protected $_planQuery = "SELECT DISTINCT tbl_studienplan.* FROM lehre.tbl_studienplan JOIN lehre.tbl_studienordnung USING(studienordnung_id) WHERE tbl_studienordnung.studiengang_kz = ?"; @@ -18,7 +18,7 @@ class Plan_model extends DB_Model /** * */ - public function getCurricula($courseOfStudiesID) + public function getPlan($courseOfStudiesID) { $result = NULL; @@ -26,7 +26,7 @@ class Plan_model extends DB_Model // All the code should be put inside this if statement if($this->_checkPermissions()) { - $result = $this->db->query($this->_curriculaQuery, array($courseOfStudiesID)); + $result = $this->db->query($this->_planQuery, array($courseOfStudiesID)); } return $result; diff --git a/include/studienplan.class.php b/include/studienplan.class.php index d6b605d89..96decc716 100644 --- a/include/studienplan.class.php +++ b/include/studienplan.class.php @@ -729,7 +729,7 @@ class studienplan extends Plan_model */ function getStudienplaene($studiengang_kz) { - $qry = str_replace('?', $this->db_add_param($studiengang_kz, FHC_INTEGER), $this->_curriculaQuery); + $qry = str_replace('?', $this->db_add_param($studiengang_kz, FHC_INTEGER), $this->_planQuery); if($result = $this->db_query($qry)) { diff --git a/tests/codeception/api/BasicLoginCept.php b/tests/codeception/api/BasicLoginCept.php index a131f5050..e4fc46680 100644 --- a/tests/codeception/api/BasicLoginCept.php +++ b/tests/codeception/api/BasicLoginCept.php @@ -2,7 +2,7 @@ $I = new ApiTester($scenario); $I->wantTo('Test the HTTP basic autentication whith HTTP GET and POST method and the API Keys'); -$I->amHttpAuthenticated("aufname", "1q2w3"); +$I->amHttpAuthenticated("wu11e001", "1Q2W3E4R"); $I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); $I->sendGET('Test/test'); $I->seeResponseCodeIs(200); @@ -10,6 +10,7 @@ $I->seeResponseIsJson(); $I->seeResponseContainsJson([ 'success' => true, 'message' => 'API HTTP GET call test succeed']); + $I->sendPOST('Test/test'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); diff --git a/tests/codeception/api/DigestLogin.php b/tests/codeception/api/DigestLogin.php index a873e2b6f..d291681cf 100644 --- a/tests/codeception/api/DigestLogin.php +++ b/tests/codeception/api/DigestLogin.php @@ -3,13 +3,13 @@ $I = new ApiTester($scenario); $I->wantTo('Test the HTTP digest autentication when calling an API'); $I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); -$I->sendGET('v1/Test/test'); +$I->sendGET('Test/test'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson([ 'success' => true, 'message' => 'API HTTP GET call test succeed']); -$I->sendPOST('v1/Test/test'); +$I->sendPOST('Test/test'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson([ diff --git a/tests/codeception/api/v1/CourseCept.php b/tests/codeception/api/v1/CourseCept.php new file mode 100644 index 000000000..1c83a604d --- /dev/null +++ b/tests/codeception/api/v1/CourseCept.php @@ -0,0 +1,12 @@ +wantTo('Test API call v1/studies/course/EnabledCourses'); +$I->amHttpAuthenticated("wu11e001", "1Q2W3E4R"); +$I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); +$I->sendGET('v1/studies/course/EnabledCourses'); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson([ + 'success' => TRUE, + 'message' => 'Courses found']); \ No newline at end of file diff --git a/tests/codeception/api/v1/NationCept.php b/tests/codeception/api/v1/NationCept.php new file mode 100644 index 000000000..4e90ca0a9 --- /dev/null +++ b/tests/codeception/api/v1/NationCept.php @@ -0,0 +1,19 @@ +wantTo('Test API call v1/nation/All'); +$I->amHttpAuthenticated("wu11e001", "1Q2W3E4R"); +$I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); +$I->sendGET('v1/nation/All'); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson([ + 'success' => TRUE, + 'message' => 'Nation found']); + +$I->sendGET('v1/nation/FederalState'); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson([ + 'success' => TRUE, + 'message' => 'Bundesland found']); \ No newline at end of file diff --git a/tests/codeception/api/v1/PersonCept.php b/tests/codeception/api/v1/PersonCept.php new file mode 100644 index 000000000..40c8679c9 --- /dev/null +++ b/tests/codeception/api/v1/PersonCept.php @@ -0,0 +1,26 @@ +wantTo('Test API call v1/person/person/Person by person_id'); +$I->amHttpAuthenticated("wu11e001", "1Q2W3E4R"); +$I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); +$I->sendGET('v1/person/person/Person', array('person_id' => 62788)); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson([ + 'success' => TRUE, + 'message' => 'Person found']); + +$I->sendGET('v1/person/person/Person', array('code' => 'bd94ef5d5a')); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson([ + 'success' => TRUE, + 'message' => 'Person found']); + +$I->sendGET('v1/person/person/Person', array('code' => 'bd94ef5d5a', 'email' => '12351235')); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson([ + 'success' => TRUE, + 'message' => 'Person found']); \ No newline at end of file diff --git a/tests/codeception/api/v1/PlanCept.php b/tests/codeception/api/v1/PlanCept.php new file mode 100644 index 000000000..2a548b3fa --- /dev/null +++ b/tests/codeception/api/v1/PlanCept.php @@ -0,0 +1,12 @@ +wantTo('Test API call v1/studies/plan/Plan'); +$I->amHttpAuthenticated("wu11e001", "1Q2W3E4R"); +$I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); +$I->sendGET('v1/studies/plan/Plan', array('studiengang_kz' => 257)); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson([ + 'success' => TRUE, + 'message' => 'Plan found']); \ No newline at end of file