You are here

public function FileApiTest::testDownloadFile in TMGMT Translator Smartling 8.2

Same name in this branch
  1. 8.2 api-sdk-php/tests/unit/FileApiTest.php \Smartling\Tests\Unit\FileApiTest::testDownloadFile()
  2. 8.2 vendor/smartling/api-sdk-php/tests/unit/FileApiTest.php \Smartling\Tests\Unit\FileApiTest::testDownloadFile()
Same name and namespace in other branches
  1. 8.4 vendor/smartling/api-sdk-php/tests/unit/FileApiTest.php \Smartling\Tests\Unit\FileApiTest::testDownloadFile()
  2. 8.3 vendor/smartling/api-sdk-php/tests/unit/FileApiTest.php \Smartling\Tests\Unit\FileApiTest::testDownloadFile()

@covers \Smartling\File\FileApi::downloadFile

@dataProvider downloadFileParams

Parameters

DownloadFileParameters|null $options:

string $expected_translated_file:

File

vendor/smartling/api-sdk-php/tests/unit/FileApiTest.php, line 183

Class

FileApiTest
Test class for Smartling\File\FileApi.

Namespace

Smartling\Tests\Unit

Code

public function testDownloadFile($options, $locale, $expected_translated_file) {
  $this
    ->prepareClientResponseMock(false);
  $this->responseMock
    ->expects($this
    ->any())
    ->method('getBody')
    ->willReturn($expected_translated_file);
  $endpointUrl = vsprintf('%s/%s/locales/%s/file', [
    FileApi::ENDPOINT_URL,
    $this->projectId,
    $locale,
  ]);
  $params = $options instanceof DownloadFileParameters ? $options
    ->exportToArray() : [];
  $params['fileUri'] = 'test.xml';
  $this->client
    ->expects($this
    ->once())
    ->method('request')
    ->with('get', $endpointUrl, [
    'headers' => [
      'Authorization' => vsprintf('%s %s', [
        $this->authProvider
          ->getTokenType(),
        $this->authProvider
          ->getAccessToken(),
      ]),
    ],
    'exceptions' => false,
    'query' => $params,
  ])
    ->willReturn($this->responseMock);
  $actual_xml = $this->object
    ->downloadFile('test.xml', $locale, $options);
  $this
    ->assertEquals($expected_translated_file, $actual_xml);
}