You are here

class ProgressTrackerApiTest in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 vendor/smartling/api-sdk-php/tests/unit/ProgressTrackerApiTest.php \Smartling\Tests\Unit\ProgressTrackerApiTest

Test class for Smartling\ProgressTracker\ProgressTrackerApi.

Hierarchy

Expanded class hierarchy of ProgressTrackerApiTest

File

vendor/smartling/api-sdk-php/tests/unit/ProgressTrackerApiTest.php, line 11

Namespace

Smartling\Tests\Unit
View source
class ProgressTrackerApiTest extends ApiTestAbstract {

  /**
   * @covers \Smartling\ProgressTracker\ProgressTrackerApi::getToken
   */
  public function testGetToken() {
    $accountUid = "account_uid";
    $endpointUrl = vsprintf('%s/accounts/%s/token', [
      ProgressTrackerApi::ENDPOINT_URL,
      $accountUid,
    ]);
    $this->client
      ->expects($this
      ->any())
      ->method('request')
      ->with('get', $endpointUrl, [
      'headers' => [
        'Accept' => 'application/json',
        'Authorization' => vsprintf('%s %s', [
          $this->authProvider
            ->getTokenType(),
          $this->authProvider
            ->getAccessToken(),
        ]),
      ],
      'exceptions' => false,
      'query' => [],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->getToken($accountUid);
  }

  /**
   * @covers \Smartling\ProgressTracker\ProgressTrackerApi::createRecord
   */
  public function testCreateRecord() {
    $spaceId = "space";
    $objectId = "object";
    $ttl = 5;
    $data = [
      "foo" => "bar",
    ];
    $endpointUrl = vsprintf('%s/projects/%s/spaces/%s/objects/%s/records', [
      ProgressTrackerApi::ENDPOINT_URL,
      $this->projectId,
      $spaceId,
      $objectId,
    ]);
    $params = new RecordParameters();
    $params
      ->setTtl($ttl);
    $params
      ->setData($data);
    $this->client
      ->expects($this
      ->any())
      ->method('request')
      ->with('post', $endpointUrl, [
      'headers' => [
        'Accept' => 'application/json',
        'Authorization' => vsprintf('%s %s', [
          $this->authProvider
            ->getTokenType(),
          $this->authProvider
            ->getAccessToken(),
        ]),
      ],
      'exceptions' => false,
      'json' => [
        "ttl" => $ttl,
        "data" => $data,
      ],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->createRecord($spaceId, $objectId, $params);
  }

  /**
   * @covers \Smartling\ProgressTracker\ProgressTrackerApi::deleteRecord
   */
  public function testDeleteRecord() {
    $spaceId = "space";
    $objectId = "object";
    $recordId = "record";
    $endpointUrl = vsprintf('%s/projects/%s/spaces/%s/objects/%s/records/%s', [
      ProgressTrackerApi::ENDPOINT_URL,
      $this->projectId,
      $spaceId,
      $objectId,
      $recordId,
    ]);
    $this->client
      ->expects($this
      ->any())
      ->method('request')
      ->with('delete', $endpointUrl, [
      'headers' => [
        'Accept' => 'application/json',
        'Authorization' => vsprintf('%s %s', [
          $this->authProvider
            ->getTokenType(),
          $this->authProvider
            ->getAccessToken(),
        ]),
      ],
      'exceptions' => false,
      'query' => [],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->deleteRecord($spaceId, $objectId, $recordId);
  }

  /**
   * @covers \Smartling\ProgressTracker\ProgressTrackerApi::updateRecord
   */
  public function testUpdateRecord() {
    $spaceId = "space";
    $objectId = "object";
    $recordId = "record";
    $ttl = 5;
    $data = [
      "foo" => "bar",
    ];
    $endpointUrl = vsprintf('%s/projects/%s/spaces/%s/objects/%s/records/%s', [
      ProgressTrackerApi::ENDPOINT_URL,
      $this->projectId,
      $spaceId,
      $objectId,
      $recordId,
    ]);
    $params = new RecordParameters();
    $params
      ->setTtl($ttl);
    $params
      ->setData($data);
    $this->client
      ->expects($this
      ->any())
      ->method('request')
      ->with('put', $endpointUrl, [
      'headers' => [
        'Accept' => 'application/json',
        'Authorization' => vsprintf('%s %s', [
          $this->authProvider
            ->getTokenType(),
          $this->authProvider
            ->getAccessToken(),
        ]),
      ],
      'exceptions' => false,
      'json' => [
        "ttl" => $ttl,
        "data" => $data,
      ],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->updateRecord($spaceId, $objectId, $recordId, $params);
  }

  /**
   * Sets up the fixture, for example, opens a network connection.
   * This method is called before a test is executed.
   */
  protected function setUp() {
    parent::setUp();
    $this
      ->prepareProgressTrackerApiMock();
  }
  private function prepareProgressTrackerApiMock() {
    $this->object = $this
      ->getMockBuilder('Smartling\\ProgressTracker\\ProgressTrackerApi')
      ->setMethods(NULL)
      ->setConstructorArgs([
      $this->projectId,
      $this->client,
      null,
      ProgressTrackerApi::ENDPOINT_URL,
    ])
      ->getMock();
    $this
      ->invokeMethod($this->object, 'setAuth', [
      $this->authProvider,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApiTestAbstract::$authProvider protected property
ApiTestAbstract::$client protected property
ApiTestAbstract::$clientInterfaceMethods protected static property
ApiTestAbstract::$hasEmitterInterfaceMethods protected static property
ApiTestAbstract::$messageInterfaceMethods protected static property
ApiTestAbstract::$object protected property
ApiTestAbstract::$projectId protected property
ApiTestAbstract::$requestInterfaceMethods protected static property
ApiTestAbstract::$requestMock protected property
ApiTestAbstract::$responseAsync protected property 1
ApiTestAbstract::$responseInterfaceMethods protected static property
ApiTestAbstract::$responseMock protected property
ApiTestAbstract::$responseWithException protected property
ApiTestAbstract::$secretKey protected property
ApiTestAbstract::$streamPlaceholder protected property
ApiTestAbstract::$userIdentifier protected property
ApiTestAbstract::$validResponse protected property
ApiTestAbstract::invokeMethod protected function Invokes protected or private method of given object.
ApiTestAbstract::JSON_OBJECT_AS_ARRAY constant
ApiTestAbstract::prepareAuthProviderMock protected function
ApiTestAbstract::prepareClientResponseMock protected function
ApiTestAbstract::prepareHttpClientMock protected function
ApiTestAbstract::readProperty protected function Reads protected or private property of given object.
ProgressTrackerApiTest::prepareProgressTrackerApiMock private function
ProgressTrackerApiTest::setUp protected function Sets up the fixture, for example, opens a network connection. This method is called before a test is executed. Overrides ApiTestAbstract::setUp
ProgressTrackerApiTest::testCreateRecord public function @covers \Smartling\ProgressTracker\ProgressTrackerApi::createRecord
ProgressTrackerApiTest::testDeleteRecord public function @covers \Smartling\ProgressTracker\ProgressTrackerApi::deleteRecord
ProgressTrackerApiTest::testGetToken public function @covers \Smartling\ProgressTracker\ProgressTrackerApi::getToken
ProgressTrackerApiTest::testUpdateRecord public function @covers \Smartling\ProgressTracker\ProgressTrackerApi::updateRecord