public function LingotekUnitTest::testUploadDocument in Lingotek Translation 8.2
Same name and namespace in other branches
- 8 tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 4.0.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.0.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.1.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.2.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.3.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.4.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.5.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.6.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.7.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
- 3.8.x tests/src/Unit/LingotekUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekUnitTest::testUploadDocument()
@covers ::uploadDocument
File
- tests/
src/ Unit/ LingotekUnitTest.php, line 414
Class
- LingotekUnitTest
- @coversDefaultClass \Drupal\lingotek\Lingotek @group lingotek @preserveGlobalState disabled
Namespace
Drupal\Tests\lingotek\UnitCode
public function testUploadDocument() {
$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([
'properties' => [
'id' => 'my-document-id',
],
]));
$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',
],
]));
// Vault id has the original value.
$this->api
->expects($this
->at(0))
->method('addDocument')
->with([
'title' => 'title',
'content' => '"content"',
'locale_code' => 'es',
'format' => 'JSON',
'project_id' => 'my_test_project',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'vault_id' => 'my_test_vault',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
])
->will($this
->returnValue($response));
// Vault id has changed.
$this->api
->expects($this
->at(1))
->method('addDocument')
->with([
'title' => 'title',
'content' => '"content"',
'locale_code' => 'es',
'format' => 'JSON',
'project_id' => 'another_test_project',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'vault_id' => 'another_test_vault',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
])
->will($this
->returnValue($response));
// If there is a profile with default vault, it must be replaced.
$this->api
->expects($this
->at(2))
->method('addDocument')
->with([
'title' => 'title',
'content' => '"content"',
'locale_code' => 'es',
'format' => 'JSON',
'project_id' => 'default_project',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'vault_id' => 'default_vault',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
])
->will($this
->returnValue($response));
// If there is no profile, vault should not be included.
$this->api
->expects($this
->at(3))
->method('addDocument')
->with([
'title' => 'title',
'content' => '"content"',
'locale_code' => 'es',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'format' => 'JSON',
'project_id' => 'default_project',
'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(4))
->method('addDocument')
->with([
'title' => 'title',
'content' => '"content"',
'locale_code' => 'es',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'format' => 'JSON',
'project_id' => 'default_project',
'external_url' => 'http://example.com/node/1',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
])
->will($this
->returnValue($response));
// If there is a profile using the project default workflow template vault,
// vault should not be specified.
$this->api
->expects($this
->at(5))
->method('addDocument')
->with([
'title' => 'title',
'content' => '"content"',
'locale_code' => 'es',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'format' => 'JSON',
'project_id' => 'default_project',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
])
->will($this
->returnValue($response));
// We upload with array of content.
$this->api
->expects($this
->at(6))
->method('addDocument')
->with([
'title' => 'title',
'content' => '{"content":"wedgiePlatypus"}',
'locale_code' => 'es',
'format' => 'JSON',
'project_id' => 'test_project',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'vault_id' => 'test_vault',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
])
->will($this
->returnValue($response));
// We upload with a job ID.
$this->api
->expects($this
->at(7))
->method('addDocument')
->with([
'title' => 'title',
'content' => '{"content":"wedgiePlatypus"}',
'locale_code' => 'es',
'format' => 'JSON',
'project_id' => 'test_project',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'vault_id' => 'test_vault',
'job_id' => 'my_job_id',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
])
->will($this
->returnValue($response));
// We upload with a profile that has a vault and a project.
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
], 'lingotek_profile');
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', NULL, $profile);
$this
->assertEquals('my-document-id', $doc_id);
// We upload with a profile that has another vault and another project.
$profile = new LingotekProfile([
'id' => 'profile2',
'project' => 'another_test_project',
'vault' => 'another_test_vault',
], 'lingotek_profile');
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', NULL, $profile);
$this
->assertEquals('my-document-id', $doc_id);
// We upload with a profile that has marked to use the default vault and project,
// so must be replaced.
$profile = new LingotekProfile([
'id' => 'profile2',
'project' => 'default',
'vault' => 'default',
'filter' => 'drupal_default',
], 'lingotek_profile');
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', NULL, $profile);
$this
->assertEquals('my-document-id', $doc_id);
// We upload without a profile.
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', NULL, NULL);
$this
->assertEquals('my-document-id', $doc_id);
// We upload without a profile, but with url.
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', 'http://example.com/node/1', NULL);
$this
->assertEquals('my-document-id', $doc_id);
// We upload with a profile that has marked to use the project default
// workflow template vault, so must be omitted.
$profile = new LingotekProfile([
'id' => 'profile2',
'project' => 'default',
'vault' => 'project_workflow_vault',
'filter' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
], 'lingotek_profile');
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', NULL, $profile);
$this
->assertEquals('my-document-id', $doc_id);
// We upload with content as an array.
$profile = new LingotekProfile([
'id' => 'profile0',
'project' => 'test_project',
'vault' => 'test_vault',
], 'lingotek_profile');
$doc_id = $this->lingotek
->uploadDocument('title', [
'content' => 'wedgiePlatypus',
], 'es', NULL, $profile);
$this
->assertEquals('my-document-id', $doc_id);
// We upload with a job ID.
$doc_id = $this->lingotek
->uploadDocument('title', [
'content' => 'wedgiePlatypus',
], 'es', NULL, $profile, 'my_job_id');
$this
->assertEquals('my-document-id', $doc_id);
}