Added new tests
This commit is contained in:
parent
c726194e31
commit
b9cb8738f6
|
@ -29,8 +29,8 @@ class UID extends Validator
|
|||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (\is_numeric($value)) {
|
||||
//return false;
|
||||
if(mb_strlen($value) > 32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
10
tests/e2e/Services/Projects/ProjectsBase.php
Normal file
10
tests/e2e/Services/Projects/ProjectsBase.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Projects;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
|
||||
trait ProjectsBase
|
||||
{
|
||||
|
||||
}
|
118
tests/e2e/Services/Projects/ProjectsConsoleClientTest.php
Normal file
118
tests/e2e/Services/Projects/ProjectsConsoleClientTest.php
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Teams;
|
||||
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectConsole;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Tests\E2E\Services\Projects\ProjectsBase;
|
||||
use Tests\E2E\Client;
|
||||
|
||||
class ProjectsConsoleClientTest extends Scope
|
||||
{
|
||||
use ProjectsBase;
|
||||
use ProjectConsole;
|
||||
use SideClient;
|
||||
|
||||
public function testCreateProject(): array
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Project Test',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $team['headers']['status-code']);
|
||||
$this->assertEquals('Project Test', $team['body']['name']);
|
||||
$this->assertNotEmpty($team['body']['$id']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Project Test',
|
||||
'teamId' => $team['body']['$id'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEquals('Project Test', $response['body']['name']);
|
||||
$this->assertEquals($team['body']['$id'], $response['body']['teamId']);
|
||||
$this->assertArrayHasKey('platforms', $response['body']);
|
||||
$this->assertArrayHasKey('webhooks', $response['body']);
|
||||
$this->assertArrayHasKey('keys', $response['body']);
|
||||
$this->assertArrayHasKey('tasks', $response['body']);
|
||||
|
||||
$projectId = $response['body']['$id'];
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => '',
|
||||
'teamId' => $team['body']['$id'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Project Test',
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
return ['projectId' => $projectId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateProject
|
||||
*/
|
||||
public function testGetProject($data):array
|
||||
{
|
||||
$id = (isset($data['projectId'])) ? $data['projectId'] : '';
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertEquals($id, $response['body']['$id']);
|
||||
$this->assertEquals('Project Test', $response['body']['name']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects/empty', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
19
tests/e2e/Services/Projects/ProjectsCustomClientTest.php
Normal file
19
tests/e2e/Services/Projects/ProjectsCustomClientTest.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Projects;
|
||||
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Tests\E2E\Client;
|
||||
|
||||
class ProjectsCustomClientTest extends Scope
|
||||
{
|
||||
use ProjectCustom;
|
||||
use SideClient;
|
||||
|
||||
public function testMock()
|
||||
{
|
||||
$this->assertEquals(true, true);
|
||||
}
|
||||
}
|
19
tests/e2e/Services/Projects/ProjectsCustomServerTest.php
Normal file
19
tests/e2e/Services/Projects/ProjectsCustomServerTest.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Projects;
|
||||
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
use Tests\E2E\Client;
|
||||
|
||||
class ProjectsCustomServerTest extends Scope
|
||||
{
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
|
||||
public function testMock()
|
||||
{
|
||||
$this->assertEquals(true, true);
|
||||
}
|
||||
}
|
30
tests/unit/Database/Validator/UIDTest.php
Normal file
30
tests/unit/Database/Validator/UIDTest.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Appwrite\Database\Validator\UID;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UIDTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var UID
|
||||
*/
|
||||
protected $object = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->object = new UID();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public function testValues()
|
||||
{
|
||||
$this->assertEquals($this->object->isValid('5f058a8925807'), true);
|
||||
$this->assertEquals($this->object->isValid('5f058a89258075f058a89258075f058t'), true);
|
||||
$this->assertEquals($this->object->isValid('5f058a89258075f058a89258075f058tx'), false);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue