From c88478f7d863c58ab40fe273c3dc1b777769b05b Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Thu, 11 Feb 2021 18:13:38 -0300 Subject: [PATCH] Includes file extension on bilingual download It is important to choose the file extension, so including it on the filename would be the easier way for us, as we already have the extension when using it. --- src/BilingualFile.php | 7 +++++-- tests/bilingualFileTest.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/BilingualFile.php b/src/BilingualFile.php index 2e1bba1..d90b4fc 100644 --- a/src/BilingualFile.php +++ b/src/BilingualFile.php @@ -30,13 +30,16 @@ class BilingualFile extends \BrunoFontes\Memsource\BaseApi */ public function download(string $projectUid, array $jobUids, string $filename): array { - $url = "/api2/v1/projects/{$projectUid}/jobs/bilingualFile"; + $fileExtension = pathinfo($filename)['extension']; + $fileNoExtension = basename($filename,'.'.$fileExtension); +; + $url = "/api2/v1/projects/{$projectUid}/jobs/bilingualFile?format=" . strtoupper($fileExtension); $filenames = []; $groupedJobUids = array_chunk($jobUids, 100); for ($i = 0; $i < count($groupedJobUids); $i++) { $apiReadyArray = $this->_convertUidArrayToApiRequest($groupedJobUids[$i]); - $filenames[$i] = count($groupedJobUids) > 1 ? "{$i}_{$filename}" : $filename; + $filenames[$i] = count($groupedJobUids) > 1 ? "{$fileNoExtension}_{$i}.{$fileExtension}" : $filename; $filecontent = $this->fetchApi->fetch('jsonPost', $url, $apiReadyArray); if ($this->hasError($filecontent)) { $errorMsg = $this->getError($filecontent); diff --git a/tests/bilingualFileTest.php b/tests/bilingualFileTest.php index e9d50ea..ac735d9 100644 --- a/tests/bilingualFileTest.php +++ b/tests/bilingualFileTest.php @@ -11,14 +11,14 @@ final class BilingualFileTest extends TestCase $api = new Memsource('fakeToken'); $this->assertEquals( [], - $api->bilingualFile()->download('uid', [], 'filename') + $api->bilingualFile()->download('uid', [], 'filename.xliff') ); } public function testInvalidDownloadUidsShouldThrowError() { $api = new Memsource('fakeToken'); $this->expectException(\Exception::class); - $api->bilingualFile()->download('uid', ['a'], 'filename'); + $api->bilingualFile()->download('uid', ['a'], 'filename.xliff'); } public function testUploadInexistentFileShouldThrowError()