ContextApiFunctionalTest.php in TMGMT Translator Smartling 8.4
File
vendor/smartling/api-sdk-php/tests/functional/ContextApiFunctionalTest.php
View source
<?php
namespace Smartling\Tests\Functional;
use PHPUnit_Framework_TestCase;
use Smartling\AuthApi\AuthTokenProvider;
use Smartling\Context\Params\MatchContextParameters;
use Smartling\Context\Params\UploadContextParameters;
use Smartling\Context\Params\UploadResourceParameters;
use Smartling\Exceptions\SmartlingApiException;
use Smartling\Context\ContextApi;
class ContextApiFunctionalTest extends PHPUnit_Framework_TestCase {
private $contextApi;
public function setUp() {
$projectId = getenv('project_id');
$userIdentifier = getenv('user_id');
$userSecretKey = getenv('user_key');
if (empty($projectId) || empty($userIdentifier) || empty($userSecretKey)) {
$this
->fail('Missing required parameters');
}
$authProvider = AuthTokenProvider::create($userIdentifier, $userSecretKey);
$this->contextApi = ContextApi::create($authProvider, $projectId);
}
public function testUploadContext() {
try {
$params = new UploadContextParameters();
$params
->setContent('tests/resources/context.html');
$params
->setName('test_context.html');
$result = $this->contextApi
->uploadContext($params);
$this
->assertArrayHasKey('contextUid', $result);
$this
->assertArrayHasKey('contextType', $result);
$this
->assertArrayHasKey('name', $result);
$this
->assertArrayHasKey('created', $result);
} catch (SmartlingApiException $e) {
$this
->fail($e
->getMessage());
}
}
public function testMatchContext() {
try {
$fileUri = 'tests/resources/context.html';
$params = new UploadContextParameters();
$params
->setContent($fileUri);
$params
->setName('test_context.html');
$contextInfo = $this->contextApi
->uploadContext($params);
$params = new MatchContextParameters();
$params
->setContentFileUri($fileUri);
$result = $this->contextApi
->matchContext($contextInfo['contextUid'], $params);
$this
->assertArrayHasKey('matchId', $result);
} catch (SmartlingApiException $e) {
$this
->fail($e
->getMessage());
}
}
public function testUploadAndMatchContext() {
try {
$fileUri = 'tests/resources/context.html';
$matchParams = new MatchContextParameters();
$matchParams
->setContentFileUri($fileUri);
$params = new UploadContextParameters();
$params
->setContent($fileUri);
$params
->setMatchParams($matchParams);
$params
->setName('test_context.html');
$result = $this->contextApi
->uploadAndMatchContext($params);
$this
->assertArrayHasKey('matchId', $result);
} catch (SmartlingApiException $e) {
$this
->fail($e
->getMessage());
}
}
public function testGetMissingResources() {
try {
$result = $this->contextApi
->getMissingResources();
$this
->assertArrayHasKey('items', $result);
} catch (SmartlingApiException $e) {
$this
->fail($e
->getMessage());
}
}
public function testGetAllMissingResources() {
try {
$result = $this->contextApi
->getAllMissingResources();
$this
->assertArrayHasKey('items', $result);
$this
->assertArrayHasKey('all', $result);
} catch (SmartlingApiException $e) {
$this
->fail($e
->getMessage());
}
}
public function testRenderContext() {
try {
$params = new UploadContextParameters();
$params
->setContent('tests/resources/context.html');
$params
->setName('test_context.html');
$contextInfo = $this->contextApi
->uploadContext($params);
$result = $this->contextApi
->renderContext($contextInfo['contextUid']);
$this
->assertTrue($result);
} catch (SmartlingApiException $e) {
$this
->fail($e
->getMessage());
}
}
}