You are here

public function LingotekUnitTest::testUpdateDocument in Lingotek Translation 8

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

@covers ::updateDocument

File

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

Class

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

Namespace

Drupal\Tests\lingotek\Unit

Code

public function testUpdateDocument() {
  $response = $this
    ->getMockBuilder('\\Psr\\Http\\Message\\ResponseInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $response
    ->expects($this
    ->any())
    ->method('getStatusCode')
    ->willReturn(Response::HTTP_ACCEPTED);
  $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',
  ])
    ->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',
  ])
    ->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',
  ])
    ->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',
  ])
    ->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');
}