You are here

public function TranslationRequestsApiTest::testUpdateTranslationRequest in TMGMT Translator Smartling 8.3

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

@covers \Smartling\TranslationRequests\TranslationRequestsApi::updateTranslationRequest

File

vendor/smartling/api-sdk-php/tests/unit/TranslationRequestsApiTest.php, line 131

Class

TranslationRequestsApiTest

Namespace

Smartling\Tests\Unit

Code

public function testUpdateTranslationRequest() {
  $translationRequestUid = '8264fd9133d3';
  $updateParams = (new UpdateTranslationRequestParams())
    ->setTitle('Submission 2');
  $testRawResponse = json_encode([
    "response" => [
      "code" => "SUCCESS",
      "data" => [
        "translationRequestUid" => $translationRequestUid,
        "projectId" => $this->projectId,
        "bucketName" => "name",
        "originalAssetId" => [
          "a" => "1",
        ],
        "title" => "Submission 2",
        "fileUri" => "/posts/hello-world_1_1_post.xml",
        "totalWordCount" => "0",
        "totalStringCount" => "0",
        "contentHash" => null,
        "originalLocaleId" => "en-US",
        "outdated" => "0",
        "customOriginalData" => null,
        "createdDate" => "2018-07-31T10:37:20.839Z",
        "modifiedDate" => "2018-07-31T10:37:20.839Z",
        "translationSubmissions" => [],
      ],
    ],
  ]);
  $this
    ->mockClientResponse(200, $testRawResponse);
  $testExpectedResponse = json_decode($testRawResponse, true)['response']['data'];
  $bucketName = 'name';
  $endpointUrl = vsprintf('%s/%s/buckets/%s/translation-requests/%s', [
    TranslationRequestsApi::ENDPOINT_URL,
    $this->projectId,
    $bucketName,
    $translationRequestUid,
  ]);
  $requestStructure = [
    'headers' => [
      'Accept' => 'application/json',
      'Authorization' => vsprintf('%s %s', [
        $this->authProvider
          ->getTokenType(),
        $this->authProvider
          ->getAccessToken(),
      ]),
    ],
    'exceptions' => false,
    'json' => $updateParams
      ->exportToArray(),
  ];
  $this->client
    ->expects(self::once())
    ->method('request')
    ->with('put', $endpointUrl, $requestStructure)
    ->willReturn($this->responseMock);
  $response = $this->object
    ->updateTranslationRequest($bucketName, $translationRequestUid, $updateParams);
  self::assertEquals($testExpectedResponse, $response);
}