View source
<?php
namespace Drupal\Tests\lingotek\Unit;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\language\ConfigurableLanguageInterface;
use Drupal\lingotek\Entity\LingotekProfile;
use Drupal\lingotek\Exception\LingotekDocumentArchivedException;
use Drupal\lingotek\Exception\LingotekDocumentLockedException;
use Drupal\lingotek\Exception\LingotekPaymentRequiredException;
use Drupal\lingotek\LanguageLocaleMapperInterface;
use Drupal\lingotek\Lingotek;
use Drupal\lingotek\LingotekConfigurationServiceInterface;
use Drupal\lingotek\LingotekFilterManagerInterface;
use Drupal\lingotek\Remote\LingotekApiInterface;
use Drupal\Tests\UnitTestCase;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Response;
class LingotekUnitTest extends UnitTestCase {
protected $lingotek;
protected $languageLocaleMapper;
protected $api;
protected $config;
protected $configEditable;
protected $configFactory;
protected $lingotekFilterManager;
protected $lingotekConfiguration;
protected function setUp() : void {
$this->api = $this
->createMock(LingotekApiInterface::class);
$this->languageLocaleMapper = $this
->createMock(LanguageLocaleMapperInterface::class);
$this->config = $this
->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$this->configEditable = $this
->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$this->lingotekFilterManager = $this
->createMock(LingotekFilterManagerInterface::class);
$this->configFactory = $this
->createMock(ConfigFactoryInterface::class);
$this->configFactory
->expects($this
->any())
->method('get')
->with('lingotek.settings')
->will($this
->returnValue($this->config));
$this->configFactory
->expects($this
->any())
->method('getEditable')
->with('lingotek.settings')
->will($this
->returnValue($this->configEditable));
$this->lingotekConfiguration = $this
->createMock(LingotekConfigurationServiceInterface::class);
$this->lingotek = new Lingotek($this->api, $this->languageLocaleMapper, $this->configFactory, $this->lingotekFilterManager, $this->lingotekConfiguration);
}
public function testGetVaultsWithData() {
$this->config
->expects($this
->once())
->method('get')
->with('account.resources.vault')
->will($this
->returnValue([
'a_vault' => 'A vault',
]));
$this->api
->expects($this
->never())
->method('getVaults');
$vaults = $this->lingotek
->getVaults(FALSE);
$this
->assertArrayEquals($vaults, [
'a_vault' => 'A vault',
]);
}
public function testGetVaultsWithNoData() {
$this->config
->expects($this
->at(0))
->method('get')
->with('account.resources.vault')
->will($this
->returnValue([]));
$this->config
->expects($this
->at(1))
->method('get')
->with('default.community')
->will($this
->returnValue([
'my_community',
]));
$this->config
->expects($this
->at(2))
->method('get')
->with('default.vault')
->will($this
->returnValue(NULL));
$this->api
->expects($this
->once())
->method('getVaults')
->will($this
->returnValue([
'a_vault' => 'A vault',
]));
$this->configEditable
->expects($this
->at(0))
->method('set')
->with('account.resources.vault', [
'a_vault' => 'A vault',
])
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(1))
->method('save');
$this->configEditable
->expects($this
->at(2))
->method('set')
->with('default.vault', 'a_vault')
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(3))
->method('save');
$vaults = $this->lingotek
->getVaults(FALSE);
$this
->assertArrayEquals($vaults, [
'a_vault' => 'A vault',
]);
}
public function testGetVaultsWithDataButForcing() {
$this->config
->expects($this
->at(0))
->method('get')
->with('account.resources.vault')
->will($this
->returnValue([
'a_vault' => 'A vault',
]));
$this->config
->expects($this
->at(1))
->method('get')
->with('default.community')
->will($this
->returnValue([
'my_community',
]));
$this->config
->expects($this
->at(2))
->method('get')
->with('default.vault')
->will($this
->returnValue(NULL));
$this->api
->expects($this
->once())
->method('getVaults')
->will($this
->returnValue([
'a_vault' => 'A vault',
]));
$this->configEditable
->expects($this
->at(0))
->method('set')
->with('account.resources.vault', [
'a_vault' => 'A vault',
])
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(1))
->method('save');
$this->configEditable
->expects($this
->at(2))
->method('set')
->with('default.vault', 'a_vault')
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(3))
->method('save');
$vaults = $this->lingotek
->getVaults(TRUE);
$this
->assertArrayEquals($vaults, [
'a_vault' => 'A vault',
]);
}
public function testGetFiltersWithData() {
$this->config
->expects($this
->once())
->method('get')
->with('account.resources.filter')
->will($this
->returnValue([
'a_filter' => 'A filter',
]));
$this->api
->expects($this
->never())
->method('getFilters');
$this->lingotek
->getFilters(FALSE);
}
public function testGetFiltersWithNoData() {
$this->config
->expects($this
->at(0))
->method('get')
->with('account.resources.filter')
->will($this
->returnValue([]));
$this->config
->expects($this
->at(1))
->method('get')
->with('default.community')
->will($this
->returnValue([
'my_community',
]));
$this->config
->expects($this
->at(2))
->method('get')
->with('default.filter')
->will($this
->returnValue(NULL));
$this->api
->expects($this
->once())
->method('getFilters')
->will($this
->returnValue([
'a_filter' => 'A filter',
]));
$this->configEditable
->expects($this
->at(0))
->method('set')
->with('account.resources.filter', [
'a_filter' => 'A filter',
])
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(1))
->method('save');
$this->configEditable
->expects($this
->at(2))
->method('set')
->with('default.filter', 'a_filter')
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(3))
->method('save');
$filters = $this->lingotek
->getFilters(FALSE);
$this
->assertArrayEquals($filters, [
'a_filter' => 'A filter',
]);
}
public function testGetFiltersWithDataButForcing() {
$this->config
->expects($this
->at(0))
->method('get')
->with('account.resources.filter')
->will($this
->returnValue([
'a_filter' => 'A filter',
]));
$this->config
->expects($this
->at(1))
->method('get')
->with('default.community')
->will($this
->returnValue([
'my_community',
]));
$this->config
->expects($this
->at(2))
->method('get')
->with('default.filter')
->will($this
->returnValue(NULL));
$this->api
->expects($this
->once())
->method('getFilters')
->will($this
->returnValue([
'a_filter' => 'A filter',
]));
$this->configEditable
->expects($this
->at(0))
->method('set')
->with('account.resources.filter', [
'a_filter' => 'A filter',
])
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(1))
->method('save');
$this->configEditable
->expects($this
->at(2))
->method('set')
->with('default.filter', 'a_filter')
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(3))
->method('save');
$filters = $this->lingotek
->getFilters(TRUE);
$this
->assertArrayEquals($filters, [
'a_filter' => 'A filter',
]);
}
public function testGetProjectsWithData() {
$this->config
->expects($this
->once())
->method('get')
->with('account.resources.project')
->will($this
->returnValue([
'a_project' => 'A project',
]));
$this->api
->expects($this
->never())
->method('getProjects');
$projects = $this->lingotek
->getProjects(FALSE);
$this
->assertArrayEquals($projects, [
'a_project' => 'A project',
]);
}
public function testGetProjectsWithNoData() {
$this->config
->expects($this
->at(0))
->method('get')
->with('account.resources.project')
->will($this
->returnValue([]));
$this->config
->expects($this
->at(1))
->method('get')
->with('default.community')
->will($this
->returnValue([
'my_community',
]));
$this->config
->expects($this
->at(2))
->method('get')
->with('default.project')
->will($this
->returnValue(NULL));
$this->api
->expects($this
->once())
->method('getProjects')
->will($this
->returnValue([
'a_project' => 'A project',
]));
$this->configEditable
->expects($this
->at(0))
->method('set')
->with('account.resources.project', [
'a_project' => 'A project',
])
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(1))
->method('save');
$this->configEditable
->expects($this
->at(2))
->method('set')
->with('default.project', 'a_project')
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(3))
->method('save');
$projects = $this->lingotek
->getProjects(FALSE);
$this
->assertArrayEquals($projects, [
'a_project' => 'A project',
]);
}
public function testGetProjectsWithDataButForcing() {
$this->config
->expects($this
->at(0))
->method('get')
->with('account.resources.project')
->will($this
->returnValue([
'a_project' => 'A project',
]));
$this->config
->expects($this
->at(1))
->method('get')
->with('default.community')
->will($this
->returnValue([
'my_community',
]));
$this->config
->expects($this
->at(2))
->method('get')
->with('default.project')
->will($this
->returnValue(NULL));
$this->api
->expects($this
->once())
->method('getProjects')
->will($this
->returnValue([
'a_project' => 'A project',
]));
$this->configEditable
->expects($this
->at(0))
->method('set')
->with('account.resources.project', [
'a_project' => 'A project',
])
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(1))
->method('save');
$this->configEditable
->expects($this
->at(2))
->method('set')
->with('default.project', 'a_project')
->will($this
->returnSelf());
$this->configEditable
->expects($this
->at(3))
->method('save');
$projects = $this->lingotek
->getProjects(TRUE);
$this
->assertArrayEquals($projects, [
'a_project' => 'A project',
]);
}
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',
],
[
'default.workflow',
'default_workflow',
],
]));
$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));
$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));
$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));
$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));
$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));
$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));
$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));
$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));
$this->api
->expects($this
->at(8))
->method('addDocument')
->with([
'title' => 'title',
'content' => '{"content":"wedgiePlatypus"}',
'locale_code' => 'en_US',
'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',
'translation_locale_code' => [
'es_ES',
'ca_ES',
'it_IT',
],
'translation_workflow_id' => [
'es_workflow',
'ca_workflow',
'default_workflow',
],
'translation_vault_id' => [
'default_vault',
'ca_vault',
'it_vault',
],
])
->will($this
->returnValue($response));
$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);
$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);
$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);
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', NULL, NULL);
$this
->assertEquals('my-document-id', $doc_id);
$doc_id = $this->lingotek
->uploadDocument('title', 'content', 'es', 'http://example.com/node/1', NULL);
$this
->assertEquals('my-document-id', $doc_id);
$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);
$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);
$doc_id = $this->lingotek
->uploadDocument('title', [
'content' => 'wedgiePlatypus',
], 'es', NULL, $profile, 'my_job_id');
$this
->assertEquals('my-document-id', $doc_id);
$english = $this
->createMock(ConfigurableLanguageInterface::class);
$english
->expects($this
->any())
->method('getId')
->willReturn('en');
$spanish = $this
->createMock(ConfigurableLanguageInterface::class);
$spanish
->expects($this
->any())
->method('getId')
->willReturn('es');
$catalan = $this
->createMock(ConfigurableLanguageInterface::class);
$catalan
->expects($this
->any())
->method('getId')
->willReturn('ca');
$italian = $this
->createMock(ConfigurableLanguageInterface::class);
$italian
->expects($this
->any())
->method('getId')
->willReturn('it');
$this->lingotekConfiguration
->expects($this
->any())
->method('getEnabledLanguages')
->willReturn([
'en' => $english,
'es' => $spanish,
'ca' => $catalan,
'it' => $italian,
]);
$this->languageLocaleMapper
->expects($this
->any())
->method('getLocaleForLangcode')
->willReturnMap([
[
'es',
'es_ES',
],
[
'ca',
'ca_ES',
],
[
'en',
'en_US',
],
[
'it',
'it_IT',
],
]);
$profile = new LingotekProfile([
'id' => 'profile_with_requests',
'project' => 'test_project',
'vault' => 'test_vault',
'workflow' => 'test_workflow',
'language_overrides' => [
'es' => [
'overrides' => 'custom',
'custom' => [
'auto_request' => TRUE,
'workflow' => 'es_workflow',
'vault' => 'default',
],
],
'ca' => [
'overrides' => 'custom',
'custom' => [
'auto_request' => TRUE,
'workflow' => 'ca_workflow',
'vault' => 'ca_vault',
],
],
'it' => [
'overrides' => 'custom',
'custom' => [
'auto_request' => TRUE,
'workflow' => 'default',
'vault' => 'it_vault',
],
],
],
], 'lingotek_profile');
$profile
->setAutomaticUpload(TRUE);
$profile
->setAutomaticRequest(TRUE);
$doc_id = $this->lingotek
->uploadDocument('title', [
'content' => 'wedgiePlatypus',
], 'en_US', NULL, $profile, 'my_job_id');
$this
->assertEquals('my-document-id', $doc_id);
}
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',
],
]));
$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));
$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));
$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));
$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));
$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));
$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));
$this->lingotek
->updateDocument('my_doc_id', 'content');
$this->lingotek
->updateDocument('my_doc_id', 'content', 'http://example.com/node/1');
$this->lingotek
->updateDocument('my_doc_id', 'content', NULL, 'title');
$this->lingotek
->updateDocument('my_doc_id', 'content', 'http://example.com/node/1', 'title');
$this->lingotek
->updateDocument('my_doc_id', [
'content' => 'wedgiePlatypus',
]);
$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');
$this->lingotek
->updateDocument('my_doc_id', NULL, NULL, NULL, $profile, 'my_job_id');
}
public function testAddTarget() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_CREATED);
$language = $this
->createMock(ConfigurableLanguageInterface::class);
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('es'));
$this->config
->expects($this
->any())
->method('get')
->will($this
->returnValueMap([
[
'default.workflow',
'default_workflow',
],
]));
$this->languageLocaleMapper
->expects($this
->any())
->method('getConfigurableLanguageForLocale')
->with('es_ES')
->will($this
->returnValue($language));
$this->api
->expects($this
->at(0))
->method('addTranslation')
->with('my_doc_id', 'es_ES', 'my_test_workflow')
->will($this
->returnValue($response));
$this->api
->expects($this
->at(1))
->method('addTranslation')
->with('my_doc_id', 'es_ES', 'another_test_workflow')
->will($this
->returnValue($response));
$this->api
->expects($this
->at(2))
->method('addTranslation')
->with('my_doc_id', 'es_ES', 'default_workflow')
->will($this
->returnValue($response));
$this->api
->expects($this
->at(3))
->method('addTranslation')
->with('my_doc_id', 'es_ES', 'overridden_workflow', 'overridden_vault')
->will($this
->returnValue($response));
$this->api
->expects($this
->at(4))
->method('addTranslation')
->with('my_doc_id', 'es_ES', 'default_workflow')
->will($this
->returnValue($response));
$this->api
->expects($this
->at(5))
->method('addTranslation')
->with('my_doc_id', 'es_ES', NULL)
->will($this
->returnValue($response));
$profile = new LingotekProfile([
'id' => 'profile1',
'workflow' => 'my_test_workflow',
], 'lingotek_profile');
$this
->assertTrue($this->lingotek
->addTarget('my_doc_id', 'es_ES', $profile));
$profile = new LingotekProfile([
'id' => 'profile2',
'workflow' => 'another_test_workflow',
], 'lingotek_profile');
$this
->assertTrue($this->lingotek
->addTarget('my_doc_id', 'es_ES', $profile));
$profile = new LingotekProfile([
'id' => 'profile2',
'workflow' => 'default',
], 'lingotek_profile');
$this
->assertTrue($this->lingotek
->addTarget('my_doc_id', 'es_ES', $profile));
$profile = new LingotekProfile([
'id' => 'profile2',
'workflow' => 'default',
'language_overrides' => [
'es' => [
'overrides' => 'custom',
'custom' => [
'workflow' => 'overridden_workflow',
'vault' => 'overridden_vault',
],
],
],
], 'lingotek_profile');
$this
->assertTrue($this->lingotek
->addTarget('my_doc_id', 'es_ES', $profile));
$profile = new LingotekProfile([
'id' => 'profile2',
'workflow' => 'a_different_test_workflow',
'language_overrides' => [
'es' => [
'overrides' => 'custom',
'custom' => [
'workflow' => 'default',
'vault' => 'default',
],
],
],
], 'lingotek_profile');
$this
->assertTrue($this->lingotek
->addTarget('my_doc_id', 'es_ES', $profile));
$this
->assertTrue($this->lingotek
->addTarget('my_doc_id', 'es_ES', NULL));
}
public function testAddTargetPaymentRequired() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_PAYMENT_REQUIRED);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'messages' => [
"Community has been disabled. Please contact support@lingotek.com to re-enable your community.",
],
]));
$language = $this
->createMock(ConfigurableLanguageInterface::class);
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('es'));
$this->config
->expects($this
->any())
->method('get')
->will($this
->returnValueMap([
[
'default.workflow',
'default_workflow',
],
]));
$this->languageLocaleMapper
->expects($this
->any())
->method('getConfigurableLanguageForLocale')
->with('es_ES')
->will($this
->returnValue($language));
$this->api
->expects($this
->at(0))
->method('addTranslation')
->with('my_doc_id', 'es_ES', NULL)
->will($this
->returnValue($response));
$this
->expectException(LingotekPaymentRequiredException::class);
$this
->expectExceptionMessage('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$this->lingotek
->addTarget('my_doc_id', 'es_ES', NULL);
}
public function testAddTargetGone() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_GONE);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'messages' => [
"Document my_doc_id has been archived.",
],
]));
$language = $this
->createMock(ConfigurableLanguageInterface::class);
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('es'));
$this->config
->expects($this
->any())
->method('get')
->will($this
->returnValueMap([
[
'default.workflow',
'default_workflow',
],
]));
$this->languageLocaleMapper
->expects($this
->any())
->method('getConfigurableLanguageForLocale')
->with('es_ES')
->will($this
->returnValue($language));
$this->api
->expects($this
->at(0))
->method('addTranslation')
->with('my_doc_id', 'es_ES', NULL)
->will($this
->returnValue($response));
$this
->assertFalse($this->lingotek
->addTarget('my_doc_id', 'es_ES', NULL));
}
public function testAddTargetLocked() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_LOCKED);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'next_document_id' => 'my_new_document_id',
'messages' => [
'Document my_doc_id has been updated with a new version. Use document my_new_document_id for all future interactions.',
],
]));
$language = $this
->createMock(ConfigurableLanguageInterface::class);
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('es'));
$this->config
->expects($this
->any())
->method('get')
->will($this
->returnValueMap([
[
'default.workflow',
'default_workflow',
],
]));
$this->languageLocaleMapper
->expects($this
->any())
->method('getConfigurableLanguageForLocale')
->with('es_ES')
->will($this
->returnValue($language));
$this->api
->expects($this
->at(0))
->method('addTranslation')
->with('my_doc_id', 'es_ES', NULL)
->will($this
->returnValue($response));
$this
->assertFalse($this->lingotek
->addTarget('my_doc_id', 'es_ES', NULL));
}
public function testCancelDocument() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->at(0))
->method('getStatusCode')
->willReturn(Response::HTTP_NO_CONTENT);
$response
->expects($this
->at(1))
->method('getStatusCode')
->willReturn(Response::HTTP_INTERNAL_SERVER_ERROR);
$response
->expects($this
->at(2))
->method('getStatusCode')
->willReturn(Response::HTTP_NOT_FOUND);
$this->api
->expects($this
->any())
->method('cancelDocument')
->with('my_doc_id')
->will($this
->returnValue($response));
$this
->assertTrue($this->lingotek
->cancelDocument('my_doc_id'));
$this
->assertFalse($this->lingotek
->cancelDocument('my_doc_id'));
$this
->assertFalse($this->lingotek
->cancelDocument('my_doc_id'));
}
public function testCancelDocumentTarget() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->at(0))
->method('getStatusCode')
->willReturn(Response::HTTP_NO_CONTENT);
$response
->expects($this
->at(1))
->method('getStatusCode')
->willReturn(Response::HTTP_INTERNAL_SERVER_ERROR);
$response
->expects($this
->at(2))
->method('getStatusCode')
->willReturn(Response::HTTP_NOT_FOUND);
$this->api
->expects($this
->any())
->method('cancelDocumentTarget')
->with('my_doc_id', 'es_ES')
->will($this
->returnValue($response));
$this
->assertTrue($this->lingotek
->cancelDocumentTarget('my_doc_id', 'es_ES'));
$this
->assertFalse($this->lingotek
->cancelDocumentTarget('my_doc_id', 'es_ES'));
$this
->assertFalse($this->lingotek
->cancelDocumentTarget('my_doc_id', 'es_ES'));
}
public function testGetDocumentTranslationStatus() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->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,
'status' => 'READY',
],
],
[
'properties' => [
'locale_code' => 'de-DE',
'percent_complete' => 50,
'status' => 'READY',
],
],
],
]));
$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));
$result = $this->lingotek
->getDocumentTranslationStatus('my_doc_id', 'es_ES');
$this
->assertEquals(TRUE, $result);
$result = $this->lingotek
->getDocumentTranslationStatus('my_doc_id', 'de_DE');
$this
->assertEquals(50, $result);
$result = $this->lingotek
->getDocumentTranslationStatus('my_doc_id', 'ca_ES');
$this
->assertEquals(FALSE, $result);
}
public function testGetDocumentTranslationStatusCancelled() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->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,
'status' => 'READY',
],
],
[
'properties' => [
'locale_code' => 'de-DE',
'percent_complete' => 50,
'status' => 'CANCELLED',
],
],
],
]));
$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));
$result = $this->lingotek
->getDocumentTranslationStatus('my_doc_id', 'es_ES');
$this
->assertEquals(TRUE, $result);
$result = $this->lingotek
->getDocumentTranslationStatus('my_doc_id', 'de_DE');
$this
->assertEquals('CANCELLED', $result);
$result = $this->lingotek
->getDocumentTranslationStatus('my_doc_id', 'ca_ES');
$this
->assertEquals(FALSE, $result);
}
public function testUploadWithNoMetadataLeaked() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_ACCEPTED);
$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',
],
]));
$this->api
->expects($this
->at(0))
->method('addDocument')
->with([
'title' => 'title',
'content' => '{"content":"My test content","_lingotek_metadata":{"_entity_id":1}}',
'locale_code' => 'es',
'format' => 'JSON',
'project_id' => 'default_project',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
'content_type' => 'node',
])
->will($this
->returnValue($response));
$data = [
'content' => 'My test content',
'_lingotek_metadata' => [
'_entity_id' => 1,
'_intelligence' => [
'content_type' => 'node',
],
],
];
$this->lingotek
->uploadDocument('title', $data, 'es');
}
public function testUpdateWithNoMetadataLeaked() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_ACCEPTED);
$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',
],
]));
$this->api
->expects($this
->at(0))
->method('patchDocument')
->with('my_doc_id', [
'content' => '{"content":"My test content","_lingotek_metadata":{"_entity_id":1}}',
'format' => 'JSON',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
'content_type' => 'node',
])
->will($this
->returnValue($response));
$data = [
'content' => 'My test content',
'_lingotek_metadata' => [
'_entity_id' => 1,
'_intelligence' => [
'content_type' => 'node',
],
],
];
$result = $this->lingotek
->updateDocument('my_doc_id', $data);
$this
->assertTrue($result == TRUE);
}
public function testUpdateDocument() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$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');
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_ACCEPTED);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'next_document_id' => 'my_new_document_id',
'messages' => [
'Document my_doc_id has been updated with a new version. Use document my_new_document_id for all future interactions.',
],
]));
$this->api
->expects($this
->at(0))
->method('patchDocument')
->with('my_doc_id', [
'content' => '{"content":"My test content","_lingotek_metadata":{"_entity_id":1}}',
'format' => 'JSON',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
'content_type' => 'node',
])
->will($this
->returnValue($response));
$data = [
'content' => 'My test content',
'_lingotek_metadata' => [
'_entity_id' => 1,
'_intelligence' => [
'content_type' => 'node',
],
],
];
$result = $this->lingotek
->updateDocument('my_doc_id', $data);
$this
->assertEquals($result, 'my_new_document_id');
}
public function testUpdateDocumentPaymentRequired() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$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');
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_PAYMENT_REQUIRED);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'messages' => [
"Community has been disabled. Please contact support@lingotek.com to re-enable your community.",
],
]));
$this->api
->expects($this
->at(0))
->method('patchDocument')
->with('my_doc_id', [
'content' => '{"content":"My test content","_lingotek_metadata":{"_entity_id":1}}',
'format' => 'JSON',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
'content_type' => 'node',
])
->will($this
->returnValue($response));
$data = [
'content' => 'My test content',
'_lingotek_metadata' => [
'_entity_id' => 1,
'_intelligence' => [
'content_type' => 'node',
],
],
];
$this
->expectException(LingotekPaymentRequiredException::class);
$this
->expectExceptionMessage('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$this->lingotek
->updateDocument('my_doc_id', $data);
}
public function testUpdateDocumentGone() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$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');
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_GONE);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'messages' => [
"Document my_doc_id has been archived.",
],
]));
$this->api
->expects($this
->at(0))
->method('patchDocument')
->with('my_doc_id', [
'content' => '{"content":"My test content","_lingotek_metadata":{"_entity_id":1}}',
'format' => 'JSON',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
'content_type' => 'node',
])
->will($this
->returnValue($response));
$data = [
'content' => 'My test content',
'_lingotek_metadata' => [
'_entity_id' => 1,
'_intelligence' => [
'content_type' => 'node',
],
],
];
$this
->expectException(LingotekDocumentArchivedException::class);
$this
->expectExceptionMessage('Document my_doc_id has been archived.');
$this->lingotek
->updateDocument('my_doc_id', $data);
}
public function testUpdateDocumentLocked() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$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');
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_LOCKED);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'next_document_id' => 'my_new_document_id',
'messages' => [
'Document my_doc_id has been updated with a new version. Use document my_new_document_id for all future interactions.',
],
]));
$this->api
->expects($this
->at(0))
->method('patchDocument')
->with('my_doc_id', [
'content' => '{"content":"My test content","_lingotek_metadata":{"_entity_id":1}}',
'format' => 'JSON',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
'content_type' => 'node',
])
->will($this
->returnValue($response));
$data = [
'content' => 'My test content',
'_lingotek_metadata' => [
'_entity_id' => 1,
'_intelligence' => [
'content_type' => 'node',
],
],
];
$this
->expectException(LingotekDocumentLockedException::class);
$this
->expectExceptionMessage('Document my_doc_id has been updated with a new version. Use document my_new_document_id for all future interactions.');
$this->lingotek
->updateDocument('my_doc_id', $data);
}
public function testUploadDocumentPaymentRequired() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$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');
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_PAYMENT_REQUIRED);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'messages' => [
"Community has been disabled. Please contact support@lingotek.com to re-enable your community.",
],
]));
$this->api
->expects($this
->at(0))
->method('addDocument')
->with([
'title' => 'title',
'content' => '{"content":"My test content","_lingotek_metadata":{"_entity_id":1}}',
'locale_code' => 'es',
'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
'fprm_id' => '4f91482b-5aa1-4a4a-a43f-712af7b39625',
'format' => 'JSON',
'external_application_id' => 'e39e24c7-6c69-4126-946d-cf8fbff38ef0',
'content_type' => 'node',
])
->will($this
->returnValue($response));
$data = [
'content' => 'My test content',
'_lingotek_metadata' => [
'_entity_id' => 1,
'_intelligence' => [
'content_type' => 'node',
],
],
];
$this
->expectException(LingotekPaymentRequiredException::class);
$this
->expectExceptionMessage('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$this->lingotek
->uploadDocument('title', $data, 'es', NULL, NULL);
}
public function testDownloadDocument() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_OK);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'title' => [
'value' => 'Document title',
],
]));
$language = $this
->createMock(ConfigurableLanguageInterface::class);
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('es'));
$this->config
->expects($this
->any())
->method('get')
->will($this
->returnValueMap([
[
'default.workflow',
'default_workflow',
],
]));
$this->languageLocaleMapper
->expects($this
->any())
->method('getConfigurableLanguageForLocale')
->with('es_ES')
->will($this
->returnValue($language));
$this->api
->expects($this
->at(0))
->method('getTranslation')
->with('my_doc_id', 'es_ES')
->will($this
->returnValue($response));
$this
->assertNotNull($this->lingotek
->downloadDocument('my_doc_id', 'es_ES'));
}
public function testDownloadDocumentGone() {
$response = $this
->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$response
->expects($this
->any())
->method('getStatusCode')
->willReturn(Response::HTTP_GONE);
$response
->expects($this
->any())
->method('getBody')
->willReturn(json_encode([
'messages' => [
"Document my_doc_id has been archived.",
],
]));
$language = $this
->createMock(ConfigurableLanguageInterface::class);
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('es'));
$this->config
->expects($this
->any())
->method('get')
->will($this
->returnValueMap([
[
'default.workflow',
'default_workflow',
],
]));
$this->languageLocaleMapper
->expects($this
->any())
->method('getConfigurableLanguageForLocale')
->with('es_ES')
->will($this
->returnValue($language));
$this->api
->expects($this
->at(0))
->method('getTranslation')
->with('my_doc_id', 'es_ES')
->will($this
->returnValue($response));
$this
->assertFalse($this->lingotek
->downloadDocument('my_doc_id', 'es_ES'));
}
}