diff --git a/README.md b/README.md index b75d7b6..bcb2193 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# GetOrganized API client +# GetOrganized API client ## Installation @@ -56,11 +56,31 @@ class Tiles extends Service ## Development +### Tests + +```sh +docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer install +docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php8.1-fpm:latest vendor/bin/phpunit +``` + ### Coding standards -The following commands let you test that the coding standards: +The following commands let you test that the code adheres to the coding standards: ```sh -docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php7.4-fpm:latest composer coding-standards-check +docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer install +docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-check ``` +Automatically fix some coding standards issues by running + +```sh +docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-apply +``` + +### Code analysis + +```sh +docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer install +docker run --interactive --tty --rm --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer code-analysis +``` diff --git a/src/Mock/resources/_goapi/Documents/AddToDocumentLibrary.yaml b/src/Mock/resources/_goapi/Documents/AddToDocumentLibrary.yaml index bb9f819..ba3685d 100644 --- a/src/Mock/resources/_goapi/Documents/AddToDocumentLibrary.yaml +++ b/src/Mock/resources/_goapi/Documents/AddToDocumentLibrary.yaml @@ -7,7 +7,7 @@ CaseId: 'GEO-2022-000114' ListName: 'Dokumenter' FolderPath: '' - FileName: '' + FileName: 'pipfugl.png' Metadata: '' Overwrite: true response: diff --git a/src/Service/Documents.php b/src/Service/Documents.php index f146de8..68e05a0 100644 --- a/src/Service/Documents.php +++ b/src/Service/Documents.php @@ -53,6 +53,14 @@ public function AddToDocumentLibrary(string $filePath, string $caseId, string $f $bytes = self::fileToIntArray($filePath); + if (empty($fileName)) { + $fileName = basename($filePath); + } + + // Make sure that the file name is valid in Windows (cf. + // https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions). + $fileName = preg_replace('@[<>:"/\\\\|?*]@', '_', $fileName); + $result = $this->getData( 'POST', $this->getApiBasePath().__FUNCTION__,