Skip to content

Commit

Permalink
feat: translation context field to Files API (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
misantron authored Oct 20, 2023
1 parent 35cdc78 commit de1d058
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/CrowdinApiClient/Api/FileApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function list(int $projectId, array $params = []): ModelCollection
* integer $data[branchId] Can't be used with directoryId in same request<br>
* integer $data[directoryId] Can't be used with branchId in same request<br>
* string $data[title]<br>
* string $data[context]<br>
* string $data[type]<br>
* array $data[importOptions]<br>
* array $data[exportOptions]
Expand Down
22 changes: 22 additions & 0 deletions src/CrowdinApiClient/Model/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class File extends BaseModel
*/
protected $title;

/**
* @var string
*/
protected $context;

/**
* @var string
*/
Expand Down Expand Up @@ -97,6 +102,7 @@ public function __construct(array $data = [])
$this->directoryId = (integer)$this->getDataProperty('directoryId');
$this->name = (string)$this->getDataProperty('name');
$this->title = (string)$this->getDataProperty('title');
$this->context = (string)$this->getDataProperty('context');
$this->type = (string)$this->getDataProperty('type');
$this->path = (string)$this->getDataProperty('path');
$this->revisionId = (integer)$this->getDataProperty('revisionId');
Expand Down Expand Up @@ -189,6 +195,22 @@ public function setTitle(string $title): void
$this->title = $title;
}

/**
* @return string
*/
public function getContext(): string
{
return $this->context;
}

/**
* @param string $context
*/
public function setContext(string $context): void
{
$this->context = $context;
}

/**
* @return string
*/
Expand Down
7 changes: 3 additions & 4 deletions tests/CrowdinApiClient/Api/FileApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
*/
class FileApiTest extends AbstractTestApi
{
/**
* @test
*/
public function testList()
{
$this->mockRequest([
Expand Down Expand Up @@ -66,7 +63,7 @@ public function testList()
}'
]);

$files = $files = $this->crowdin->file->list(2);
$files = $this->crowdin->file->list(2);

$this->assertInstanceOf(ModelCollection::class, $files);
$this->assertCount(1, $files);
Expand Down Expand Up @@ -259,6 +256,7 @@ public function testCreate()
'branchId' => 34,
'directoryId' => 4,
'title' => 'source_app_info',
'context' => 'Context for translators',
'type' => 'xliff',
'importOptions' =>
[
Expand Down Expand Up @@ -290,6 +288,7 @@ public function testCreate()
"directoryId": 4,
"name": "umbrella_app.xliff",
"title": "source_app_info",
"context": "Context for translators",
"type": "xliff",
"path": "/directory1/directory2/filename.extension",
"status": "active",
Expand Down
10 changes: 7 additions & 3 deletions tests/CrowdinApiClient/Model/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FileTest extends TestCase
'directoryId' => 4,
'name' => 'umbrella_app.xliff',
'title' => 'source_app_info',
'context' => 'Context for translators',
'type' => 'xliff',
'path' => '/someBranch/someDir/umbrella_app.xliff',
'revisionId' => 1,
Expand Down Expand Up @@ -54,19 +55,20 @@ class FileTest extends TestCase
'updatedAt' => '2019-09-19T15:10:46+00:00',
];

public function testLoadData()
public function testLoadData(): void
{
$this->file = new File($this->data);
$this->checkData();
}

public function testSetData()
public function testSetData(): void
{
$this->file = new File();
$this->file->setBranchId($this->data['branchId']);
$this->file->setDirectoryId($this->data['directoryId']);
$this->file->setName($this->data['name']);
$this->file->setTitle($this->data['title']);
$this->file->setContext($this->data['context']);
$this->file->setPriority($this->data['priority']);
$this->file->setImportOptions($this->data['importOptions']);
$this->file->setExportOptions($this->data['exportOptions']);
Expand All @@ -76,20 +78,22 @@ public function testSetData()
$this->assertEquals($this->data['directoryId'], $this->file->getDirectoryId());
$this->assertEquals($this->data['name'], $this->file->getName());
$this->assertEquals($this->data['title'], $this->file->getTitle());
$this->assertEquals($this->data['context'], $this->file->getContext());
$this->assertEquals($this->data['priority'], $this->file->getPriority());
$this->assertEquals($this->data['importOptions'], $this->file->getImportOptions());
$this->assertEquals($this->data['exportOptions'], $this->file->getExportOptions());
$this->assertEquals($this->data['excludedTargetLanguages'], $this->file->getExcludedTargetLanguages());
}

public function checkData()
public function checkData(): void
{
$this->assertEquals($this->data['id'], $this->file->getId());
$this->assertEquals($this->data['projectId'], $this->file->getProjectId());
$this->assertEquals($this->data['branchId'], $this->file->getBranchId());
$this->assertEquals($this->data['directoryId'], $this->file->getDirectoryId());
$this->assertEquals($this->data['name'], $this->file->getName());
$this->assertEquals($this->data['title'], $this->file->getTitle());
$this->assertEquals($this->data['context'], $this->file->getContext());
$this->assertEquals($this->data['type'], $this->file->getType());
$this->assertEquals($this->data['path'], $this->file->getPath());
$this->assertEquals($this->data['revisionId'], $this->file->getRevisionId());
Expand Down

0 comments on commit de1d058

Please sign in to comment.