You are here

public function LingotekUnitTest::testUpdateDocumentBC in Lingotek Translation 8.2

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

@covers ::updateDocument

File

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

Class

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

Namespace

Drupal\Tests\lingotek\Unit

Code

public function testUpdateDocumentBC() {
  $response = $this
    ->getMockBuilder(ResponseInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $response
    ->expects($this
    ->any())
    ->method('getStatusCode')
    ->willReturn(Response::HTTP_ACCEPTED);
  $response
    ->expects($this
    ->any())
    ->method('getBody')
    ->willReturn(json_encode([]));
  $this->lingotekFilterManager
    ->expects($this
    ->any())
    ->method('getFilterId')
    ->willReturn('4f91482b-5aa1-4a4a-a43f-712af7b39625');
  $this->lingotekFilterManager
    ->expects($this
    ->any())
    ->method('getSubfilterId')
    ->willReturn('0e79f34d-f27b-4a0c-880e-cd9181a5d265');
  $this->config
    ->expects($this
    ->any())
    ->method('get')
    ->will($this
    ->returnValueMap([
    [
      'default.project',
      'default_project',
    ],
    [
      'default.vault',
      'default_vault',
    ],
  ]));

  // Simplest update.
  $this->api
    ->expects($this
    ->at(0))
    ->method('patchDocument')
    ->with('my_doc_id', [
    'format' => 'JSON',
    'content' => '"content"',
    'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
    'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
    'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
  ])
    ->will($this
    ->returnValue($response));

  // If there is an url, it should be included.
  $this->api
    ->expects($this
    ->at(1))
    ->method('patchDocument')
    ->with('my_doc_id', [
    'format' => 'JSON',
    'content' => '"content"',
    'external_url' => 'http://example.com/node/1',
    'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
    'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
    'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
  ])
    ->will($this
    ->returnValue($response));

  // If there is a title, it should be included.
  $this->api
    ->expects($this
    ->at(2))
    ->method('patchDocument')
    ->with('my_doc_id', [
    'format' => 'JSON',
    'content' => '"content"',
    'title' => 'title',
    'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
    'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
    'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
  ])
    ->will($this
    ->returnValue($response));

  // If there is an url and a title, they should be included.
  $this->api
    ->expects($this
    ->at(3))
    ->method('patchDocument')
    ->with('my_doc_id', [
    'format' => 'JSON',
    'content' => '"content"',
    'external_url' => 'http://example.com/node/1',
    'title' => 'title',
    'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
    'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
    'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
  ])
    ->will($this
    ->returnValue($response));

  // The content is an array.
  $this->api
    ->expects($this
    ->at(4))
    ->method('patchDocument')
    ->with('my_doc_id', [
    'format' => 'JSON',
    'content' => '{"content":"wedgiePlatypus"}',
    'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
    'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
    'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
  ])
    ->will($this
    ->returnValue($response));

  // The call includes a job_id and a profile.
  $this->api
    ->expects($this
    ->at(5))
    ->method('patchDocument')
    ->with('my_doc_id', [
    'format' => 'JSON',
    'content' => '"content"',
    'title' => 'title',
    'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
    'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
    'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
    'job_id' => 'my_job_id',
  ])
    ->will($this
    ->returnValue($response));
  $this->api
    ->expects($this
    ->at(6))
    ->method('patchDocument')
    ->with('my_doc_id', [
    'job_id' => 'my_job_id',
  ])
    ->will($this
    ->returnValue($response));

  // Simplest update.
  $this->lingotek
    ->updateDocument('my_doc_id', 'content');

  // If there is an url, it should be included.
  $this->lingotek
    ->updateDocument('my_doc_id', 'content', 'http://example.com/node/1');

  // If there is a title, it should be included.
  $this->lingotek
    ->updateDocument('my_doc_id', 'content', NULL, 'title');

  // If there is an url and a title, they should be included.
  $this->lingotek
    ->updateDocument('my_doc_id', 'content', 'http://example.com/node/1', 'title');

  // The content is an array.
  $this->lingotek
    ->updateDocument('my_doc_id', [
    'content' => 'wedgiePlatypus',
  ]);

  // We upload with a profile and a job ID.
  $profile = new LingotekProfile([
    'id' => 'profile0',
    'project' => 'test_project',
    'vault' => 'test_vault',
  ], 'lingotek_profile');
  $this->lingotek
    ->updateDocument('my_doc_id', 'content', NULL, 'title', $profile, 'my_job_id');

  // Only update Job ID.
  $this->lingotek
    ->updateDocument('my_doc_id', NULL, NULL, NULL, $profile, 'my_job_id');
}