psr12 fixes for new PHP_CodeSniffer (#4795)
[openemr.git] / tests / Tests / Services / DocumentTest.php
blob77f58b58b6fd108b4738bb6d647483ad1aa8b55f
1 <?php
3 /**
4 * DocumentTest tests the \Document object
5 * @package openemr
6 * @link http://www.open-emr.org
7 * @author Stephen Nielson <stephen@nielson.org>
8 * @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
12 namespace OpenEMR\Tests\Services;
14 use Document;
15 use Monolog\Test\TestCase;
16 use OpenEMR\Services\UserService;
17 use Ramsey\Uuid\Uuid;
19 class DocumentTest extends TestCase
21 /**
22 * Checks that a document can be created and the file exists at the location the document says it saves at
24 public function testCreateDocument()
26 $userService = new UserService();
27 $apiSystemUser = $userService->getSystemUser();
29 $jobId = Uuid::uuid4();
30 $document = new \Document();
31 $folder = 'services-test-file';
32 $categoryId = null;
33 $fileName = "Patient-" . $jobId . ".ndjson";
34 $fullPath = $folder . DIRECTORY_SEPARATOR . $fileName;
36 $data = json_encode(['id' => $jobId]);
38 $mimeType = "application/fhir+ndjson";
39 $higherLevelPath = "";
40 $pathDepth = 1;
41 $owner = $apiSystemUser['id']; // userID, if we didn't have one it would default to the session
42 $document->createDocument($jobId, $categoryId, $fullPath, $mimeType, $data, $higherLevelPath, $pathDepth, $owner);
44 $this->assertNotEmpty($document->get_id(), "database id should be populated");
45 $this->assertEquals($folder . '/' . $fileName, $document->get_name(), "Saved document should have a matching name");
46 $this->assertEquals($mimeType, $document->get_mimetype());
48 $url = $document->get_url();
49 if ($document->get_storagemethod() === Document::STORAGE_METHOD_FILESYSTEM) {
50 // not sure how the couch db tests should work but we are going to verify if the file is stored on the file
51 // system that we did indeed write a file here.
52 if (strpos($url, 'file:') !== false) {
53 $this->assertTrue(file_exists($document->get_url_filepath(), "File should exist at document location"));