From cbd23a0925313ea98b55652530d47b5eb5b745c7 Mon Sep 17 00:00:00 2001 From: Reynold Tan Date: Fri, 29 Jan 2021 13:03:45 -0600 Subject: [PATCH] Creates unit test for trials call --- .../trials/TripalWebServiceBrapiV1Trials.inc | 10 ++- tests/calls-v.13/trialsCallTest.php | 83 +++++++++++++++++++ 2 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 tests/calls-v.13/trialsCallTest.php diff --git a/calls/v1/trials/TripalWebServiceBrapiV1Trials.inc b/calls/v1/trials/TripalWebServiceBrapiV1Trials.inc index 27a3aa8..b077cb7 100644 --- a/calls/v1/trials/TripalWebServiceBrapiV1Trials.inc +++ b/calls/v1/trials/TripalWebServiceBrapiV1Trials.inc @@ -136,7 +136,7 @@ class TripalWebServiceBrapiV1Trials extends TripalWebServiceDatabaseCall { if (isset($call_asset['parameter']['programDbId']) && !empty($call_asset['parameter']['programDbId'])) { - $filter[] = 'category.projectprop_id = :programDbId'; + $filter[] = 'program.project_id = :programDbId'; $args[':programDbId'] = $call_asset['parameter']['programDbId']; } @@ -181,8 +181,10 @@ class TripalWebServiceBrapiV1Trials extends TripalWebServiceDatabaseCall { LEFT JOIN {project_relationship} AS category ON project.project_id = category.subject_project_id AND category.type_id = %d LEFT JOIN {project} AS program ON category.object_project_id = program.project_id - WHERE is_research_area.value::int = 0 OR is_research_area.value IS NULL %s - %s + WHERE + project.project_id IN (SELECT project_id FROM {phenotype} GROUP BY project_id) AND + is_research_area.value::int = 0 OR is_research_area.value IS NULL %s + %s LIMIT %d OFFSET %d "; @@ -233,7 +235,7 @@ class TripalWebServiceBrapiV1Trials extends TripalWebServiceDatabaseCall { } } - $project->studies = [ $all_studies ]; + $project->studies = (array) ['set' => $all_studies]; // Dates (year range). if (preg_match('/^[0-9]{4}-{1}[0-9]{4}$/', $project->startdate)) { diff --git a/tests/calls-v.13/trialsCallTest.php b/tests/calls-v.13/trialsCallTest.php new file mode 100644 index 0000000..dbc4392 --- /dev/null +++ b/tests/calls-v.13/trialsCallTest.php @@ -0,0 +1,83 @@ + valuetype | array. + * Valid valuetypes are: string, integer, object, array. + */ + public $data_structure = [ + 'active' => 'string', + 'additionalInfo' => 'object', + 'commonCropName' => 'string', + 'documentationURL' => 'string', + 'programDbId' => 'string', + 'programName' => 'string', + 'studies' => 'array', + 'trialDbId' => 'string', + 'trialName' => 'string', + 'endDate' => 'string', + 'startDate' => 'string', + ]; + + /** + * CORE TEST. + */ + public function testCall() { + + //--------------------------------- + // 1. NO PARAMETERS. + $response = NULL; + $this->assertWithNoParameters($response); + $numOfResults = sizeof($response->result->data); + + //--------------------------------- + // 2. WITH PARAMETERS: pageSize + $response = NULL; + $this->assertPageSize($response, $numOfResults); + $page1_results = $response->result->data; + + //--------------------------------- + // 3. WITH PARAMETERS: page, pageSize + $response = NULL; + $this->assertPaging($response, $numOfResults, $page1_results); + + //--------------------------------- + // 4. WITH PARAMETERS: commonCropName + $response = NULL; + $this->assertWithParameter($response, [ + 'name' => 'commonCropName', // Parameter name. + 'key' => 'commonCropName', // The response key the parameter name will match. + 'value' => 'Brapus', // Parameter value + ]); + + //--------------------------------- + // 5. WITH PARAMETERS: programDbId + $response = NULL; + $this->assertWithParameter($response, [ + 'name' => 'programDbId', // Parameter name. + 'key' => 'programDbId', // The response key the parameter name will match. + 'value' => '', // Pick one. + ], TRUE); + } +}