You are here

class AuditLogApiTest in TMGMT Translator Smartling 8.4

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

Hierarchy

Expanded class hierarchy of AuditLogApiTest

File

vendor/smartling/api-sdk-php/tests/unit/AuditLogApiTest.php, line 9

Namespace

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

  /**
   * @covers \Smartling\AuditLog\AuditLogApi::createProjectLevelLogRecord
   */
  public function testCreateProjectLevelLogRecord() {
    $endpointUrl = vsprintf('%s/projects/%s/logs', [
      AuditLogApi::ENDPOINT_URL,
      $this->projectId,
    ]);
    $createParams = (new CreateRecordParameters())
      ->setActionTime(1234567890)
      ->setActionType(CreateRecordParameters::ACTION_TYPE_UPLOAD)
      ->setFileUri("file_uri")
      ->setFileUid("file_uid")
      ->setSourceLocaleId('en')
      ->setTargetLocaleIds([
      'de',
    ])
      ->setTranslationJobUid("smartling_job_uid")
      ->setTranslationJobName("smartling_job_name")
      ->setTranslationJobDueDate("smartling_job_due_date")
      ->setTranslationJobAuthorize(1)
      ->setBatchUid("batch_uid")
      ->setDescription("description")
      ->setClientUserId("user_id")
      ->setClientUserEmail("user_email")
      ->setClientUserName("user_name")
      ->setEnvId("env_id")
      ->setClientData("foo", "bar")
      ->setClientData("foo1", "bar1");
    $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' => [
        'actionTime' => '2009-02-13T23:31:30Z',
        'actionType' => CreateRecordParameters::ACTION_TYPE_UPLOAD,
        'fileUri' => 'file_uri',
        'fileUid' => 'file_uid',
        'sourceLocaleId' => 'en',
        'targetLocaleIds' => [
          'de',
        ],
        'translationJobUid' => 'smartling_job_uid',
        'translationJobName' => 'smartling_job_name',
        'translationJobDueDate' => 'smartling_job_due_date',
        'translationJobAuthorize' => true,
        'batchUid' => 'batch_uid',
        'description' => 'description',
        'clientUserId' => 'user_id',
        'clientUserEmail' => 'user_email',
        'clientUserName' => 'user_name',
        'envId' => 'env_id',
        'clientData' => [
          'foo' => 'bar',
          'foo1' => 'bar1',
        ],
      ],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->createProjectLevelLogRecord($createParams);
  }

  /**
   * @covers \Smartling\AuditLog\AuditLogApi::createAccountLevelLogRecord
   */
  public function testCreateAccountLevelLogRecord() {
    $accountUid = "account_uid";
    $endpointUrl = vsprintf('%s/accounts/%s/logs', [
      AuditLogApi::ENDPOINT_URL,
      $accountUid,
    ]);
    $createParams = (new CreateRecordParameters())
      ->setActionTime(1234567890)
      ->setActionType(CreateRecordParameters::ACTION_TYPE_UPLOAD)
      ->setFileUri("file_uri")
      ->setFileUid("file_uid")
      ->setSourceLocaleId('en')
      ->setTargetLocaleIds([
      'de',
    ])
      ->setTranslationJobUid("smartling_job_uid")
      ->setTranslationJobName("smartling_job_name")
      ->setTranslationJobDueDate("smartling_job_due_date")
      ->setTranslationJobAuthorize(true)
      ->setBatchUid("batch_uid")
      ->setDescription("description")
      ->setClientUserId("user_id")
      ->setClientUserEmail("user_email")
      ->setClientUserName("user_name")
      ->setEnvId("env_id")
      ->setClientData("foo", "bar")
      ->setClientData("foo1", "bar1");
    $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' => [
        'actionTime' => '2009-02-13T23:31:30Z',
        'actionType' => CreateRecordParameters::ACTION_TYPE_UPLOAD,
        'fileUri' => 'file_uri',
        'fileUid' => 'file_uid',
        'sourceLocaleId' => 'en',
        'targetLocaleIds' => [
          'de',
        ],
        'translationJobUid' => 'smartling_job_uid',
        'translationJobName' => 'smartling_job_name',
        'translationJobDueDate' => 'smartling_job_due_date',
        'translationJobAuthorize' => true,
        'batchUid' => 'batch_uid',
        'description' => 'description',
        'clientUserId' => 'user_id',
        'clientUserEmail' => 'user_email',
        'clientUserName' => 'user_name',
        'envId' => 'env_id',
        'clientData' => [
          'foo' => 'bar',
          'foo1' => 'bar1',
        ],
      ],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->createAccountLevelLogRecord($accountUid, $createParams);
  }

  /**
   * @covers \Smartling\AuditLog\AuditLogApi::searchProjectLevelLogRecord
   */
  public function testSearchProjectLevelLogRecord() {
    $endpointUrl = vsprintf('%s/projects/%s/logs', [
      AuditLogApi::ENDPOINT_URL,
      $this->projectId,
    ]);
    $createParams = (new SearchRecordParameters())
      ->setSearchQuery("foo:bar")
      ->setOffset(1)
      ->setLimit(100)
      ->setSort("baz", SearchRecordParameters::ORDER_ASC);
    $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' => [
        'q' => 'foo:bar',
        'offset' => 1,
        'limit' => 100,
        'sort' => 'baz:' . SearchRecordParameters::ORDER_ASC,
      ],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->searchProjectLevelLogRecord($createParams);
  }

  /**
   * @covers \Smartling\AuditLog\AuditLogApi::searchAccountLevelLogRecord
   */
  public function testSearchAccountLevelLogRecord() {
    $accountUid = "account_uid";
    $endpointUrl = vsprintf('%s/accounts/%s/logs', [
      AuditLogApi::ENDPOINT_URL,
      $accountUid,
    ]);
    $createParams = (new SearchRecordParameters())
      ->setSearchQuery("foo:bar")
      ->setOffset(1)
      ->setLimit(100)
      ->setSort("baz", SearchRecordParameters::ORDER_ASC);
    $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' => [
        'q' => 'foo:bar',
        'offset' => 1,
        'limit' => 100,
        'sort' => 'baz:' . SearchRecordParameters::ORDER_ASC,
      ],
    ])
      ->willReturn($this->responseMock);
    $this->object
      ->searchAccountLevelLogRecord($accountUid, $createParams);
  }
  protected function setUp() {
    parent::setUp();
    $this
      ->prepareAuditLogApiMock();
  }
  private function prepareAuditLogApiMock() {
    $this->object = $this
      ->getMockBuilder('Smartling\\AuditLog\\AuditLogApi')
      ->setMethods(NULL)
      ->setConstructorArgs([
      $this->projectId,
      $this->client,
      null,
      AuditLogApi::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.
AuditLogApiTest::prepareAuditLogApiMock private function
AuditLogApiTest::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
AuditLogApiTest::testCreateAccountLevelLogRecord public function @covers \Smartling\AuditLog\AuditLogApi::createAccountLevelLogRecord
AuditLogApiTest::testCreateProjectLevelLogRecord public function @covers \Smartling\AuditLog\AuditLogApi::createProjectLevelLogRecord
AuditLogApiTest::testSearchAccountLevelLogRecord public function @covers \Smartling\AuditLog\AuditLogApi::searchAccountLevelLogRecord
AuditLogApiTest::testSearchProjectLevelLogRecord public function @covers \Smartling\AuditLog\AuditLogApi::searchProjectLevelLogRecord