You are here

class ContextApiFunctionalTest in TMGMT Translator Smartling 8.2

Same name in this branch
  1. 8.2 api-sdk-php/tests/functional/ContextApiFunctionalTest.php \Smartling\Tests\Functional\ContextApiFunctionalTest
  2. 8.2 vendor/smartling/api-sdk-php/tests/functional/ContextApiFunctionalTest.php \Smartling\Tests\Functional\ContextApiFunctionalTest
Same name and namespace in other branches
  1. 8.4 vendor/smartling/api-sdk-php/tests/functional/ContextApiFunctionalTest.php \Smartling\Tests\Functional\ContextApiFunctionalTest
  2. 8.3 vendor/smartling/api-sdk-php/tests/functional/ContextApiFunctionalTest.php \Smartling\Tests\Functional\ContextApiFunctionalTest

Test class for Project API examples.

Hierarchy

Expanded class hierarchy of ContextApiFunctionalTest

File

api-sdk-php/tests/functional/ContextApiFunctionalTest.php, line 15

Namespace

Smartling\Tests\Functional
View source
class ContextApiFunctionalTest extends PHPUnit_Framework_TestCase {

  /**
   * @var ContextApi
   */
  private $contextApi;

  /**
   * Test mixture.
   */
  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);
  }

  /**
   * Test for upload context.
   */
  public function testUploadContext() {
    try {
      $params = new UploadContextParameters();
      $params
        ->setContextFileUri('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());
    }
  }

  /**
   * Test for match context.
   */
  public function testMatchContext() {
    try {
      $params = new UploadContextParameters();
      $params
        ->setContextFileUri('tests/resources/context.html');
      $params
        ->setName('test_context.html');
      $contextInfo = $this->contextApi
        ->uploadContext($params);
      $result = $this->contextApi
        ->matchContext($contextInfo['contextUid']);
      $this
        ->assertArrayHasKey('matchId', $result);
    } catch (SmartlingApiException $e) {
      $this
        ->fail($e
        ->getMessage());
    }
  }

  /**
   * Test for upload and match context.
   */
  public function testUploadAndMatchContext() {
    try {
      $params = new UploadContextParameters();
      $params
        ->setContextFileUri('tests/resources/context.html');
      $params
        ->setName('test_context.html');
      $result = $this->contextApi
        ->uploadAndMatchContext($params);
      $this
        ->assertArrayHasKey('matchId', $result);
    } catch (SmartlingApiException $e) {
      $this
        ->fail($e
        ->getMessage());
    }
  }

  /**
   * Test for get missing resources.
   */
  public function testGetMissingResources() {
    try {
      $result = $this->contextApi
        ->getMissingResources();
      $this
        ->assertArrayHasKey('items', $result);
    } catch (SmartlingApiException $e) {
      $this
        ->fail($e
        ->getMessage());
    }
  }

  /**
   * Test for get all missing resources.
   */
  public function testGetAllMissingResources() {
    try {
      $result = $this->contextApi
        ->getAllMissingResources();
      $this
        ->assertArrayHasKey('items', $result);
      $this
        ->assertArrayHasKey('all', $result);
    } catch (SmartlingApiException $e) {
      $this
        ->fail($e
        ->getMessage());
    }
  }

  /**
   * Test for render context.
   */
  public function testRenderContext() {
    try {
      $params = new UploadContextParameters();
      $params
        ->setContextFileUri('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());
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContextApiFunctionalTest::$contextApi private property
ContextApiFunctionalTest::setUp public function Test mixture.
ContextApiFunctionalTest::testGetAllMissingResources public function Test for get all missing resources.
ContextApiFunctionalTest::testGetMissingResources public function Test for get missing resources.
ContextApiFunctionalTest::testMatchContext public function Test for match context.
ContextApiFunctionalTest::testRenderContext public function Test for render context.
ContextApiFunctionalTest::testUploadAndMatchContext public function Test for upload and match context.
ContextApiFunctionalTest::testUploadContext public function Test for upload context.