You are here

public function BatchApiTest::testUploadBatchFile in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.3 vendor/smartling/api-sdk-php/tests/unit/BatchApiTest.php \Smartling\Tests\Unit\BatchApiTest::testUploadBatchFile()

@covers \Smartling\Batch\BatchApi::uploadBatchFile

File

vendor/smartling/api-sdk-php/tests/unit/BatchApiTest.php, line 93

Class

BatchApiTest
Test class for Smartling\Batch\BatchApi.

Namespace

Smartling\Tests\Unit

Code

public function testUploadBatchFile() {
  $batchId = 'test_batch_id';
  $localesToApprove = 'fr-FR';
  $fileRealPath = realpath(__DIR__ . '/../resources/test.xml');
  $fileUri = 'test-file-uri.xml';
  $extension = 'xml';
  $params = new UploadFileParameters();
  $params
    ->setLocalesToApprove($localesToApprove);
  $endpointUrl = vsprintf('%s/%s/batches/%s/file', [
    BatchApi::ENDPOINT_URL,
    $this->projectId,
    $batchId,
  ]);
  $this->client
    ->expects(self::once())
    ->method('request')
    ->with('post', $endpointUrl, [
    'headers' => [
      'Accept' => 'application/json',
      'Authorization' => vsprintf('%s %s', [
        $this->authProvider
          ->getTokenType(),
        $this->authProvider
          ->getAccessToken(),
      ]),
    ],
    'exceptions' => FALSE,
    'multipart' => [
      [
        'name' => 'authorize',
        'contents' => 0,
      ],
      [
        'name' => 'smartling.client_lib_id',
        'contents' => json_encode([
          'client' => BatchApi::CLIENT_LIB_ID_SDK,
          'version' => BatchApi::CLIENT_LIB_ID_VERSION,
        ], JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE),
      ],
      [
        'name' => 'localeIdsToAuthorize[]',
        'contents' => $localesToApprove,
      ],
      [
        'name' => 'file',
        'contents' => $this->streamPlaceholder,
      ],
      [
        'name' => 'fileUri',
        'contents' => $fileUri,
      ],
      [
        'name' => 'fileType',
        'contents' => $extension,
      ],
    ],
  ])
    ->willReturn($this->responseMock);
  $this->object
    ->uploadBatchFile($fileRealPath, $fileUri, $extension, $batchId, $params);
}