You are here

public function LingotekUnitTest::testGetDocumentTranslationStatus in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  2. 4.0.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  3. 3.0.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  4. 3.1.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  5. 3.2.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  6. 3.3.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  7. 3.4.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  8. 3.5.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  9. 3.6.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  10. 3.7.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()
  11. 3.8.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testGetDocumentTranslationStatus()

@covers ::getDocumentTranslationStatus

File

tests/src/Unit/LingotekUnitTest.php, line 539

Class

LingotekUnitTest
@coversDefaultClass \Drupal\lingotek\Lingotek @group lingotek @preserveGlobalState disabled

Namespace

Drupal\Tests\lingotek\Unit

Code

public function testGetDocumentTranslationStatus() {
  $response = $this
    ->getMockBuilder('\\Psr\\Http\\Message\\ResponseInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $response
    ->expects($this
    ->any())
    ->method('getStatusCode')
    ->willReturn(Response::HTTP_OK);
  $response
    ->expects($this
    ->any())
    ->method('getBody')
    ->willReturn(json_encode([
    'entities' => [
      [
        'properties' => [
          'locale_code' => 'es-ES',
          'percent_complete' => 100,
        ],
      ],
      [
        'properties' => [
          'locale_code' => 'de-DE',
          'percent_complete' => 50,
        ],
      ],
    ],
  ]));
  $this->api
    ->expects($this
    ->at(0))
    ->method('getDocumentTranslationStatus')
    ->with('my_doc_id', 'es_ES')
    ->will($this
    ->returnValue($response));
  $this->api
    ->expects($this
    ->at(1))
    ->method('getDocumentTranslationStatus')
    ->with('my_doc_id', 'de_DE')
    ->will($this
    ->returnValue($response));
  $this->api
    ->expects($this
    ->at(2))
    ->method('getDocumentTranslationStatus')
    ->with('my_doc_id', 'ca_ES')
    ->will($this
    ->returnValue($response));

  // Assert that a complete translation is reported as completed.
  $result = $this->lingotek
    ->getDocumentTranslationStatus('my_doc_id', 'es_ES');
  $this
    ->assertEquals(TRUE, $result);

  // Assert that an incomplete translation is reported as not completed.
  $result = $this->lingotek
    ->getDocumentTranslationStatus('my_doc_id', 'de_DE');
  $this
    ->assertEquals(FALSE, $result);

  // Assert that an unrequested translation is reported as not completed.
  $result = $this->lingotek
    ->getDocumentTranslationStatus('my_doc_id', 'ca_ES');
  $this
    ->assertEquals(FALSE, $result);
}