1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00
appwrite/tests/e2e/BaseConsole.php

125 lines
4.1 KiB
PHP
Raw Normal View History

2019-09-16 08:17:10 +12:00
<?php
namespace Tests\E2E;
use Tests\E2E\Client;
use PHPUnit\Framework\TestCase;
2019-09-17 16:21:20 +12:00
class BaseConsole extends TestCase
2019-09-16 08:17:10 +12:00
{
/**
* @var Client
*/
protected $client = null;
protected $endpoint = 'http://localhost/v1';
protected $demoEmail = '';
protected $demoPassword = '';
2019-11-04 08:05:26 +13:00
protected function setUp(): void
2019-09-16 08:17:10 +12:00
{
$this->client = new Client();
2019-11-04 08:05:26 +13:00
2019-09-16 08:17:10 +12:00
$this->client
->setEndpoint($this->endpoint)
;
$this->demoEmail = 'user.' . rand(0, 1000000) . '@appwrite.io';
$this->demoPassword = 'password.' . rand(0, 1000000);
2019-09-16 08:17:10 +12:00
}
2019-11-04 08:05:26 +13:00
protected function tearDown(): void
2019-09-16 08:17:10 +12:00
{
$this->client = null;
}
public function register()
{
2019-09-16 08:17:10 +12:00
$response = $this->client->call(Client::METHOD_POST, '/auth/register', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-09-16 08:17:10 +12:00
], [
'email' => $this->demoEmail,
'password' => $this->demoPassword,
2019-09-29 11:55:54 +13:00
'confirm' => 'http://localhost/confirm',
2019-09-16 08:17:10 +12:00
'success' => 'http://localhost/success',
'failure' => 'http://localhost/failure',
'name' => 'Demo User',
]);
2019-11-30 07:26:06 +13:00
2019-09-16 08:17:10 +12:00
return $response;
}
2019-10-21 19:01:07 +13:00
2019-11-04 08:05:26 +13:00
public function initProject(array $scopes): array {
2019-10-21 19:01:07 +13:00
$response = $this->register();
$this->assertEquals('http://localhost/success', $response['headers']['location']);
$this->assertEquals("", $response['body']);
2019-11-04 08:05:26 +13:00
$session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console'];
2019-10-21 19:01:07 +13:00
$team = $this->client->call(Client::METHOD_POST, '/teams', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session,
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-10-21 19:01:07 +13:00
], [
'name' => 'Demo Project Team',
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertEquals('Demo Project Team', $team['body']['name']);
$this->assertNotEmpty($team['body']['$uid']);
$project = $this->client->call(Client::METHOD_POST, '/projects', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session,
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-10-21 19:01:07 +13:00
], [
'name' => 'Demo Project',
'teamId' => $team['body']['$uid'],
'description' => 'Demo Project Description',
'logo' => '',
'url' => 'https://appwrite.io',
'legalName' => '',
'legalCountry' => '',
'legalState' => '',
'legalCity' => '',
'legalAddress' => '',
'legalTaxId' => '',
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertNotEmpty($project['body']);
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$uid'] . '/keys', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session,
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-10-21 19:01:07 +13:00
], [
'name' => 'Demo Project Key',
'scopes' => $scopes,
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertNotEmpty($key['body']);
$this->assertNotEmpty($key['body']['secret']);
$user = $this->projectRegister($project['body']['$uid']);
2019-11-04 08:05:26 +13:00
2019-10-21 19:01:07 +13:00
$this->assertEquals('http://localhost/success', $user['headers']['location']);
$this->assertEquals("", $user['body']);
2019-11-04 08:05:26 +13:00
2019-10-21 19:01:07 +13:00
return [
'email' => $this->demoEmail,
'password' => $this->demoPassword,
'session' => $session,
'projectUid' => $project['body']['$uid'],
'projectAPIKeySecret' => $key['body']['secret'],
'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a_session_' . $project['body']['$uid']],
2019-10-21 19:01:07 +13:00
];
}
}