diff --git a/src/CrowdinApiClient/Api/Enterprise/FileApi.php b/src/CrowdinApiClient/Api/Enterprise/FileApi.php index 1ab581ec..31c977d8 100644 --- a/src/CrowdinApiClient/Api/Enterprise/FileApi.php +++ b/src/CrowdinApiClient/Api/Enterprise/FileApi.php @@ -40,9 +40,9 @@ public function listReviewedSourceFilesBuilds(int $projectId, array $params = [] * @param int $projectId * @param array $data * integer $data[branchId] - * @return ReviewedSourceFileBuild + * @return ReviewedSourceFileBuild|null */ - public function buildReviewedSourceFiles(int $projectId, array $data = []): ReviewedSourceFileBuild + public function buildReviewedSourceFiles(int $projectId, array $data = []): ?ReviewedSourceFileBuild { $path = sprintf('projects/%d/strings/reviewed-builds', $projectId); return $this->_create($path, ReviewedSourceFileBuild::class, $data); @@ -51,18 +51,18 @@ public function buildReviewedSourceFiles(int $projectId, array $data = []): Revi /** * Check Reviewed Source Files Build Status * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings.reviewed-builds.get API Documentation Enterprise - * - * @param int $projectId - * @param int $buildId - * @return ReviewedSourceFileBuild */ - public function checkReviewedSourceFilesBuildStatus(int $projectId, int $buildId): ReviewedSourceFileBuild + public function checkReviewedSourceFilesBuildStatus(int $projectId, int $buildId): ?ReviewedSourceFileBuild { $path = sprintf('projects/%d/strings/reviewed-builds/%d', $projectId, $buildId); return $this->_get($path, ReviewedSourceFileBuild::class); } - public function downloadReviewedSourceFiles(int $projectId, int $buildId): DownloadFile + /** + * Download Reviewed Source Files + * @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Source-Files/operation/api.projects.strings.reviewed-builds.download.download API Documentation Enterprise + */ + public function downloadReviewedSourceFiles(int $projectId, int $buildId): ?DownloadFile { $path = sprintf('projects/%d/strings/reviewed-builds/%d/download', $projectId, $buildId); return $this->_get($path, DownloadFile::class); diff --git a/src/CrowdinApiClient/Api/FileApi.php b/src/CrowdinApiClient/Api/FileApi.php index 0c6f1c95..75585a05 100644 --- a/src/CrowdinApiClient/Api/FileApi.php +++ b/src/CrowdinApiClient/Api/FileApi.php @@ -19,6 +19,7 @@ class FileApi extends AbstractApi * List Files * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.getMany API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.getMany API Documentation Enterprise + * * @param int $projectId * @param array $params * integer $params[branchId] Can't be used with directoryId in the same request
@@ -62,9 +63,6 @@ public function create(int $projectId, array $data): File * Get File Info * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.get API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.get API Documentation Enterprise - * @param int $projectId - * @param int $fileId - * @return File|null */ public function get(int $projectId, int $fileId): ?File { @@ -76,6 +74,7 @@ public function get(int $projectId, int $fileId): ?File * Update File * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.put API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.put API Documentation Enterprise + * * @param int $projectId * @param int $fileId * @param array $data @@ -95,6 +94,7 @@ public function update(int $projectId, int $fileId, array $data): File * Restore file to revision * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.put API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.put API Documentation Enterprise + * * @param int $projectId * @param int $fileId * @param array $data @@ -111,10 +111,6 @@ public function restore(int $projectId, int $fileId, array $data): File * Download Preview File * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.preview.get API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.preview.get API Documentation Enterprise - * - * @param int $projectId - * @param int $fileId - * @return DownloadFilePreview|null */ public function downloadPreview(int $projectId, int $fileId): ?DownloadFilePreview { @@ -126,10 +122,6 @@ public function downloadPreview(int $projectId, int $fileId): ?DownloadFilePrevi * Download File * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.download.get API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.download.get API Documentation Enterprise - * - * @param int $projectId - * @param int $fileId - * @return DownloadFile|null */ public function download(int $projectId, int $fileId): ?DownloadFile { @@ -141,9 +133,6 @@ public function download(int $projectId, int $fileId): ?DownloadFile * Edit File * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.patch API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.patch API Documentation Enterprise - * - * @param File $file - * @return File|null */ public function edit(File $file): ?File { @@ -156,9 +145,7 @@ public function edit(File $file): ?File * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.delete API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.delete API Documentation Enterprise * - * @param int $projectId - * @param int $fileId - * @return mixed + * @return null */ public function delete(int $projectId, int $fileId) { @@ -170,10 +157,6 @@ public function delete(int $projectId, int $fileId) * List File Revisions * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.revisions.getMany API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.revisions.getMany API Documentation Enterprise - * - * @param int $projectId - * @param int $fileId - * @return ModelCollection */ public function revisions(int $projectId, int $fileId): ModelCollection { @@ -185,11 +168,6 @@ public function revisions(int $projectId, int $fileId): ModelCollection * Get File Revision * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.revisions.get API Documentation * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.revisions.get API Documentation Enterprise - * - * @param int $projectId - * @param int $fileId - * @param int $revision - * @return FileRevision|null */ public function getRevision(int $projectId, int $fileId, int $revision): ?FileRevision { diff --git a/src/CrowdinApiClient/Model/FileRevision.php b/src/CrowdinApiClient/Model/FileRevision.php index 3a7bc9f2..dafc6149 100644 --- a/src/CrowdinApiClient/Model/FileRevision.php +++ b/src/CrowdinApiClient/Model/FileRevision.php @@ -8,22 +8,22 @@ class FileRevision extends BaseModel { /** - * @var integer + * @var int */ protected $id; /** - * @var integer + * @var int */ protected $projectId; /** - * @var integer + * @var int */ protected $fileId; /** - * @var integer + * @var int|null */ protected $restoreToRevision; @@ -37,82 +37,47 @@ class FileRevision extends BaseModel */ protected $date; - /** - * FileRevision constructor. - * @param array $data - */ public function __construct(array $data = []) { parent::__construct($data); - $this->id = (integer)$this->getDataProperty('id'); - $this->projectId = (integer)$this->getDataProperty('projectId'); - $this->restoreToRevision = (integer)$this->getDataProperty('restoreToRevision'); - $this->fileId = (integer)$this->getDataProperty('fileId'); + + $this->id = (int)$this->getDataProperty('id'); + $this->projectId = (int)$this->getDataProperty('projectId'); + $this->fileId = (int)$this->getDataProperty('fileId'); + $this->restoreToRevision = $this->getDataProperty('restoreToRevision') + ? (int)$this->getDataProperty('restoreToRevision') + : null; $this->info = (array)$this->getDataProperty('info'); $this->date = (string)$this->getDataProperty('date'); } - /** - * @return int - */ public function getId(): int { return $this->id; } - /** - * @return int - */ public function getProjectId(): int { return $this->projectId; } - /** - * @param int $projectId - */ - public function setProjectId(int $projectId): void + public function getFileId(): int { - $this->projectId = $projectId; + return $this->fileId; } - /** - * @return array - */ - public function getInfo(): array + public function getRestoreToRevision(): ?int { - return $this->info; + return $this->restoreToRevision; } - /** - * @param array $info - */ - public function setInfo(array $info): void + public function getInfo(): array { - $this->info = $info; + return $this->info; } - /** - * @return string - */ public function getDate(): string { return $this->date; } - - /** - * @return int - */ - public function getFileId(): int - { - return $this->fileId; - } - - /** - * @return int - */ - public function getRestoreToRevision(): int - { - return $this->restoreToRevision; - } } diff --git a/tests/CrowdinApiClient/Api/Enterprise/FileApiTest.php b/tests/CrowdinApiClient/Api/Enterprise/FileApiTest.php index 2fb58eaa..55cc1503 100644 --- a/tests/CrowdinApiClient/Api/Enterprise/FileApiTest.php +++ b/tests/CrowdinApiClient/Api/Enterprise/FileApiTest.php @@ -10,50 +10,54 @@ class FileApiTest extends AbstractTestApi { - public function testBuildReviewedSourceFiles() + public function testBuildReviewedSourceFiles(): void { $params = [ - 'branchId' => 3 + 'branchId' => 3, ]; $this->mockRequest([ 'path' => '/projects/2/strings/reviewed-builds', 'method' => 'post', 'body' => json_encode($params), - 'response' => '{ - "data": { - "id": 44, - "projectId": 2, - "status": "created", - "progress":0, - "attributes": { - "branchId": 3, - "targetLanguageId": "en" - } - } - }' + 'response' => json_encode([ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'status' => 'created', + 'progress' => 0, + 'attributes' => [ + 'branchId' => 3, + 'targetLanguageId' => 'en', + ], + ], + ]), ]); $reviewedSourceFileBuild = $this->crowdin->file->buildReviewedSourceFiles(2, $params); + $this->assertInstanceOf(ReviewedSourceFileBuild::class, $reviewedSourceFileBuild); $this->assertEquals(44, $reviewedSourceFileBuild->getId()); $this->assertEquals("created", $reviewedSourceFileBuild->getStatus()); } - public function testCheckReviewedSourceFilesBuildStatus() + public function testCheckReviewedSourceFilesBuildStatus(): void { - $this->mockRequestGet('/projects/2/strings/reviewed-builds/44', '{ - "data": { - "id": 44, - "projectId": 2, - "status": "finished", - "progress":100, - "attributes": { - "branchId": 3, - "targetLanguageId": "en" - } - } - }'); + $this->mockRequestGet( + '/projects/2/strings/reviewed-builds/44', + json_encode([ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'status' => 'finished', + 'progress' => 100, + 'attributes' => [ + 'branchId' => 3, + 'targetLanguageId' => 'en', + ], + ], + ]) + ); $reviewedSourceFileBuild = $this->crowdin->file->checkReviewedSourceFilesBuildStatus(2, 44); @@ -63,36 +67,36 @@ public function testCheckReviewedSourceFilesBuildStatus() $this->assertEquals(100, $reviewedSourceFileBuild->getProgress()); } - public function testListReviewedSourceFilesBuilds() + public function testListReviewedSourceFilesBuilds(): void { $this->mockRequest([ 'path' => '/projects/2/strings/reviewed-builds', 'method' => 'get', - 'response' => '{ - "data": [ - { - "data": { - "id": 44, - "projectId": 2, - "status": "finished", - "progress":100, - "attributes": { - "branchId": 3, - "targetLanguageId": "en" - } - } - } - ], - "pagination": [ - { - "offset": 0, - "limit": 0 - } - ] - }' + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'status' => 'finished', + 'progress' => 100, + 'attributes' => [ + 'branchId' => 3, + 'targetLanguageId' => 'en', + ], + ], + ], + ], + 'pagination' => [ + [ + 'offset' => 0, + 'limit' => 0, + ], + ], + ]), ]); - $reviewedSourceBuilds = $reviewedSourceBuilds = $this->crowdin->file->listReviewedSourceFilesBuilds(2); + $reviewedSourceBuilds = $this->crowdin->file->listReviewedSourceFilesBuilds(2); $this->assertInstanceOf(ModelCollection::class, $reviewedSourceBuilds); $this->assertCount(1, $reviewedSourceBuilds); @@ -101,17 +105,24 @@ public function testListReviewedSourceFilesBuilds() $this->assertEquals(100, $reviewedSourceBuilds[0]->getProgress()); } - public function testDownloadReviewedSourceFiles() + public function testDownloadReviewedSourceFiles(): void { - $this->mockRequestGet('/projects/2/strings/reviewed-builds/44/download', '{ - "data": { - "url": "https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62", - "expireIn": "2019-09-20T10:31:21+00:00" - } - }'); + $this->mockRequestGet( + '/projects/2/strings/reviewed-builds/44/download', + json_encode([ + 'data' => [ + 'url' => 'https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff', + 'expireIn' => '2019-09-20T10:31:21+00:00', + ], + ]) + ); $downloadFile = $this->crowdin->file->downloadReviewedSourceFiles(2, 44); + $this->assertInstanceOf(DownloadFile::class, $downloadFile); - $this->assertEquals('https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62', $downloadFile->getUrl()); + $this->assertEquals( + 'https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff', + $downloadFile->getUrl() + ); } } diff --git a/tests/CrowdinApiClient/Api/FileApiTest.php b/tests/CrowdinApiClient/Api/FileApiTest.php index 80505608..c915c831 100644 --- a/tests/CrowdinApiClient/Api/FileApiTest.php +++ b/tests/CrowdinApiClient/Api/FileApiTest.php @@ -10,53 +10,50 @@ class FileApiTest extends AbstractTestApi { - public function testList() + public function testList(): void { $this->mockRequest([ 'path' => '/projects/2/files', 'method' => 'get', - 'response' => '{ - "data": [ - { - "data": { - "id": 44, - "projectId": 2, - "branchId": 34, - "directoryId": 4, - "name": "umbrella_app.xliff", - "title": "source_app_info", - "type": "xliff", - "path": "/directory1/directory2/filename.extension", - "status": "active", - "revisionId": 1, - "priority": "normal", - "importOptions": { - "firstLineContainsHeader": false, - "importTranslations": true, - "scheme": { - "identifier": 0, - "sourcePhrase": 1, - "en": 2, - "de": 3 - } - }, - "exportOptions": { - "exportPattern": "/localization/%locale%/%file_name%.%file_extension%" - }, - "excludedTargetLanguages": [ - "es", - "pl" + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 4, + 'name' => 'umbrella_app.xliff', + 'title' => 'source_app_info', + 'type' => 'xliff', + 'path' => '/directory1/directory2/filename.extension', + 'status' => 'active', + 'revisionId' => 1, + 'priority' => 'normal', + 'importOptions' => [ + 'firstLineContainsHeader' => false, + 'importTranslations' => true, + 'scheme' => [ + 'identifier' => 0, + 'sourcePhrase' => 1, + 'en' => 2, + 'de' => 3, + ], + ], + 'exportOptions' => [ + 'exportPattern' => '/localization/%locale%/%file_name%.%file_extension%', + ], + 'excludedTargetLanguages' => ['es', 'pl'], + 'createdAt' => '2019-09-19T15:10:43+00:00', + 'updatedAt' => '2019-09-19T15:10:46+00:00', + ], ], - "createdAt": "2019-09-19T15:10:43+00:00", - "updatedAt": "2019-09-19T15:10:46+00:00" - } - } - ], - "pagination": { - "offset": 0, - "limit": 25 - } - }' + ], + 'pagination' => [ + 'offset' => 0, + 'limit' => 25, + ], + ]), ]); $files = $this->crowdin->file->list(2); @@ -67,42 +64,42 @@ public function testList() $this->assertEquals(44, $files[0]->getId()); } - public function testGetAndEdit() + public function testGetAndEdit(): void { - $this->mockRequestGet('/projects/2/files/44', '{ - "data": { - "id": 44, - "projectId": 2, - "branchId": 34, - "directoryId": 4, - "name": "umbrella_app.xliff", - "title": "source_app_info", - "type": "xliff", - "path": "/directory1/directory2/filename.extension", - "status": "active", - "revisionId": 1, - "priority": "normal", - "importOptions": { - "firstLineContainsHeader": false, - "importTranslations": true, - "scheme": { - "identifier": 0, - "sourcePhrase": 1, - "en": 2, - "de": 3 - } - }, - "exportOptions": { - "exportPattern": "/localization/%locale%/%file_name%.%file_extension%" - }, - "excludedTargetLanguages": [ - "es", - "pl" - ], - "createdAt": "2019-09-19T15:10:43+00:00", - "updatedAt": "2019-09-19T15:10:46+00:00" - } - }'); + $this->mockRequestGet( + '/projects/2/files/44', + json_encode([ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 4, + 'name' => 'umbrella_app.xliff', + 'title' => 'source_app_info', + 'type' => 'xliff', + 'path' => '/directory1/directory2/filename.extension', + 'status' => 'active', + 'revisionId' => 1, + 'priority' => 'normal', + 'importOptions' => [ + 'firstLineContainsHeader' => false, + 'importTranslations' => true, + 'scheme' => [ + 'identifier' => 0, + 'sourcePhrase' => 1, + 'en' => 2, + 'de' => 3, + ], + ], + 'exportOptions' => [ + 'exportPattern' => '/localization/%locale%/%file_name%.%file_extension%', + ], + 'excludedTargetLanguages' => ['es', 'pl'], + 'createdAt' => '2019-09-19T15:10:43+00:00', + 'updatedAt' => '2019-09-19T15:10:46+00:00', + ], + ]) + ); $file = $this->crowdin->file->get(2, 44); @@ -115,41 +112,40 @@ public function testGetAndEdit() $file->setTitle('source_app_info edit'); $file->setExcludedTargetLanguages(['bg', 'es', 'pl']); - $this->mockRequestPatch('/projects/2/files/44', '{ - "data": { - "id": 44, - "projectId": 2, - "branchId": 34, - "directoryId": 4, - "name": "umbrella_app.xliff", - "title": "source_app_info edit", - "type": "xliff", - "path": "/directory1/directory2/filename.extension", - "status": "active", - "revisionId": 1, - "priority": "normal", - "importOptions": { - "firstLineContainsHeader": false, - "importTranslations": true, - "scheme": { - "identifier": 0, - "sourcePhrase": 1, - "en": 2, - "de": 3 - } - }, - "exportOptions": { - "exportPattern": "/localization/%locale%/%file_name%.%file_extension%" - }, - "excludedTargetLanguages": [ - "bg", - "es", - "pl" + $this->mockRequestPatch( + '/projects/2/files/44', + json_encode([ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 4, + 'name' => 'umbrella_app.xliff', + 'title' => 'source_app_info edit', + 'type' => 'xliff', + 'path' => '/directory1/directory2/filename.extension', + 'status' => 'active', + 'revisionId' => 1, + 'priority' => 'normal', + 'importOptions' => [ + 'firstLineContainsHeader' => false, + 'importTranslations' => true, + 'scheme' => [ + 'identifier' => 0, + 'sourcePhrase' => 1, + 'en' => 2, + 'de' => 3, + ], + ], + 'exportOptions' => [ + 'exportPattern' => '/localization/%locale%/%file_name%.%file_extension%', + ], + 'excludedTargetLanguages' => ['bg', 'es', 'pl'], + 'createdAt' => '2019-09-19T15:10:43+00:00', + 'updatedAt' => '2019-09-19T15:10:46+00:00', ], - "createdAt": "2019-09-19T15:10:43+00:00", - "updatedAt": "2019-09-19T15:10:46+00:00" - } - }'); + ]) + ); $file = $this->crowdin->file->edit($file); @@ -157,42 +153,42 @@ public function testGetAndEdit() $this->assertEquals(['bg', 'es', 'pl'], $file->getExcludedTargetLanguages()); } - public function testUpdate() + public function testUpdate(): void { - $this->mockRequestPut('/projects/2/files/44', '{ - "data": { - "id": 44, - "projectId": 2, - "branchId": 34, - "directoryId": 4, - "name": "umbrella_app.xliff", - "title": "source_app_info", - "type": "xliff", - "path": "/directory1/directory2/filename.extension", - "status": "active", - "revisionId": 2, - "priority": "normal", - "importOptions": { - "firstLineContainsHeader": false, - "importTranslations": true, - "scheme": { - "identifier": 0, - "sourcePhrase": 1, - "en": 2, - "de": 3 - } - }, - "exportOptions": { - "exportPattern": "/localization/%locale%/%file_name%.%file_extension%" - }, - "excludedTargetLanguages": [ - "es", - "pl" - ], - "createdAt": "2019-09-19T15:10:43+00:00", - "updatedAt": "2019-09-19T15:10:46+00:00" - } - }'); + $this->mockRequestPut( + '/projects/2/files/44', + json_encode([ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 4, + 'name' => 'umbrella_app.xliff', + 'title' => 'source_app_info', + 'type' => 'xliff', + 'path' => '/directory1/directory2/filename.extension', + 'status' => 'active', + 'revisionId' => 2, + 'priority' => 'normal', + 'importOptions' => [ + 'firstLineContainsHeader' => false, + 'importTranslations' => true, + 'scheme' => [ + 'identifier' => 0, + 'sourcePhrase' => 1, + 'en' => 2, + 'de' => 3, + ], + ], + 'exportOptions' => [ + 'exportPattern' => '/localization/%locale%/%file_name%.%file_extension%', + ], + 'excludedTargetLanguages' => ['es', 'pl'], + 'createdAt' => '2019-09-19T15:10:43+00:00', + 'updatedAt' => '2019-09-19T15:10:46+00:00', + ], + ]) + ); $file = $this->crowdin->file->update(2, 44, ['storageId' => 1]); @@ -200,51 +196,50 @@ public function testUpdate() $this->assertEquals(2, $file->getRevisionId()); } - public function testRestore() + public function testRestore(): void { - $this->mockRequestPut('/projects/2/files/44', '{ - "data": { - "id": 44, - "projectId": 2, - "branchId": 34, - "directoryId": 4, - "name": "umbrella_app.xliff", - "title": "source_app_info", - "type": "xliff", - "path": "/directory1/directory2/filename.extension", - "status": "active", - "revisionId": 19, - "priority": "normal", - "importOptions": { - "firstLineContainsHeader": false, - "importTranslations": true, - "scheme": { - "identifier": 0, - "sourcePhrase": 1, - "en": 2, - "de": 3 - } - }, - "exportOptions": { - "exportPattern": "/localization/%locale%/%file_name%.%file_extension%" - }, - "excludedTargetLanguages": [ - "en", - "es", - "pl" - ], - "createdAt": "2019-09-19T15:10:43+00:00", - "updatedAt": "2019-09-19T15:10:46+00:00" - } - }'); + $this->mockRequestPut( + '/projects/2/files/44', + json_encode([ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 4, + 'name' => 'umbrella_app.xliff', + 'title' => 'source_app_info', + 'type' => 'xliff', + 'path' => '/directory1/directory2/filename.extension', + 'status' => 'active', + 'revisionId' => 19, + 'priority' => 'normal', + 'importOptions' => [ + 'firstLineContainsHeader' => false, + 'importTranslations' => true, + 'scheme' => [ + 'identifier' => 0, + 'sourcePhrase' => 1, + 'en' => 2, + 'de' => 3, + ], + ], + 'exportOptions' => [ + 'exportPattern' => '/localization/%locale%/%file_name%.%file_extension%', + ], + 'excludedTargetLanguages' => ['en', 'es', 'pl'], + 'createdAt' => '2019-09-19T15:10:43+00:00', + 'updatedAt' => '2019-09-19T15:10:46+00:00', + ], + ]) + ); - $file = $this->crowdin->file->update(2, 44, ['storageId' => 1]); + $file = $this->crowdin->file->restore(2, 44, ['storageId' => 1]); $this->assertInstanceOf(File::class, $file); $this->assertEquals(19, $file->getRevisionId()); } - public function testCreate() + public function testCreate(): void { $params = [ 'storageId' => 61, @@ -254,234 +249,251 @@ public function testCreate() 'title' => 'source_app_info', 'context' => 'Context for translators', 'type' => 'xliff', - 'importOptions' => - [ - 'firstLineContainsHeader' => true, - 'scheme' => - [ - 'identifier' => 0, - 'sourcePhrase' => 1, - 'en' => 2, - 'de' => 3, - ], - ], - 'exportOptions' => - [ - 'escapeQuotes' => 3, + 'importOptions' => [ + 'firstLineContainsHeader' => true, + 'scheme' => [ + 'identifier' => 0, + 'sourcePhrase' => 1, + 'en' => 2, + 'de' => 3, ], - 'excludedTargetLanguages' => ['bg'] + ], + 'exportOptions' => [ + 'escapeQuotes' => 3, + ], + 'excludedTargetLanguages' => ['bg'], ]; $this->mockRequest([ 'path' => '/projects/2/files', 'method' => 'post', 'body' => json_encode($params), - 'response' => '{ - "data": { - "id": 44, - "projectId": 2, - "branchId": 34, - "directoryId": 4, - "name": "umbrella_app.xliff", - "title": "source_app_info", - "context": "Context for translators", - "type": "xliff", - "path": "/directory1/directory2/filename.extension", - "status": "active", - "revisionId": 1, - "priority": "normal", - "importOptions": { - "firstLineContainsHeader": false, - "importTranslations": true, - "scheme": { - "identifier": 0, - "sourcePhrase": 1, - "en": 2, - "de": 3 - } - }, - "exportOptions": { - "exportPattern": "/localization/%locale%/%file_name%.%file_extension%" - }, - "excludedTargetLanguages": [ - "bg" + 'response' => json_encode([ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 4, + 'name' => 'umbrella_app.xliff', + 'title' => 'source_app_info', + 'context' => 'Context for translators', + 'type' => 'xliff', + 'path' => '/directory1/directory2/filename.extension', + 'status' => 'active', + 'revisionId' => 1, + 'priority' => 'normal', + 'importOptions' => [ + 'firstLineContainsHeader' => false, + 'importTranslations' => true, + 'scheme' => [ + 'identifier' => 0, + 'sourcePhrase' => 1, + 'en' => 2, + 'de' => 3, + ], + ], + 'exportOptions' => [ + 'exportPattern' => '/localization/%locale%/%file_name%.%file_extension%', + ], + 'excludedTargetLanguages' => ['bg'], + 'createdAt' => '2019-09-19T15:10:43+00:00', + 'updatedAt' => '2019-09-19T15:10:46+00:00', ], - "createdAt": "2019-09-19T15:10:43+00:00", - "updatedAt": "2019-09-19T15:10:46+00:00" - } - }' + ]), ]); $file = $this->crowdin->file->create(2, $params); + $this->assertInstanceOf(File::class, $file); $this->assertEquals(44, $file->getId()); $this->assertEquals(["bg"], $file->getExcludedTargetLanguages()); } - public function testDelete() + public function testDelete(): void { $this->mockRequestDelete('/projects/2/files/44'); $this->crowdin->file->delete(2, 44); } - public function testDownloadPreview() + public function testDownloadPreview(): void { - $this->mockRequestGet('/projects/2/files/44/preview', '{ - "data": { - "url": "https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62", - "expireIn": "2019-09-20T10:31:21+00:00" - } - }'); + $this->mockRequestGet( + '/projects/2/files/44/preview', + json_encode([ + 'data' => [ + 'url' => 'https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff', + 'expireIn' => '2019-09-20T10:31:21+00:00', + ], + ]) + ); $downloadFilePreview = $this->crowdin->file->downloadPreview(2, 44); + $this->assertInstanceOf(DownloadFilePreview::class, $downloadFilePreview); - $this->assertEquals('https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62', $downloadFilePreview->getUrl()); + $this->assertEquals( + 'https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff', + $downloadFilePreview->getUrl() + ); } - public function testDownload() + public function testDownload(): void { - $this->mockRequestGet('/projects/2/files/44/download', '{ - "data": { - "url": "https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62", - "expireIn": "2019-09-20T10:31:21+00:00" - } - }'); + $this->mockRequestGet( + '/projects/2/files/44/download', + json_encode([ + 'data' => [ + 'url' => 'https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff', + 'expireIn' => '2019-09-20T10:31:21+00:00', + ], + ]) + ); $downloadFile = $this->crowdin->file->download(2, 44); + $this->assertInstanceOf(DownloadFile::class, $downloadFile); - $this->assertEquals('https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62', $downloadFile->getUrl()); + $this->assertEquals( + 'https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff', + $downloadFile->getUrl() + ); } - public function testListRevisions() + public function testListRevisions(): void { - $this->mockRequestGet('/projects/2/files/44/revisions', '{ - "data": [ - { - "data": { - "id": 16, - "projectId": 2, - "revision": 2, - "revertTo": 0, - "translationChunks": 1, - "info": { - "added": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "deleted": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "changed": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "updated": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "translated": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "approved": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "addedToTranslate": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - } - }, - "date": "2019-09-20T09:08:16+00:00" - } - } - ], - "pagination": [ - { - "offset": 0, - "limit": 0 - } - ] - }'); + $this->mockRequestGet( + '/projects/2/files/44/revisions', + json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 16, + 'projectId' => 2, + 'revision' => 2, + 'revertTo' => 0, + 'translationChunks' => 1, + 'info' => [ + 'added' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'deleted' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'changed' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'updated' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'translated' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'approved' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'addedToTranslate' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + ], + 'date' => '2019-09-20T09:08:16+00:00', + ], + ], + ], + 'pagination' => [ + [ + 'offset' => 0, + 'limit' => 0, + ], + ], + ]) + ); $revisions = $this->crowdin->file->revisions(2, 44); + $this->assertInstanceOf(ModelCollection::class, $revisions); $this->assertCount(1, $revisions); $this->assertInstanceOf(FileRevision::class, $revisions[0]); $this->assertEquals(16, $revisions[0]->getId()); } - public function testGetRevision() + public function testGetRevision(): void { - $this->mockRequestGet('/projects/2/files/44/revisions/16', '{ - "data": { - "id": 16, - "projectId": 2, - "revision": 2, - "revertTo": 0, - "translationChunks": 1, - "info": { - "added": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "deleted": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "changed": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "updated": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "translated": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "approved": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - }, - "addedToTranslate": { - "strings": 17, - "words": 43, - "chars": 242, - "charsWithSpaces": 268 - } - }, - "date": "2019-09-20T09:08:16+00:00" - } - }'); + $this->mockRequestGet( + '/projects/2/files/44/revisions/16', + json_encode([ + 'data' => [ + 'id' => 16, + 'projectId' => 2, + 'revision' => 2, + 'revertTo' => 0, + 'translationChunks' => 1, + 'info' => [ + 'added' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'deleted' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'changed' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'updated' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'translated' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'approved' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + 'addedToTranslate' => [ + 'strings' => 17, + 'words' => 43, + 'chars' => 242, + 'charsWithSpaces' => 268, + ], + ], + 'date' => '2019-09-20T09:08:16+00:00', + ], + ]) + ); $fileRevision = $this->crowdin->file->getRevision(2, 44, 16); diff --git a/tests/CrowdinApiClient/Model/FileRevisionTest.php b/tests/CrowdinApiClient/Model/FileRevisionTest.php index d9eeffaf..c42da2f8 100644 --- a/tests/CrowdinApiClient/Model/FileRevisionTest.php +++ b/tests/CrowdinApiClient/Model/FileRevisionTest.php @@ -7,11 +7,6 @@ class FileRevisionTest extends TestCase { - /** - * @var FileRevision - */ - public $fileRevision; - /** * @var array */ @@ -19,36 +14,33 @@ class FileRevisionTest extends TestCase 'id' => 2, 'projectId' => 2, 'fileId' => 248, - 'restoreToRevision' => 0, - 'info' => - [ - 'added' => - [ - 'strings' => 17, - 'words' => 43, - ], - 'deleted' => - [ - 'strings' => 17, - 'words' => 43, - ], - 'updated' => - [ - 'strings' => 17, - 'words' => 43, - ], + 'restoreToRevision' => null, + 'info' => [ + 'added' => [ + 'strings' => 17, + 'words' => 43, ], + 'deleted' => [ + 'strings' => 17, + 'words' => 43, + ], + 'updated' => [ + 'strings' => 17, + 'words' => 43, + ], + ], 'date' => '2019-09-20T09:08:16+00:00', ]; - public function testLoadData() + public function testLoadData(): void { - $this->fileRevision = new FileRevision($this->data); - $this->assertEquals($this->data['id'], $this->fileRevision->getId()); - $this->assertEquals($this->data['projectId'], $this->fileRevision->getProjectId()); - $this->assertEquals($this->data['fileId'], $this->fileRevision->getFileId()); - $this->assertEquals($this->data['restoreToRevision'], $this->fileRevision->getRestoreToRevision()); - $this->assertEquals($this->data['info'], $this->fileRevision->getInfo()); - $this->assertEquals($this->data['date'], $this->fileRevision->getDate()); + $fileRevision = new FileRevision($this->data); + + $this->assertEquals($this->data['id'], $fileRevision->getId()); + $this->assertEquals($this->data['projectId'], $fileRevision->getProjectId()); + $this->assertEquals($this->data['fileId'], $fileRevision->getFileId()); + $this->assertEquals($this->data['restoreToRevision'], $fileRevision->getRestoreToRevision()); + $this->assertEquals($this->data['info'], $fileRevision->getInfo()); + $this->assertEquals($this->data['date'], $fileRevision->getDate()); } }