mirror of
https://github.com/brunofontes/Memsource-API.git
synced 2025-11-17 02:30:54 -03:00
Including Tests and verifications for errors
This commit is contained in:
37
tests/bilingualFileTest.php
Normal file
37
tests/bilingualFileTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use BrunoFontes\Memsource;
|
||||
|
||||
final class BilingualFileTest extends TestCase
|
||||
{
|
||||
public function testEmptyDownloadJobUidListShouldReturnEmptyFilenames()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->assertEquals(
|
||||
[],
|
||||
$api->bilingualFile()->download('uid', [], 'filename')
|
||||
);
|
||||
}
|
||||
public function testInvalidDownloadUidsShouldThrowError()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->expectException(\Exception::class);
|
||||
$api->bilingualFile()->download('uid', ['a'], 'filename');
|
||||
}
|
||||
|
||||
public function testUploadInexistentFileShouldThrowError()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->expectException(\Exception::class);
|
||||
$api->bilingualFile()->upload('myInvalidFile', []);
|
||||
}
|
||||
|
||||
public function testUploadWithNoTokenShouldThrowError()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->expectException(\Exception::class);
|
||||
$api->bilingualFile()->upload('tests/bilingualFileTest.php', []);
|
||||
}
|
||||
}
|
||||
57
tests/fetchApiTest.php
Normal file
57
tests/fetchApiTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use BrunoFontes\Memsource\FetchApi;
|
||||
|
||||
final class FetchApiTest extends TestCase
|
||||
{
|
||||
public function testEmptyFetchUrlShouldThrowError()
|
||||
{
|
||||
$fetch = new FetchApi('fakeToken', 'https://google.com');
|
||||
$this->expectExceptionMessage('URL not defined');
|
||||
$this->assertNotEmpty($fetch->fetch('get', ''));
|
||||
}
|
||||
|
||||
public function testNotEmptyTokenOnFetchShouldNotThrowError()
|
||||
{
|
||||
$fetch = new FetchApi('fakeToken', 'https://google.com');
|
||||
$this->assertNotEmpty($fetch->fetch('get', '/'));
|
||||
}
|
||||
public function testEmptyTokenOnFetchRawShouldNotThrowError()
|
||||
{
|
||||
$fetch = new FetchApi(null, 'http://google.com');
|
||||
$this->assertNotEmpty($fetch->fetch('raw', '/'));
|
||||
}
|
||||
|
||||
public function testEmptyTokenOnFetchGetShouldThrowError()
|
||||
{
|
||||
$fetch = new FetchApi(null, 'http://testUrl.com');
|
||||
$this->expectExceptionMessage('Missing Access Token');
|
||||
$fetch->fetch('get', 'url');
|
||||
}
|
||||
public function testEmptyTokenOnFetchPutShouldThrowError()
|
||||
{
|
||||
$fetch = new FetchApi(null, 'http://testUrl.com');
|
||||
$this->expectExceptionMessage('Missing Access Token');
|
||||
$fetch->fetch('put', 'url');
|
||||
}
|
||||
public function testEmptyTokenOnFetchPostShouldThrowError()
|
||||
{
|
||||
$fetch = new FetchApi(null, 'http://testUrl.com');
|
||||
$this->expectExceptionMessage('Missing Access Token');
|
||||
$fetch->fetch('post', 'url');
|
||||
}
|
||||
public function testEmptyTokenOnFetchJsonPostShouldThrowError()
|
||||
{
|
||||
$fetch = new FetchApi(null, 'http://testUrl.com');
|
||||
$this->expectExceptionMessage('Missing Access Token');
|
||||
$fetch->fetch('jsonPost', 'url');
|
||||
}
|
||||
public function testEmptyTokenOnFetchDownloadShouldThrowError()
|
||||
{
|
||||
$fetch = new FetchApi(null, 'http://testUrl.com');
|
||||
$this->expectExceptionMessage('Missing Access Token');
|
||||
$fetch->fetch('download', 'url');
|
||||
}
|
||||
}
|
||||
15
tests/jobsTest.php
Normal file
15
tests/jobsTest.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use BrunoFontes\Memsource;
|
||||
|
||||
final class JobsTest extends TestCase
|
||||
{
|
||||
public function testInvalidProjectUidShouldThrowError()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->expectException(\Exception::class);
|
||||
$api->jobs()->list('invalidProjectUid', []);
|
||||
}
|
||||
}
|
||||
34
tests/oauthTest.php
Normal file
34
tests/oauthTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use BrunoFontes\Memsource;
|
||||
|
||||
final class oauthTest extends TestCase
|
||||
{
|
||||
public function testOauthGetAuthorizationCodeUrl()
|
||||
{
|
||||
$customServerURL = 'http://myPersonalMemsource.com';
|
||||
$api = new Memsource(null, $customServerURL);
|
||||
$expected = $customServerURL . '/oauth/authorize?response_type=code&client_id=id&redirect_uri=http%3A%2F%2Furi&scope=openid';
|
||||
$memsourceUrl = $api->oauth()->getAuthorizationCodeUrl('id', 'http://uri');
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$memsourceUrl
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetAccessTokenExceptionOnFakeCode()
|
||||
{
|
||||
$api = new Memsource();
|
||||
$this->expectException(\Exception::class);
|
||||
$token = $api->oauth()->getAccessToken('fakeCode', 'fakeId', 'fakePass', 'http://any');
|
||||
}
|
||||
|
||||
public function testGetAccessTokenExceptionOnEmptyCode()
|
||||
{
|
||||
$api = new Memsource();
|
||||
$this->expectException(\Exception::class);
|
||||
$token = $api->oauth()->getAccessToken('', '', '', '');
|
||||
}
|
||||
}
|
||||
21
tests/projectTest.php
Normal file
21
tests/projectTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use BrunoFontes\Memsource;
|
||||
|
||||
final class ProjectTest extends TestCase
|
||||
{
|
||||
public function testNoTokenShouldThrowError()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->expectException(\Exception::class);
|
||||
$api->project()->list();
|
||||
}
|
||||
public function testInvalidProjectUidShouldThrowError()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->expectException(\Exception::class);
|
||||
$api->project()->get('invalidProjectUid');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user