diff --git a/package.json b/package.json index d5c36fe4cbe..7e3f3f064c2 100644 --- a/package.json +++ b/package.json @@ -19,23 +19,23 @@ }, "devDependencies": { "@babel/cli": "^7.6.4", - "@babel/core": "^7.6.4", + "@babel/core": "^7.11.0", "@babel/plugin-proposal-object-rest-spread": "^7.6.2", "@babel/preset-env": "^7.6.3", "@babel/preset-react": "^7.6.3", - "c3": "^0.7.15", - "d3": "^5.15.0", - "css-loader": "^3.4.2", + "alex": ">=8.0.1", "babel-eslint": "^10.0.1", "babel-loader": "^8.0.5", + "c3": "^0.7.15", + "css-loader": "^3.4.2", + "d3": "^5.15.0", "eslint": "^5.16.0", "eslint-config-google": "0.9.1", "eslint-loader": "^2.2.1", "eslint-plugin-react": "^7.16.0", "terser-webpack-plugin": "^1.3.0", "webpack": "^4.41.2", - "webpack-cli": "^3.3.0", - "alex": ">=8.0.1" + "webpack-cli": "^3.3.0" }, "scripts": { "lint:javascript": "./test/run-js-linter.sh", diff --git a/raisinbread/test/api/LorisApiAuthenticatedTest.php b/raisinbread/test/api/LorisApiAuthenticatedTest.php new file mode 100644 index 00000000000..3a5f7283ee1 --- /dev/null +++ b/raisinbread/test/api/LorisApiAuthenticatedTest.php @@ -0,0 +1,143 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiAuthenticatedTest extends LorisIntegrationTest +{ + + protected $client; + protected $headers; + protected $base_uri; + protected $originalJwtKey; + protected $configIdJwt; + + /** + * Overrides LorisIntegrationTest::setUp() to store the current JWT key + * and replaces it for an acceptable one. + * + * @return void + */ + public function setUp() + { + parent::setUp(); + // store the original JWT key for restoring it later + $jwtConfig = $this->DB->pselect( + ' + SELECT + Value, ConfigID + FROM + Config + WHERE + ConfigID= + (SELECT ID FROM ConfigSettings WHERE Name="JWTKey") + ', + [] + )[0] ?? null; + + if ($jwtConfig === null) { + throw new \LorisException('There is no Config for "JWTKey"'); + } + + $this->originalJwtKey = $jwtConfig['Value']; + $this->configIdJwt = $jwtConfig['ConfigID']; + + // generating a random JWTkey + $new_id = bin2hex(random_bytes(30)) . 'A1!'; + + $set = [ + 'Value' => $new_id + ]; + + $where = [ + 'ConfigID' => $this->configIdJwt + ]; + + $this->DB->update('Config', $set, $where); + + $this->apiLogin('UnitTester', $this->validPassword); + } + + /** + * Used to log in with GuzzleHttp\Client + * + * @param string $username The username to log in as + * @param string $password The (plain text) password to login as. + * + * @return void + */ + public function apiLogin($username, $password) + { + $this->base_uri = "$this->url/api/v0.0.3/"; + $this->client = new Client(['base_uri' => $this->base_uri]); + $response = $this->client->request( + 'POST', + "login", + [ + 'json' => ['username' => $username, + 'password' => $password + ] + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + $token = json_decode( + $response->getBody()->getContents() + )->token ?? null; + + if ($token === null) { + throw new \LorisException("Login failed"); + } + $headers = [ + 'Authorization' => "Bearer $token", + 'Accept' => 'application/json' + ]; + $this->headers = $headers; + } + + /** + * Used to test login + * + * @return void + */ + function testLoginSuccess() + { + $this->assertArrayHasKey('Authorization', $this->headers); + $this->assertArrayHasKey('Accept', $this->headers); + } + + /** + * Overrides LorisIntegrationTest::tearDown() to set the original key back. + * + * @return void + */ + public function tearDown() + { + $set = [ + 'Value' => $this->originalJwtKey + ]; + + $where = [ + 'ConfigID' => $this->configIdJwt + ]; + + $this->DB->update('Config', $set, $where); + parent::tearDown(); + } + +} + diff --git a/raisinbread/test/api/LorisApiCandidatesTest.php b/raisinbread/test/api/LorisApiCandidatesTest.php new file mode 100644 index 00000000000..a81634b5755 --- /dev/null +++ b/raisinbread/test/api/LorisApiCandidatesTest.php @@ -0,0 +1,262 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiCandidatesTest extends LorisApiAuthenticatedTest +{ + protected $candidTest = '300001'; + + /** + * Tests the HTTP GET request for the endpoint /candidates + * + * @return void + */ + public function testGetCandidates(): void + { + $response = $this->client->request( + 'GET', + "candidates", + [ + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $candidatesArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($candidatesArray), + 'array' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']), + 'array' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']), + 'array' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']['CandID']), + 'string' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']['Project']), + 'string' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']['PSCID']), + 'string' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']['Site']), + 'string' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']['EDC']), + 'string' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']['DoB']), + 'string' + ); + $this->assertSame( + gettype($candidatesArray['Candidates']['0']['Sex']), + 'string' + ); + + $this->assertArrayHasKey('Candidates', $candidatesArray); + $this->assertArrayHasKey('0', $candidatesArray['Candidates']); + $this->assertArrayHasKey( + 'CandID', + $candidatesArray['Candidates']['0'] + ); + $this->assertArrayHasKey( + 'Project', + $candidatesArray['Candidates']['0'] + ); + $this->assertArrayHasKey( + 'Site', + $candidatesArray['Candidates']['0'] + ); + $this->assertArrayHasKey( + 'EDC', + $candidatesArray['Candidates']['0'] + ); + $this->assertArrayHasKey( + 'DoB', + $candidatesArray['Candidates']['0'] + ); + $this->assertArrayHasKey( + 'Sex', + $candidatesArray['Candidates']['0'] + ); + } + + /** + * Tests the HTTP GET request for the endpoint /candidates/{candid} + * + * @return void + */ + public function testGetCandidatesCandid(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest", + [ + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $candidatesCandidArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($candidatesCandidArray), + 'array' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']['Project']), + 'string' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']['PSCID']), + 'string' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']['Site']), + 'string' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']['EDC']), + 'string' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']['DoB']), + 'string' + ); + $this->assertSame( + gettype($candidatesCandidArray['Meta']['Sex']), + 'array' + ); + $this->assertSame( + gettype($candidatesCandidArray['Visits']), + 'array' + ); + $this->assertSame( + gettype($candidatesCandidArray['Visits']['0']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $candidatesCandidArray + ); + $this->assertArrayHasKey( + 'Visits', + $candidatesCandidArray + ); + $this->assertArrayHasKey( + '0', + $candidatesCandidArray['Visits'] + ); + + } + + /** + * Tests the HTTP POST request for the endpoint /candidates/{candid} + * + * @return void + */ + public function testPostCandidatesCandid(): void + { + // First, create a valid new candidate + $json_new = [ + 'Candidate' => + [ + 'Project' => "Rye", + 'Site' => "Data Coordinating Center", + 'EDC' => "2020-01-03", + 'DoB' => "2020-01-03", + 'Sex' => "Male" + ] + ]; + $response_new = $this->client->request( + 'POST', + "candidates", + [ + 'headers' => $this->headers, + 'json' => $json_new + ] + ); + // Verify the status code + $this->assertEquals(201, $response_new->getStatusCode()); + // Verify the endpoint has a body + $body = $response_new->getBody(); + $this->assertNotEmpty($body); + + // Finally, try to create a new candidate with an invalid input + $json_invalid = [ + 'Candidate' => + [ + 'Site' => "Data Coordinating Center", + 'EDC' => "2020-01-03", + 'DoB' => "2020-01-03", + 'Sex' => "Male" + ] + ]; + + $response_invalid = $this->client->request( + 'POST', + "candidates", + [ + 'headers' => $this->headers, + 'http_errors' => false, + 'json' => $json_invalid + ], + ); + // Verify the status code + $this->assertEquals(400, $response_invalid->getStatusCode()); + // Verify the endpoint has a body + $body = $response_invalid->getBody(); + $this->assertNotEmpty($body); + } +} diff --git a/raisinbread/test/api/LorisApiDicomsTest.php b/raisinbread/test/api/LorisApiDicomsTest.php new file mode 100644 index 00000000000..773eaa3e381 --- /dev/null +++ b/raisinbread/test/api/LorisApiDicomsTest.php @@ -0,0 +1,210 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiDicomsTest extends LorisApiAuthenticatedTest +{ + protected $candidTest = "400162"; + protected $visitTest = "V6"; + protected $tarfileTest = "DCM_2016-08-15_ImagingUpload-18-25-i9GRv3.tar"; + protected $processidTest = ""; + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/dicoms + * + * @return void + */ + public function testGetCandidatesCandidVisitDicoms(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/dicoms", + [ + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + $dicomArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame(gettype($dicomArray), 'array'); + $this->assertSame(gettype($dicomArray['Meta']), 'array'); + $this->assertSame( + gettype($dicomArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($dicomArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($dicomArray['DicomTars']), + 'array' + ); + $this->assertSame( + gettype($dicomArray['DicomTars']['0']), + 'array' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo'] + ), + 'array' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ), + 'array' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['SeriesDescription'] + ), + 'string' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['SeriesNumber'] + ), + 'integer' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['EchoTime'] + ), + 'string' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['RepetitionTime'] + ), + 'string' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['InversionTime'] + ), + 'NULL' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['1']['InversionTime'] + ), + 'string' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['SliceThickness'] + ), + 'string' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['Modality'] + ), + 'string' + ); + $this->assertSame( + gettype( + $dicomArray['DicomTars']['0']['SeriesInfo']['0']['SeriesUID'] + ), + 'string' + ); + + $this->assertArrayHasKey('Meta', $dicomArray); + $this->assertArrayHasKey('CandID', $dicomArray['Meta']); + $this->assertArrayHasKey('Visit', $dicomArray['Meta']); + + $this->assertArrayHasKey( + 'DicomTars', + $dicomArray + ); + $this->assertArrayHasKey( + '0', + $dicomArray['DicomTars'] + ); + $this->assertArrayHasKey( + 'Tarname', + $dicomArray['DicomTars']['0'] + ); + + $this->assertArrayHasKey( + 'SeriesInfo', + $dicomArray['DicomTars']['0'] + ); + $this->assertArrayHasKey( + '0', + $dicomArray['DicomTars']['0']['SeriesInfo'] + ); + $this->assertArrayHasKey( + 'SeriesDescription', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'SeriesDescription', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'SeriesNumber', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'EchoTime', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'RepetitionTime', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'InversionTime', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'SliceThickness', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'Modality', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + $this->assertArrayHasKey( + 'SeriesUID', + $dicomArray['DicomTars']['0']['SeriesInfo']['0'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/dicoms/tarname + * + * @return void + */ + public function testGetCandidatesCandidVisitDicomsTarname(): void + { + $this->markTestSkipped('Missing data in docker image'); + } +} diff --git a/raisinbread/test/api/LorisApiImagesTest.php b/raisinbread/test/api/LorisApiImagesTest.php new file mode 100644 index 00000000000..da3572625f6 --- /dev/null +++ b/raisinbread/test/api/LorisApiImagesTest.php @@ -0,0 +1,698 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiImagesTest extends LorisApiAuthenticatedTest +{ + protected $candidTest = "676061"; + protected $visitTest = "V4"; + protected $imagefileTest = "demo_676061_V4_t1_001.mnc"; + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images + * + * @return void + */ + public function testGetCandidatesCandidVisitImages(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/images/", + [ + 'headers' => $this->headers, + 'http_errors' => false + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $imagesArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame(gettype($imagesArray), 'array'); + $this->assertSame(gettype($imagesArray['Meta']), 'array'); + $this->assertSame(gettype($imagesArray['Meta']['CandID']), 'string'); + $this->assertSame(gettype($imagesArray['Meta']['Visit']), 'string'); + $this->assertSame(gettype($imagesArray['Files']), 'array'); + $this->assertSame( + gettype($imagesArray['Files']['0']['OutputType']), + 'string' + ); + $this->assertSame( + gettype($imagesArray['Files']['0']['Filename']), + 'string' + ); + $this->assertSame( + gettype($imagesArray['Files']['0']['AcquisitionType']), + 'string' + ); + + $this->assertArrayHasKey('Meta', $imagesArray); + $this->assertArrayHasKey('CandID', $imagesArray['Meta']); + $this->assertArrayHasKey('Visit', $imagesArray['Meta']); + $this->assertArrayHasKey('Files', $imagesArray); + $this->assertArrayHasKey('OutputType', $imagesArray['Files']['0']); + $this->assertArrayHasKey('Filename', $imagesArray['Files']['0']); + $this->assertArrayHasKey('AcquisitionType', $imagesArray['Files']['0']); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/filename + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilename(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/qc + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilenameQc(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/images/" . + "$this->imagefileTest/qc", + [ + 'headers' => $this->headers, + 'http_errors' => false, + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + $imagesArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($imagesArray), + 'array' + ); + $this->assertSame( + gettype($imagesArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($imagesArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($imagesArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($imagesArray['QC']), + 'string' + ); + $this->assertSame( + gettype($imagesArray['Selected']), + 'boolean' + ); + $this->assertSame( + gettype($imagesArray['Caveats'][0]), + 'array' + ); + $this->assertSame( + gettype($imagesArray['Caveats']['0']['Severity']), + 'NULL' + ); + $this->assertSame( + gettype($imagesArray['Caveats']['0']['Header']), + 'NULL' + ); + $this->assertSame( + gettype($imagesArray['Caveats']['0']['Value']), + 'NULL' + ); + $this->assertSame( + gettype($imagesArray['Caveats']['0']['ValidRange']), + 'NULL' + ); + $this->assertSame( + gettype($imagesArray['Caveats']['0']['ValidRegex']), + 'NULL' + ); + + $this->assertArrayHasKey( + 'Meta', + $imagesArray + ); + $this->assertArrayHasKey( + 'CandID', + $imagesArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $imagesArray['Meta'] + ); + $this->assertArrayHasKey( + 'QC', + $imagesArray + ); + $this->assertArrayHasKey( + 'Selected', + $imagesArray + ); + $this->assertArrayHasKey( + 'Caveats', + $imagesArray + ); + $this->assertArrayHasKey( + '0', + $imagesArray['Caveats'] + ); + $this->assertArrayHasKey( + 'Severity', + $imagesArray['Caveats']['0'] + ); + $this->assertArrayHasKey( + 'Header', + $imagesArray['Caveats']['0'] + ); + $this->assertArrayHasKey( + 'Value', + $imagesArray['Caveats']['0'] + ); + $this->assertArrayHasKey( + 'ValidRange', + $imagesArray['Caveats']['0'] + ); + $this->assertArrayHasKey( + 'ValidRegex', + $imagesArray['Caveats']['0'] + ); + } + + /** + * Tests the HTTP PUT request for the + * endpoint /candidates/{candid}/{visit}/imaging/qc + * TODO: NOT WORKING: the request puts QC to null, but was 'Pass' should become + * 'pass'. Selected remains true, should be changed to false + * + * @return void + */ + public function testPutCandidatesCandidVisitImagesFilenameQc(): void + { + $candid = '587630'; + $visit = 'V1'; + $filename = 'demo_587630_V1_t1_001.mnc'; + $json = [ + 'Meta' => [ + 'CandID' => $candid, + 'Visit' => $visit, + 'File' => $filename + ], + "QC" => 'pass', + "Selected" => false, + 'Caveats' => [ + '0' => [ + 'Severity' => '', + 'Header' => '', + 'Value' => '', + 'ValidRange' => '', + 'ValidRegex' => '' + ] + ] + ]; + + $response = $this->client->request( + 'PUT', + "candidates/$candid/$visit/images/$filename/qc", + [ + 'headers' => $this->headers, + 'http_errors' => false, + 'json' => $json + ] + ); + // Verify the status code + $this->assertEquals(204, $response->getStatusCode()); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/filename/format/brainbrowser + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilenameFormatBbrowser(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/filename/format/raw + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilenameFormatRaw(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/filename/format/thumbnail + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilenameFormatThumbnail(): + void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/filename/headers + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilenameHeaders(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/images/" . + "$this->imagefileTest/headers", + [ + 'headers' => $this->headers, + 'http_errors' => false, + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $imagesHeadersArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($imagesHeadersArray), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Meta']['File']), + 'string' + ); + + $this->assertSame( + gettype($imagesHeadersArray['Physical']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Physical']['TE']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Physical']['TR']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Physical']['TI']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Physical']['SliceThickness']), + 'string' + ); + + $this->assertSame( + gettype($imagesHeadersArray['Description']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Description']['SeriesName']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Description']['SeriesDescription']), + 'string' + ); + + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['XSpace']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['XSpace']['Length']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['XSpace']['StepSize']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['YSpace']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['YSpace']['Length']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['YSpace']['StepSize']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['ZSpace']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['ZSpace']['Length']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['Dimensions']['ZSpace']['StepSize']), + 'string' + ); + + $this->assertSame( + gettype($imagesHeadersArray['ScannerInfo']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersArray['ScannerInfo']['Manufacturer']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['ScannerInfo']['Model']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['ScannerInfo']['SoftwareVersion']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['ScannerInfo']['SerialNumber']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersArray['ScannerInfo']['FieldStrength']), + 'string' + ); + + $this->assertArrayHasKey('Meta', $imagesHeadersArray); + $this->assertArrayHasKey('Physical', $imagesHeadersArray); + $this->assertArrayHasKey('Description', $imagesHeadersArray); + $this->assertArrayHasKey('Dimensions', $imagesHeadersArray); + $this->assertArrayHasKey('ScannerInfo', $imagesHeadersArray); + + $this->assertArrayHasKey('Meta', $imagesHeadersArray); + $this->assertArrayHasKey('CandID', $imagesHeadersArray['Meta']); + $this->assertArrayHasKey('Visit', $imagesHeadersArray['Meta']); + $this->assertArrayHasKey('File', $imagesHeadersArray['Meta']); + $this->assertArrayHasKey('TE', $imagesHeadersArray['Physical']); + $this->assertArrayHasKey('TR', $imagesHeadersArray['Physical']); + $this->assertArrayHasKey('TI', $imagesHeadersArray['Physical']); + $this->assertArrayHasKey( + 'SliceThickness', + $imagesHeadersArray['Physical'] + ); + $this->assertArrayHasKey( + 'SeriesName', + $imagesHeadersArray['Description'] + ); + $this->assertArrayHasKey( + 'SeriesDescription', + $imagesHeadersArray['Description'] + ); + $this->assertArrayHasKey( + 'XSpace', + $imagesHeadersArray['Dimensions'] + ); + $this->assertArrayHasKey( + 'Length', + $imagesHeadersArray['Dimensions']['XSpace'] + ); + $this->assertArrayHasKey( + 'StepSize', + $imagesHeadersArray['Dimensions']['XSpace'] + ); + $this->assertArrayHasKey( + 'YSpace', + $imagesHeadersArray['Dimensions'] + ); + $this->assertArrayHasKey( + 'Length', + $imagesHeadersArray['Dimensions']['YSpace'] + ); + $this->assertArrayHasKey( + 'StepSize', + $imagesHeadersArray['Dimensions']['YSpace'] + ); + $this->assertArrayHasKey( + 'YSpace', + $imagesHeadersArray['Dimensions'] + ); + $this->assertArrayHasKey( + 'Length', + $imagesHeadersArray['Dimensions']['YSpace'] + ); + $this->assertArrayHasKey( + 'StepSize', + $imagesHeadersArray['Dimensions']['YSpace'] + ); + $this->assertArrayHasKey( + 'ScannerInfo', + $imagesHeadersArray + ); + $this->assertArrayHasKey( + 'Manufacturer', + $imagesHeadersArray['ScannerInfo'] + ); + $this->assertArrayHasKey( + 'Model', + $imagesHeadersArray['ScannerInfo'] + ); + $this->assertArrayHasKey( + 'SoftwareVersion', + $imagesHeadersArray['ScannerInfo'] + ); + $this->assertArrayHasKey( + 'SerialNumber', + $imagesHeadersArray['ScannerInfo'] + ); + $this->assertArrayHasKey( + 'FieldStrength', + $imagesHeadersArray['ScannerInfo'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/filename/header/full + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilenameHeadersFull(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/images/" . + "$this->imagefileTest/headers/full", + [ + 'headers' => $this->headers, + 'http_errors' => false, + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $imagesHeadersFullArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertArrayHasKey( + 'Meta', + $imagesHeadersFullArray + ); + $this->assertArrayHasKey( + 'CandID', + $imagesHeadersFullArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $imagesHeadersFullArray['Meta'] + ); + $this->assertArrayHasKey( + 'File', + $imagesHeadersFullArray['Meta'] + ); + $this->assertArrayHasKey( + 'Headers', + $imagesHeadersFullArray + ); + $this->assertArrayHasKey( + 'slice_thickness', + $imagesHeadersFullArray['Headers'] + ); + $this->assertArrayHasKey( + 'acquisition:slice_order', + $imagesHeadersFullArray['Headers'] + ); + $this->assertArrayHasKey( + 'dicom_0x0051:el_0x1011', + $imagesHeadersFullArray['Headers'] + ); + $this->assertArrayHasKey( + 'image:vartype', + $imagesHeadersFullArray['Headers'] + ); + $this->assertArrayHasKey( + 'acquisition:percent_sampling', + $imagesHeadersFullArray['Headers'] + ); + $this->assertArrayHasKey( + 'dicom_0x0051:el_0x1012', + $imagesHeadersFullArray['Headers'] + ); + $this->assertArrayHasKey( + 'dicom_0x0028:vartype', + $imagesHeadersFullArray['Headers'] + ); + + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/images/filename/header/headername + * + * @return void + */ + public function testGetCandidatesCandidVisitImagesFilenameHeadersHeadername(): + void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/images/" . + "$this->imagefileTest/headers/headername", + [ + 'headers' => $this->headers, + 'http_errors' => false, + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $imagesHeadersHeadernameArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertArrayHasKey( + 'Meta', + $imagesHeadersHeadernameArray + ); + $this->assertArrayHasKey( + 'Value', + $imagesHeadersHeadernameArray + ); + $this->assertArrayHasKey( + 'CandID', + $imagesHeadersHeadernameArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $imagesHeadersHeadernameArray['Meta'] + ); + $this->assertArrayHasKey( + 'File', + $imagesHeadersHeadernameArray['Meta'] + ); + $this->assertArrayHasKey( + 'Header', + $imagesHeadersHeadernameArray['Meta'] + ); + + $this->assertSame( + gettype($imagesHeadersHeadernameArray), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersHeadernameArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($imagesHeadersHeadernameArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersHeadernameArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersHeadernameArray['Meta']['File']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersHeadernameArray['Meta']['Header']), + 'string' + ); + $this->assertSame( + gettype($imagesHeadersHeadernameArray['Value']), + 'string' + ); + } +} diff --git a/raisinbread/test/api/LorisApiInstrumentsTest.php b/raisinbread/test/api/LorisApiInstrumentsTest.php new file mode 100644 index 00000000000..02cfa335a64 --- /dev/null +++ b/raisinbread/test/api/LorisApiInstrumentsTest.php @@ -0,0 +1,178 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiInstrumentsTest extends LorisApiAuthenticatedTest +{ + protected $instrumentTest = "medical_history"; + protected $candidTest = "300004"; + protected $visitTest = "V3"; + + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/instruments + * + * @return void + */ + public function testGetCandidatesCandidVisitInstruments(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/instruments", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $instrArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame(gettype($instrArray), 'array'); + $this->assertSame( + gettype($instrArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($instrArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($instrArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($instrArray['Instruments']), + 'array' + ); + $this->assertSame( + gettype($instrArray['Instruments']['0']), + 'string' + ); + + $this->assertArrayHasKey( + 'CandID', + $instrArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $instrArray['Meta'] + ); + $this->assertArrayHasKey( + '0', + $instrArray['Instruments'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/instruments{instruments} + * + * @return void + */ + public function testGetCandidatesCandidVisitInstrumentsInstrument(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP PATCH request for the + * endpoint /projects/{project}/instruments{instrument} + * + * @return void + */ + public function testPatchCandidatesCandidVisitInstrumentsInstrument(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP PUT request for the + * endpoint /projects/{project}/instruments{instrument} + * + * @return void + */ + public function testPutCandidatesCandidVisitInstrumentsInstrument(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/instruments{instruments}/flags + * + * @return void + */ + public function testGetCandidatesCandidVisitInstrumentsInstrumentFlags(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/instruments{instruments}/dde + * + * @return void + */ + public function testGetCandidatesCandidVisitInstrumentsInstrumentDde(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP PATCH request for the + * endpoint /projects/{project}/instruments{instrument}/flag + * + * @return void + */ + public function testPatchCandidatesCandidVisitInstrumentsInstrumentDde(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP PUT request for the + * endpoint /projects/{project}/instruments{instrument} + * + * @return void + */ + public function testPutCandidatesCandidVisitInstrumentsInstrumentDde(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/instruments{instruments}/dde/flags + * + * @return void + */ + public function testGetCandidatesCandidVisitInstrumentsInstrumentDdeFlags() + { + $this->markTestSkipped('Missing data in docker image'); + } +} diff --git a/raisinbread/test/api/LorisApiProjectsTest.php b/raisinbread/test/api/LorisApiProjectsTest.php new file mode 100644 index 00000000000..fd2e42d6188 --- /dev/null +++ b/raisinbread/test/api/LorisApiProjectsTest.php @@ -0,0 +1,524 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiProjectsTest extends LorisApiAuthenticatedTest +{ + protected $projectName = "Pumpernickel"; + + /** + * Tests the HTTP GET request for the endpoint /projects + * + * @return void + */ + public function testGetProjects(): void + { + $response = $this->client->request( + 'GET', + "projects", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + if ($response->getStatusCode() === 404) { + $this->markTestSkipped( + "Endpoint not found: GET projects" + ); + } + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $projectsArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype( + $projectsArray['Projects'] + ), + 'array' + ); + $this->assertSame( + gettype( + $projectsArray['Projects']['Pumpernickel'] + ), + 'array' + ); + $this->assertSame( + gettype( + $projectsArray['Projects']['Pumpernickel']['useEDC'] + ), + 'string' + ); + $this->assertSame( + gettype( + $projectsArray['Projects']['Pumpernickel']['PSCID'] + ), + 'array' + ); + $this->assertSame( + gettype($projectsArray['Projects']['Pumpernickel']['PSCID']['Type']), + 'string' + ); + $this->assertSame( + gettype($projectsArray['Projects']['Pumpernickel']['PSCID']['Regex']), + 'string' + ); + + $this->assertArrayHasKey( + 'Projects', + $projectsArray + ); + $this->assertArrayHasKey( + 'Pumpernickel', + $projectsArray['Projects'] + ); + $this->assertArrayHasKey( + 'useEDC', + $projectsArray['Projects']['Pumpernickel'] + ); + $this->assertArrayHasKey( + 'PSCID', + $projectsArray['Projects']['Pumpernickel'] + ); + $this->assertArrayHasKey( + 'Type', + $projectsArray['Projects']['Pumpernickel']['PSCID'] + ); + $this->assertArrayHasKey( + 'Regex', + $projectsArray['Projects']['Pumpernickel']['PSCID'] + ); + } + + /** + * Tests the HTTP GET request for the endpoint /projects/{project} + * + * @return void + */ + public function testGetProjectsProject(): void + { + $response = $this->client->request( + 'GET', + "projects/$this->projectName", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $projectsProjectArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($projectsProjectArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($projectsProjectArray['Meta']['Project']), + 'string' + ); + $this->assertSame( + gettype($projectsProjectArray['Candidates']), + 'array' + ); + $this->assertSame( + gettype($projectsProjectArray['Candidates']['0']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $projectsProjectArray + ); + $this->assertArrayHasKey( + 'Project', + $projectsProjectArray['Meta'] + ); + $this->assertArrayHasKey( + 'Candidates', + $projectsProjectArray + ); + $this->assertArrayHasKey( + '0', + $projectsProjectArray['Candidates'] + ); + } + + /** + * Tests the HTTP GET request for the endpoint /projects/{project}/candidates + * + * @return void + */ + public function testGetProjectsProjectCandidates(): void + { + $response = $this->client->request( + 'GET', + "projects/$this->projectName/candidates", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $projectsProjectArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($projectsProjectArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($projectsProjectArray['Meta']['Project']), + 'string' + ); + $this->assertSame( + gettype($projectsProjectArray['Candidates']), + 'array' + ); + $this->assertSame( + gettype($projectsProjectArray['Candidates']['0']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $projectsProjectArray + ); + $this->assertArrayHasKey( + 'Project', + $projectsProjectArray['Meta'] + ); + $this->assertArrayHasKey( + 'Candidates', + $projectsProjectArray + ); + + } + + /** + * Tests the HTTP GET request for the endpoint /projects/{project}/images + * + * @return void + */ + public function testGetProjectsProjectImages(): void + { + $response = $this->client->request( + 'GET', + "projects/$this->projectName/images", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + $projectsImagesArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($projectsImagesArray['Images']), + 'array' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']), + 'array' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['Candidate']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['PSCID']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['Visit']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['Visit_date']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['Site']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['InsertTime']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['ScanType']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['Selected']), + 'string' + ); + $this->assertSame( + gettype($projectsImagesArray['Images']['0']['Link']), + 'string' + ); + + $this->assertArrayHasKey( + 'Images', + $projectsImagesArray + ); + $this->assertArrayHasKey( + '0', + $projectsImagesArray['Images'] + ); + $this->assertArrayHasKey( + 'Candidate', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'PSCID', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'Visit', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'Visit_date', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'Site', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'InsertTime', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'ScanType', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'QC_status', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'Selected', + $projectsImagesArray['Images']['0'] + ); + $this->assertArrayHasKey( + 'Link', + $projectsImagesArray['Images']['0'] + ); + } + + /** + * Tests the HTTP GET request for the endpoint /projects/{project}/visits + * + * @return void + */ + public function testGetProjectsProjectVisits(): void + { + $response = $this->client->request( + 'GET', + "projects/$this->projectName/visits", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $projectsVisitsArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($projectsVisitsArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($projectsVisitsArray['Meta']['Project']), + 'string' + ); + $this->assertSame( + gettype($projectsVisitsArray['Visits']), + 'array' + ); + $this->assertSame( + gettype($projectsVisitsArray['Visits']['0']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $projectsVisitsArray + ); + $this->assertArrayHasKey( + 'Project', + $projectsVisitsArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visits', + $projectsVisitsArray + ); + $this->assertArrayHasKey( + '0', + $projectsVisitsArray['Visits'] + ); + } + + /** + * Tests the HTTP GET request for the endpoint /projects/{project}/instruments + * + * @return void + */ + public function testGetProjectsProjectInstruments(): void + { + $response = $this->client->request( + 'GET', + "projects/$this->projectName/instruments", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $projectsInstrArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($projectsInstrArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($projectsInstrArray['Meta']['Project']), + 'string' + ); + $this->assertSame( + gettype($projectsInstrArray['Instruments']), + 'array' + ); + $this->assertSame( + gettype($projectsInstrArray['Instruments']['aosi']), + 'array' + ); + $this->assertSame( + gettype( + $projectsInstrArray['Instruments']['aosi']['Fullname'] + ), + 'string' + ); + $this->assertSame( + gettype( + $projectsInstrArray['Instruments']['aosi']['Subgroup'] + ), + 'string' + ); + $this->assertSame( + gettype( + $projectsInstrArray['Instruments']['aosi']['DoubleDataEntryEnabled'] + ), + 'boolean' + ); + + $this->assertArrayHasKey( + 'Meta', + $projectsInstrArray + ); + $this->assertArrayHasKey( + 'Project', + $projectsInstrArray['Meta'] + ); + $this->assertArrayHasKey( + 'Instruments', + $projectsInstrArray + ); + $this->assertArrayHasKey( + 'radiology_review', + $projectsInstrArray['Instruments'] + ); + $this->assertArrayHasKey( + 'bmi', + $projectsInstrArray['Instruments'] + ); + $this->assertArrayHasKey( + 'medical_history', + $projectsInstrArray['Instruments'] + ); + $this->assertArrayHasKey( + 'aosi', + $projectsInstrArray['Instruments'] + ); + $this->assertArrayHasKey( + 'mri_parameter_form', + $projectsInstrArray['Instruments'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /projects/{project}/instruments/{instrument} + * + * @return void + */ + public function testGetProjectsProjectInstrumentsInstrument(): void + { + $this->markTestSkipped('Missing data in docker image'); + } +} diff --git a/raisinbread/test/api/LorisApiRecordingsTest.php b/raisinbread/test/api/LorisApiRecordingsTest.php new file mode 100644 index 00000000000..0386d7cc523 --- /dev/null +++ b/raisinbread/test/api/LorisApiRecordingsTest.php @@ -0,0 +1,1026 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiRecordingsTest extends LorisApiAuthenticatedTest +{ + protected $frecordTest = "sub-OTT174_ses-V1_task-faceO_eeg.edf"; + protected $frecordTestFile = "bids_imports/Face13_BIDSVersion_1.1.0/" . + "sub-OTT174/ses-V1/eeg/sub-OTT174_ses-V1_task-faceO_eeg.edf"; + protected $candidTest = "300174"; + protected $visitTest = "V1"; + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordings(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/recordings", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + $recordingsArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame(gettype($recordingsArray), 'array'); + $this->assertSame(gettype($recordingsArray['Meta']), 'array'); + $this->assertSame( + gettype($recordingsArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($recordingsArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($recordingsArray['Files']), + 'array' + ); + $this->assertSame( + gettype($recordingsArray['Files']['0']), + 'array' + ); + $this->assertSame( + gettype($recordingsArray['Files']['0']), + 'array' + ); + + $this->assertArrayHasKey('Meta', $recordingsArray); + $this->assertArrayHasKey('CandID', $recordingsArray['Meta']); + $this->assertArrayHasKey('Visit', $recordingsArray['Meta']); + $this->assertArrayHasKey('Files', $recordingsArray); + $this->assertArrayHasKey('0', $recordingsArray['Files']); + $this->assertArrayHasKey('OutputType', $recordingsArray['Files']['0']); + $this->assertArrayHasKey('Filename', $recordingsArray['Files']['0']); + $this->assertArrayHasKey( + 'AcquisitionModality', + $recordingsArray['Files']['0'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings/{edffile} + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordingsEdffile(): void + { + $this->markTestSkipped('Missing data in docker image'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings/{edffile}/channels + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordingsEdffileChannels(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/" . + "recordings/$this->frecordTest/channels", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $recChannelsArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($recChannelsArray), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['ChannelName']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['ChannelDescription']), + 'NULL' + ); + $this->assertSame( + gettype( + $recChannelsArray['Channels']['0']['ChannelTypeDescription'] + ), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['ChannelStatus']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['StatusDescription']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['SamplingFrequency']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['LowCutoff']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['HighCutoff']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['ManualFlag']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['Notch']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['Reference']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['Unit']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Channels']['0']['ChannelFilePath']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $recChannelsArray + ); + $this->assertArrayHasKey( + 'CandID', + $recChannelsArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $recChannelsArray['Meta'] + ); + $this->assertArrayHasKey( + 'Channels', + $recChannelsArray + ); + $this->assertArrayHasKey( + '0', + $recChannelsArray['Channels'] + ); + $this->assertArrayHasKey( + 'ChannelName', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelDescription', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelTypeDescription', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelStatus', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'StatusDescription', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'SamplingFrequency', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'LowCutoff', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'HighCutoff', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ManualFlag', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'Notch', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'Reference', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'Unit', + $recChannelsArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelFilePath', + $recChannelsArray['Channels']['0'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings/{edffile}/channels/meta + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordingsEdffileChannelsMeta(): + void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/recordings/" . + "$this->frecordTest/channels/meta", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $recChannelsMetaArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($recChannelsMetaArray), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['ChannelName']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['ChannelDescription']), + 'NULL' + ); + $this->assertSame( + gettype( + $recChannelsMetaArray['Channels']['0']['ChannelTypeDescription'] + ), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['ChannelStatus']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['StatusDescription']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['SamplingFrequency']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['LowCutoff']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['HighCutoff']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['ManualFlag']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['Notch']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['Reference']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['Unit']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Channels']['0']['ChannelFilePath']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $recChannelsMetaArray + ); + $this->assertArrayHasKey( + 'CandID', + $recChannelsMetaArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $recChannelsMetaArray['Meta'] + ); + $this->assertArrayHasKey( + 'Channels', + $recChannelsMetaArray + ); + $this->assertArrayHasKey( + '0', + $recChannelsMetaArray['Channels'] + ); + $this->assertArrayHasKey( + 'ChannelName', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelDescription', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelTypeDescription', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelStatus', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'StatusDescription', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'SamplingFrequency', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'LowCutoff', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'HighCutoff', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ManualFlag', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'Notch', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'Reference', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'Unit', + $recChannelsMetaArray['Channels']['0'] + ); + $this->assertArrayHasKey( + 'ChannelFilePath', + $recChannelsMetaArray['Channels']['0'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings/{edffile}/electrodes + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordingsEdfFileElectrodes(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/recordings/" . + "$this->frecordTest/electrodes", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $recChannelsArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($recChannelsArray), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']), + 'array' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['ElectrodeName']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['ElectrodeType']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['ElectrodeMaterial']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['X']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['Y']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['Z']), + 'string' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['Impedance']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsArray['Electrodes']['0']['ElectrodeFilePath']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $recChannelsArray + ); + $this->assertArrayHasKey( + 'CandID', + $recChannelsArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $recChannelsArray['Meta'] + ); + $this->assertArrayHasKey( + 'Electrodes', + $recChannelsArray + ); + $this->assertArrayHasKey( + '0', + $recChannelsArray['Electrodes'] + ); + $this->assertArrayHasKey( + 'ElectrodeName', + $recChannelsArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'ElectrodeType', + $recChannelsArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'ElectrodeMaterial', + $recChannelsArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'X', + $recChannelsArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'Y', + $recChannelsArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'Z', + $recChannelsArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'Impedance', + $recChannelsArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'ElectrodeFilePath', + $recChannelsArray['Electrodes']['0'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings/{edffile}/electrodes/meta + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordingsEdfFileElectrodesMeta(): + void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/recordings/" . + "$this->frecordTest/electrodes/meta", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $recChannelsMetaArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($recChannelsMetaArray), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']), + 'array' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['ElectrodeName']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['ElectrodeType']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['ElectrodeMaterial']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['X']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['Y']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['Z']), + 'string' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['Impedance']), + 'NULL' + ); + $this->assertSame( + gettype($recChannelsMetaArray['Electrodes']['0']['ElectrodeFilePath']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $recChannelsMetaArray + ); + $this->assertArrayHasKey( + 'CandID', + $recChannelsMetaArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $recChannelsMetaArray['Meta'] + ); + $this->assertArrayHasKey( + 'Electrodes', + $recChannelsMetaArray + ); + $this->assertArrayHasKey( + '0', + $recChannelsMetaArray['Electrodes'] + ); + $this->assertArrayHasKey( + 'ElectrodeName', + $recChannelsMetaArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'ElectrodeType', + $recChannelsMetaArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'ElectrodeMaterial', + $recChannelsMetaArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'X', + $recChannelsMetaArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'Y', + $recChannelsMetaArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'Z', + $recChannelsMetaArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'Impedance', + $recChannelsMetaArray['Electrodes']['0'] + ); + $this->assertArrayHasKey( + 'ElectrodeFilePath', + $recChannelsMetaArray['Electrodes']['0'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings/{edffile}/events + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordingsEdfFileEvents(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/recordings/" . + "$this->frecordTest/events/meta", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $recordingsEventsArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($recordingsEventsArray), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['Onset']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['Duration']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['EventCode']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['EventSample']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['EventType']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['TrialType']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['ResponseTime']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsArray['TaskEvents']['0']['EventFilePath']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $recordingsEventsArray + ); + $this->assertArrayHasKey( + 'CandID', + $recordingsEventsArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $recordingsEventsArray['Meta'] + ); + $this->assertArrayHasKey( + 'TaskEvents', + $recordingsEventsArray + ); + $this->assertArrayHasKey( + '0', + $recordingsEventsArray['TaskEvents'] + ); + $this->assertArrayHasKey( + 'Onset', + $recordingsEventsArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'Duration', + $recordingsEventsArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventCode', + $recordingsEventsArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventSample', + $recordingsEventsArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventType', + $recordingsEventsArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'TrialType', + $recordingsEventsArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'ResponseTime', + $recordingsEventsArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventFilePath', + $recordingsEventsArray['TaskEvents']['0'] + ); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/recordings/{edffile}/events/meta + * + * @return void + */ + public function testGetCandidatesCandidVisitRecordingsEdfFileEventsMeta(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/recordings/" . + "$this->frecordTest/events/meta", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + + $recordingsEventsMetaArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame( + gettype($recordingsEventsMetaArray), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']), + 'array' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['Onset']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['Duration']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['EventCode']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['EventSample']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['EventType']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['TrialType']), + 'string' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['ResponseTime']), + 'NULL' + ); + $this->assertSame( + gettype($recordingsEventsMetaArray['TaskEvents']['0']['EventFilePath']), + 'string' + ); + + $this->assertArrayHasKey( + 'Meta', + $recordingsEventsMetaArray + ); + $this->assertArrayHasKey( + 'CandID', + $recordingsEventsMetaArray['Meta'] + ); + $this->assertArrayHasKey( + 'Visit', + $recordingsEventsMetaArray['Meta'] + ); + $this->assertArrayHasKey( + 'TaskEvents', + $recordingsEventsMetaArray + ); + $this->assertArrayHasKey( + '0', + $recordingsEventsMetaArray['TaskEvents'] + ); + $this->assertArrayHasKey( + 'Onset', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'Duration', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventCode', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventSample', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventType', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'TrialType', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'ResponseTime', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + $this->assertArrayHasKey( + 'EventFilePath', + $recordingsEventsMetaArray['TaskEvents']['0'] + ); + } +} diff --git a/raisinbread/test/api/LorisApiVisitsTest.php b/raisinbread/test/api/LorisApiVisitsTest.php new file mode 100644 index 00000000000..2aec6340417 --- /dev/null +++ b/raisinbread/test/api/LorisApiVisitsTest.php @@ -0,0 +1,209 @@ +/api// + * (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host + * "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects) + * + * @category API + * @package Tests + * @subpackage Integration + * @author Simon Pelletier + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class LorisApiVisitsTest extends LorisApiAuthenticatedTest +{ + protected $candidTest = "300008"; + protected $visitTest = "V1"; + + /** + * Tests the HTTP GET request for the endpoint /candidates/{candid}/{visit} + * + * @return void + */ + public function testGetCandidatesCandidVisit(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + $candidatesVisitArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame(gettype($candidatesVisitArray), 'array'); + $this->assertSame( + gettype($candidatesVisitArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($candidatesVisitArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['Meta']['Site']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['Meta']['Battery']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['Stages']), + 'array' + ); + $this->assertSame( + gettype($candidatesVisitArray['Stages']['Visit']), + 'array' + ); + $this->assertSame( + gettype($candidatesVisitArray['Stages']['Visit']['Date']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['Stages']['Visit']['Status']), + 'string' + ); + + $this->assertArrayHasKey('Meta', $candidatesVisitArray); + $this->assertArrayHasKey('CandID', $candidatesVisitArray['Meta']); + $this->assertArrayHasKey('Project', $candidatesVisitArray['Meta']); + $this->assertArrayHasKey('Site', $candidatesVisitArray['Meta']); + $this->assertArrayHasKey('Battery', $candidatesVisitArray['Meta']); + $this->assertArrayHasKey('Project', $candidatesVisitArray['Meta']); + $this->assertArrayHasKey('Stages', $candidatesVisitArray); + $this->assertArrayHasKey( + 'Visit', + $candidatesVisitArray['Stages'] + ); + $this->assertArrayHasKey( + 'Date', + $candidatesVisitArray['Stages']['Visit'] + ); + $this->assertArrayHasKey( + 'Status', + $candidatesVisitArray['Stages']['Visit'] + ); + + } + + /** + * Tests the HTTP PUT request for the endpoint /candidates/{candid}/{visit} + * + * @return void + */ + public function testPutCandidatesCandidVisit(): void + { + $this->markTestSkipped('No access to create visits for any site'); + } + + /** + * Tests the HTTP GET request for the + * endpoint /candidates/{candid}/{visit}/imaging/qc + * + * @return void + */ + public function testGetCandidatesCandidVisitQcImaging(): void + { + $response = $this->client->request( + 'GET', + "candidates/$this->candidTest/$this->visitTest/qc/imaging", + [ + 'http_errors' => false, + 'headers' => $this->headers + ] + ); + $this->assertEquals(200, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + $candidatesVisitArray = json_decode( + (string) utf8_encode( + $response->getBody()->getContents() + ), + true + ); + + $this->assertSame(gettype($candidatesVisitArray), 'array'); + $this->assertSame( + gettype($candidatesVisitArray['Meta']), + 'array' + ); + $this->assertSame( + gettype($candidatesVisitArray['Meta']['CandID']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['Meta']['Visit']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['SessionQC']), + 'string' + ); + $this->assertSame( + gettype($candidatesVisitArray['Pending']), + 'boolean' + ); + + $this->assertArrayHasKey('Meta', $candidatesVisitArray); + $this->assertArrayHasKey('CandID', $candidatesVisitArray['Meta']); + $this->assertArrayHasKey('Visit', $candidatesVisitArray['Meta']); + $this->assertArrayHasKey('SessionQC', $candidatesVisitArray); + $this->assertArrayHasKey('Pending', $candidatesVisitArray); + } + + /** + * Tests the HTTP PUT request for the + * endpoint /candidates/{candid}/{visit}/imaging/qc + * + * @return void + */ + public function testPutCandidatesCandidVisitQcImaging(): void + { + $candid = '400162'; + $visit = 'V6'; + $json = [ + "Meta" => [ + 'CandID' => $candid, + 'Visit' => $visit + ], + 'SessionQC' => "", + 'Pending' => true + ]; + $response = $this->client->request( + 'PUT', + "candidates/$candid/$visit/qc/imaging", + [ + 'http_errors' => false, + 'headers' => $this->headers, + 'json' => $json + ] + ); + // Verify the status code + $this->assertEquals(204, $response->getStatusCode()); + // Verify the endpoint has a body + $body = $response->getBody(); + $this->assertNotEmpty($body); + } +} diff --git a/test/integrationtests/LorisIntegrationTest.class.inc b/test/integrationtests/LorisIntegrationTest.class.inc old mode 100644 new mode 100755 diff --git a/test/phpunit.xml b/test/phpunit.xml index 89e2fab0e1e..815f4d40964 100644 --- a/test/phpunit.xml +++ b/test/phpunit.xml @@ -13,6 +13,7 @@ + ../raisinbread/test/api/ ../modules/api/test/ ../modules/acknowledgements/test/ ../modules/brainbrowser/test/